Skip to content

Instantly share code, notes, and snippets.

@elden1337
Created May 27, 2021 06:54
Show Gist options
  • Save elden1337/9b899089948cb2ed442195ca3f8f80f4 to your computer and use it in GitHub Desktop.
Save elden1337/9b899089948cb2ed442195ca3f8f80f4 to your computer and use it in GitHub Desktop.
brightness helper to slowly (linear) dim the lights from 17:00 - 20:00 and then inverted exponential until 23:00. Use in automations to call light.turn_on in Home Assistant.
- platform: template
sensors:
lightbrightness:
friendly_name: 'light brightness - helper'
unit_of_measurement: '%'
value_template: >
{% if now().hour > 16 and now().hour < 23 %}
{% set timer = now().minute+((now().hour-17)*60) %}
{% set const = 1.01452 %}
{% set hourdivider = ((now().hour/20)-0.45)|round(0) %}
{{ 255-((45/180)*timer)+(hourdivider*(-(const**timer)+13.4)) }}
{% elif now().hour < 7 or now().hour == 23 %}
3
{% else %}
255
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment