Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template:
- - binary_sensor:
- - name: sun_above_horizon
- device_class: light
- state: "{%if state_attr('sun.sun', 'elevation')|float(0) > 2 %}True{%else%}False{%endif%}"
- input_number:
- outdoor_lights_brightness:
- name: Outdoor light brightness
- min: -1
- max: 101
- step: 1
- automation:
- - alias: dim outdoor lights according to daylight
- trigger:
- - platform: state
- entity_id: binary_sensor.sun_above_horizon
- to: ['on', 'off']
- from: ['on', 'off']
- variables:
- brightness_pct: "{{ 0 if states('binary_sensor.sun_above_horizon') == 'on' else 100 }}"
- direction: "{{ 1 if states('binary_sensor.sun_above_horizon') == 'on' else -1 }}"
- action:
- # store the starting value
- - service: input_number.set_value
- data:
- entity_id: input_number.outdoor_lights_brightness
- value: "{{brightness_pct}}"
- - repeat:
- # repeat until value is outside of range
- until: "{{states('input_number.outdoor_lights_brightness')|int(-1) < 0 or states('input_number.outdoor_lights_brightness')|int(101) > 100}}"
- sequence:
- #first calculate the new number
- - service: input_number.set_value
- data:
- entity_id: input_number.outdoor_lights_brightness
- value: "{{states('input_number.outdoor_lights_brightness')|int(0)+direction}}"
- # then apply new number to the lights
- - service: light.turn_on
- data:
- entity_id: light.outdoor_lights
- brightness_pct: "{{states('input_number.outdoor_lights_brightness')|int(0)}}"
- - delay: '00:00:02'
- mode: restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement