Advertisement
314ma

plants light

Nov 21st, 2020
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 0.71 KB | None | 0 0
  1. - alias: plants_light
  2.   trigger:
  3.     - platform: sun
  4.       event: sunset
  5.   actions:
  6.     - service: light.turn_on
  7.       data:
  8.         entity_id: light.plants
  9.     - delay: >-
  10.         {% set current_night_length = as_timestamp(state_attr('sun.sun', 'next_setting')) - as_timestamp(state_attr('sun.sun', 'next_rising')) %}
  11.         {% set min_night_length =  7*3600 + 47*60 + 43 %}
  12.         {% set max_night_length = 16*3600 + 46*60 + 39 %}
  13.         {% set scale = 1 - (current_night_length - min_night_length) / (max_night_length - min_night_length) %}
  14.         {% set delay = (scale * min_night_length / 4) | int %}
  15.         {{ delay }}
  16.     - service: light.turn_off
  17.       data:
  18.         entity_id: light.plants
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement