Skip to content

Instantly share code, notes, and snippets.

@disconn3ct
Created April 7, 2023 14:07
Show Gist options
  • Save disconn3ct/07682a8a7bfb51aa23cb4672366b360f to your computer and use it in GitHub Desktop.
Save disconn3ct/07682a8a7bfb51aa23cb4672366b360f to your computer and use it in GitHub Desktop.
Home Assistant automation for temperature (F) lights with time-decay brightness
- alias: LED - Temperature
description: ''
trigger:
# How often to decay:
- platform: time_pattern
seconds: /30
# And whenever the source is freshened:
- platform: state
entity_id:
- sensor.tomorrow_io_weather_feels_like
condition: []
action:
# This could be done a ton of ways but I wanted to mess with choose
- choose:
- conditions:
- condition: state
entity_id: sensor.tomorrow_io_weather_feels_like
state: unavailable
sequence:
- service: light.turn_on
data:
hs_color:
- 375
- 100
# 30 minute updates
# 255/1800 0.141666...
brightness:
"{% if states('sensor.tomorrow_io_weather_feels_like','last_updated')
%}{{ 255 - ((now() | as_timestamp - states.sensor.tomorrow_io_weather_feels_like.last_updated
| as_timestamp) * 0.1416 )| int | round(0) }}{% else %} {{ state_attr('light.wled_segment_1','brightness')
}}{%endif%}"
target:
entity_id: light.wled_segment_1
- conditions:
- condition: numeric_state
entity_id: sensor.tomorrow_io_weather_feels_like
below: 45
sequence:
- service: light.turn_on
data:
hs_color:
- 180
- 100
brightness:
"{% if states('sensor.tomorrow_io_weather_feels_like','last_updated')
%}{{ 255 - ((now() | as_timestamp - states.sensor.tomorrow_io_weather_feels_like.last_updated
| as_timestamp) * 0.1416 )| int | round(0) }}{% else %} {{ state_attr('light.wled_segment_1','brightness')
}}{%endif%}"
target:
entity_id: light.wled_segment_1
- conditions:
- condition: numeric_state
entity_id: sensor.tomorrow_io_weather_feels_like
above: 100
sequence:
- service: light.turn_on
data:
hs_color:
- 0
- 100
brightness:
"{% if states('sensor.tomorrow_io_weather_feels_like','last_updated')
%}{{ 255 - ((now() | as_timestamp - states.sensor.tomorrow_io_weather_feels_like.last_updated
| as_timestamp) * 0.1416 )| int | round(0) }}{% else %} {{ state_attr('light.wled_segment_1','brightness')
}}{%endif%}"
entity_id: light.wled_segment_1
default:
- service: light.turn_on
data_template:
hs_color:
"[{{ ((180 | int) - (((states('sensor.tomorrow_io_weather_feels_like')
| float) - 45 | int) * 3.272) | int | round(0))}},100]"
brightness:
"{% if states('sensor.tomorrow_io_weather_feels_like','last_updated')
%}{{ 255 - ((now() | as_timestamp - states.sensor.tomorrow_io_weather_feels_like.last_updated
| as_timestamp) * 0.1416 )| int | round(0) }}{% else %} {{ state_attr('light.wled_segment_1','brightness')
}}{%endif%}"
entity_id: light.wled_segment_1
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment