I’ve made a sensor which changes state depending on the time of day. I then have an automation which uses this state to set the light colour & brightness when they turn on. This works perfectly.
But, I also want lights that are currently on, to change mode when the sensor changes. I thought I’d figured it out, but it doesn’t work. Even if I manually trigger it, it does nothing. I copied the action from the working automation, so I know it shouldn’t be that. The condition just checks if the light is on, so that should be fine. Everything I’ve read suggests that the trigger I’ve put should make the automation run whenever the sensor state changes, but I’m not 100% sure.
Can anyone see a reason this isn’t working?
Also, as a bonus question, is there anyway to include minutes in the sensor? I’d love it if some of the changes happened at half past instead of on the hour.
sensors:
platform: template
sensors:
default_light_mode:
entity_id: sensor.time
friendly_name: 'Default Light Mode'
value_template: >-
{% if 00 <= now().hour < 01 %}
Soft
{% elif 01 <= now().hour < 02 %}
Dim
{% elif 02 <= now().hour < 06 %}
Dark
{% elif 06 <= now().hour < 08 %}
Dim
{% elif 08 <= now().hour < 10 %}
Soft
{% elif 10 <= now().hour < 21 %}
Bright
{% elif 21 <= now().hour < 24 %}
Soft
{% else %}
Soft
{% endif %}
automations:
- alias: Set Default Mode When Lamp Turns On
trigger:
- platform: state
entity_id: light.lamp
from: 'off'
to: 'on'
action:
- service: input_select.select_option
data_template:
entity_id: input_select.lamp_mode
option: "{{ states.sensor.default_light_mode.state }}"
- alias: Transition to Default Mode if Lamp is On
trigger:
- platform: state
entity_id: sensor.default_light_mode
condition:
- condition: state
entity_id: light.lamp
state: 'on'
action:
- service: input_select.select_option
data_template:
entitiy_id: input_select.lamp_mode
option: "{{ states.sensor.default_light_mode.state }}"