Advertisement
dale3h

[Home Assistant] Persistent Input Slider Example

Aug 1st, 2016
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.41 KB | None | 0 0
  1. # For this to work properly, your MQTT broker must be setup to handle persistence
  2.  
  3. sensor:
  4.   - platform: mqtt
  5.     state_topic: home-assistant/nightlight_brightness
  6.     name: Nightlight Brightness
  7.  
  8. input_slider:
  9.   nightlight_brightness:
  10.     name: Nightlight Brightness
  11.     initial: 64
  12.     min: 0
  13.     max: 255
  14.     step: 1
  15.  
  16. automation:
  17.   - alias: Update Nightlight Brightness Sensor
  18.     trigger:
  19.       - platform: state
  20.         entity_id: input_slider.nightlight_brightness
  21.     condition:
  22.       - condition: template
  23.         value_template: "{{ not is_state('sensor.nightlight_brightness', states('input_slider.nightlight_brightness')) }}"
  24.     action:
  25.       service: mqtt.publish
  26.       data_template:
  27.         topic: home-assistant/nightlight_brightness
  28.         payload: "{{ states('input_slider.nightlight_brightness') }}"
  29.         retain: true
  30.  
  31.   - alias: Update Nightlight Brightness Input Slider
  32.     trigger:
  33.       - platform: state
  34.         entity_id: sensor.nightlight_brightness
  35.       - platform: event
  36.         event_type: homeassistant_start
  37.     condition:
  38.       - condition: template
  39.         value_template: "{{ not is_state('sensor.nightlight_brightness', states('input_slider.nightlight_brightness')) }}"
  40.     action:
  41.       service: input_slider.select_value
  42.       entity_id: input_slider.nightlight_brightness
  43.       data_template:
  44.         value: "{{ states('sensor.nightlight_brightness')|int }}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement