Okay so this may be a bit confusing so I’m going to try and be clear.
Example code will be inserted at the end of the post.
Here’s my use case.
I’ve manually made automations for circadian lights. I’m in the process of cleaning things up using templates and template sensors.
I have 5 entities that when they turn on, the brightness and color_temp are brought in based on template sensors that change every half hour or so throughout the day. I think I have this part working (haven’t done the real world testing yet, but it’s looking good in the template editor). See code below Fig. A
I have another automation for the overnight times because the template sensor has an RGB value from 23:01 to 05:00 for rgb_color instead of color_temp (in case you’re wondering about the time condition)
This works great (or should) if the light is turning from off to on, but doesn’t help when the light is already on when it goes from, for example: 16:59 to 17:00. I would like it to transition to the new value.
In my old version manual automations, each entity and time frame had it’s own automation (19 automations per entity…don’t judge…I’m trying to make things a bit sexier now).
Fig. B
below
So you can see that when the light turns on and the time condition is met, it turns on to the specified brightness/temp
If it’s already on and the time trigger is met, then the light will transition from the old brightness/temp to the new one.
This was a TON of code, but worked surprisingly well.
So I’m looking for a template or automation or script or combination to recreate that time trigger. What I have so far is the last bit at the end of this post… Fig. C
As I type this, I’m thinking that maybe a template sensor may be possible. One that has the entities that are currently in the on state and could be brought into the entity_id:
of the action. Is that possible?
Thanks in advance for any help with this.
#####################Example Code###################
This code should work for when any of the entities turn on
Fig. A
- id: circadian_day
alias: Circadian Day On Trigger
initial_state: true
trigger:
- platform: state
entity_id: light.lamp
from: 'off'
to: 'on'
- platform: state
entity_id: light.desk_lamp
from: 'off'
to: 'on'
- platform: state
entity_id: light.sengled_cabinet_strip
from: 'off'
to: 'on'
- platform: state
entity_id: light.dining_bulb
from: 'off'
to: 'on'
- platform: state
entity_id: light.back_hall_lights
from: 'off'
to: 'on'
condition:
- condition: time
before: '23:01:00'
after: '04:59:00'
- condition: state
entity_id: input_boolean.circadian_on
state: 'on'
action:
- service: light.turn_on
data_template:
entity_id: "{{ trigger.entity_id }}"
brightness: "{{ states('sensor.cl_brightness') }}"
color_temp: "{{ states('sensor.cl_color_temp') }}"
transition: '5'
##################Example of old circadian automations############
Fig. B
- id: cl6a_desk_lamp
alias: 6am desk_lamp
initial_state: true
trigger:
- platform: state
entity_id: light.desk_lamp
from: 'off'
to: 'on'
- platform: time
at: '06:01:00'
condition:
- condition: time
after: '06:01:00'
before: '06:30:00'
- condition: state
entity_id: light.desk_lamp
state: 'on'
- condition: state
entity_id: input_boolean.circadian_on
state: 'on'
action:
- service: light.turn_on
data_template:
entity_id: light.desk_lamp
brightness_pct: 25
color_temp: 450
transition: '5'
################Beginning of the time trigger automation################
Here’s what I have so far, but not even sure if it’s worth anything
Fig. C
- id: circadian_time_transition
alias: Circadian Time Transition
initial_state: true
trigger:
- platform: time
at: '05:00:00'
- platform: time
at: '06:00:00'
- platform: time
at: '06:30:00'
- platform: time
at: '07:00:00'
- platform: time
at: '07:30:00'
- platform: time
at: '08:00:00'
- platform: time
at: '09:00:00'
- platform: time
at: '16:30:00'
- platform: time
at: '17:00:00'
- platform: time
at: '17:30:00'
- platform: time
at: '18:00:00'
- platform: time
at: '18:30:00'
- platform: time
at: '19:00:00'
- platform: time
at: '19:30:00'
- platform: time
at: '20:00:00'
- platform: time
at: '20:30:00'
- platform: time
at: '21:00:00'
- platform: time
at: '22:00:00'
- platform: time
at: '22:30:00'
condition:
- condition: state
entity_id: input_boolean.circadian_on
state: 'on'
action:
- service: light.turn_on
data_template:
entity_id: #########need only the specified entities that are currently on.
##########################Template sensor maybe?
brightness: "{{ states('sensor.cl_brightness') }}"
color_temp: "{{ states('sensor.cl_color_temp') }}"
transition: '15'
I may be going about this the wrong way and am open to new ideas too. I’ve tried the Flux component and the Circadian Lighting Custom component. I’m not interested in using them.
Thanks!