Advertisement
dale3h

[Home Assistant] Persistent Input Boolean Example

Aug 1st, 2016
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.38 KB | None | 0 0
  1. # For this to work properly, your MQTT broker must be setup to handle persistence
  2.  
  3. binary_sensor:
  4.   - platform: mqtt
  5.     state_topic: home-assistant/sunrise-lighting
  6.     name: Sunrise Lighting
  7.     payload_on: 'on'
  8.     payload_off: 'off'
  9.  
  10. input_boolean:
  11.   sunrise_lighting:
  12.     name: Sunrise Lighting
  13.     initial: on
  14.  
  15. automation:
  16.   - alias: Update Sunrise Lighting Binary Sensor
  17.     trigger:
  18.       - platform: state
  19.         entity_id: input_boolean.sunrise_lighting
  20.     condition:
  21.       - condition: template
  22.         value_template: "{{ not is_state('input_boolean.sunrise_lighting', states('binary_sensor.sunrise_lighting')) }}"
  23.     action:
  24.       service: mqtt.publish
  25.       data_template:
  26.         topic: home-assistant/sunrise-lighting
  27.         payload: "{{ states('input_boolean.sunrise_lighting') }}"
  28.         retain: true
  29.  
  30.   - alias: Update Sunrise Lighting Input Boolean
  31.     trigger:
  32.       - platform: state
  33.         entity_id: binary_sensor.sunrise_lighting
  34.       - platform: event
  35.         event_type: homeassistant_start
  36.     condition:
  37.       - condition: template
  38.         value_template: "{{ not is_state('input_boolean.sunrise_lighting', states('binary_sensor.sunrise_lighting')) }}"
  39.     action:
  40.       service_template: "input_boolean.turn_{{ 'on' if is_state('binary_sensor.sunrise_lighting', 'on') else 'off' }}"
  41.       entity_id: input_boolean.sunrise_lighting
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement