Skip to content

Instantly share code, notes, and snippets.

@vibrog
Last active November 25, 2019 21:04
Show Gist options
  • Save vibrog/c7404dfd0ef59a84d4b4d07cc965c017 to your computer and use it in GitHub Desktop.
Save vibrog/c7404dfd0ef59a84d4b4d07cc965c017 to your computer and use it in GitHub Desktop.
Futurehome-inspirert modusvelger til Home Assistant

Futurehome-inspirert modusvelger til Home Assistant

Min egen løsning på mitt eget spørsmål om hvordan man kan lage en pen og brukervennlig modusvelger i Home Assistant, som samtidig viser gjeldende modus ved et raskt blikk på en skjerm. Jeg vil gjerne ha forslag til forenklinger.

Opprett en variabel som holder på modusene til boligen din:

input_select:
  house_mode:
    name: House mode
    icon: mdi:home
    options:
      - Hjemme
      - Borte
      - Natt
      - Ferie
    initial: Hjemme

Denne kan brukes direkte som en nedtrekksmeny. Men knapper kan kreve et trykk mindre.

Løsning 1

Lovelace kort med Futurehome lookalike modusvelger, men denne markerer ikke gjeldende modus.

type: glance
columns: 4
entities:
  - entity: input_select.house_mode
    name: Hjemme
    icon: mdi:home
    tap_action:
      action: call-service
      service: input_select.select_option
      service_data:
        entity_id: input_select.house_mode
        option: Hjemme
  - entity: input_select.house_mode
    name: Borte
    icon: mdi:car
    tap_action:
      action: call-service
      service: input_select.select_option
      service_data:
        entity_id: input_select.house_mode
        option: Borte
  - entity: input_select.house_mode
    name: Natt
    icon: mdi:power-sleep
    tap_action:
      action: call-service
      service: input_select.select_option
      service_data:
        entity_id: input_select.house_mode
        option: Natt
  - entity: input_select.house_mode
    name: Ferie
    icon: mdi:airplane
    tap_action:
      action: call-service
      service: input_select.select_option
      service_data:
        entity_id: input_select.house_mode
        option: Ferie
show_icon: true
show_name: true
show_state: false

Eksempel på bruk i automasjon:

automation:
- alias: Arrive home
  trigger:
    platform: state
    entity_id: input_select.house_mode
    to: Hjemme
  action:
    - service: notify.slack
      data: { message: Velkommen hjem }

Løsning 2

En enkelt knapp som man kan tappe for å toggle, hvor ikonet viser nåværende modus.

Den trenger input selektoren over for å huske valgt modus, en input boolean for å håndtere tap_action og en binær sensor for å skifte ikoner.

binary_sensor:
  - platform: template
    sensors:
      house_mode:
        friendly_name: House mode
        device_class: presence
        icon_template: >
          {% if is_state("input_select.house_mode", "Hjemme") %}
            mdi:home
          {% elif is_state("input_select.house_mode", "Borte") %}
            mdi:car
          {% elif is_state("input_select.house_mode", "Natt") %}
            mdi:power-sleep
          {% elif is_state("input_select.house_mode", "Ferie") %}
            mdi:airplane
          {% else %}
            mdi:minus
          {% endif %}
        value_template: >
          {{ is_state("input_select.house_mode", "Hjemme") }}
input_boolean:
  house_mode:
    icon: mdi:home
    initial: on

Lovelace card, enten som en stor knapp

type: entity-button
tap_action:
  action: call-service
  service: input_select.select_option
  service_data:
    entity_id: input_boolean.house_mode
hold_action:
  action: more-info
show_icon: true
show_name: false
entity: binary_sensor.house_mode

... eller mer kompakt i et glance kort:

type: glance
columns: 4
entities:
  - entity: binary_sensor.house_mode
    tap_action:
      action: call-service
      service: input_boolean.toggle
      service_data:
        entity_id: input_boolean.house_mode
show_icon: true
show_name: false
show_state: true

Det må lages automasjoner som lager slaver av input_boolean og input_select, for eksempel:

automation:
- alias: Input away
  trigger:
    platform: state
    entity_id: input_boolean.house_mode
    to: 'off'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: input_select.house_mode
        state: Hjemme
      - condition: time
        after: '06:00:00'
        before: '22:00:00'
  action:
    service: input_select.select_option
    data:
      entity_id: input_select.house_mode
      option: Borte
- alias: Input night
  trigger:
    platform: state
    entity_id: input_boolean.house_mode
    to: 'off'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: input_select.house_mode
        state: Hjemme
      - condition: time
        after: '22:00:00'
        before: '06:00:00'
  action:
    service: input_select.select_option
    data:
      entity_id: input_select.house_mode
      option: Natt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment