Advertisement
rootiest

period_of_day template_sensor

Dec 2nd, 2021 (edited)
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. template:
  2. - sensor:
  3. - unique_id: period_of_day
  4. name: Period of the day
  5. state: >
  6. {% if (as_timestamp(state_attr('sun.sun','next_dusk'))) -
  7. (as_timestamp(state_attr('sun.sun','next_setting'))) < 0 %}
  8. Dusk
  9. {% elif (as_timestamp(state_attr('sun.sun','next_rising'))) -
  10. (as_timestamp(state_attr('sun.sun','next_dawn'))) < 0 %}
  11. Dawn
  12. {% elif now().hour == 0 %}
  13. Midnight
  14. {% elif (state_attr('sun.sun', 'elevation')) < 0 %}
  15. Night
  16. {% else %}
  17. Day
  18. {% endif %}
  19. icon: >
  20. {% set period = states('sensor.period_of_day') %}
  21. {% if period == 'Dusk' %} mdi:weather-sunset-down
  22. {% elif period == 'Dawn' %} mdi:weather-sunset-up
  23. {% elif period == 'Night' %} mdi:weather-night
  24. {% elif period == 'Midnight' %} mdi:clock-time-twelve
  25. {% else %} mdi:weather-sunny
  26. {% endif %}
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement