123
(Taras)
July 30, 2024, 6:51pm
21
Did the example I suggested fail to work entirely or just under certain conditions? What were the results of your tests?
123:
The following single automation will:
Turn off the fan switch when:
The light is turned on between 00:30-10:00.
The fan switch is on
.
Turn on the fan switch when:
The light is turned off between 00:30-09:45.
The fan switch is off
.
The last time the fan switch’s state changed was between 00:30-09:45.
Change the following two entity_ids to match what you have in your system.
light.your_light
switch.your_fan_plug
alias: example
trigger:
- platform: state
entity_id: light.your_light
from: 'off'
to: 'on'
variables:
mode: 'off'
is_true: >
{{ today_at('00:30') <= now() < today_at('10:00')
and is_state('switch.your_fan_plug', 'on') }}
- platform: state
entity_id: light.your_light
from: 'on'
to: 'off'
variables:
mode: 'on'
is_true: >
{{ today_at('00:30') <= now() < today_at('09:45')
and is_state('switch.your_fan_plug', 'off') }}
and today_at('00:30') <= trigger.from_state.last_changed < today_at('09:45') }}
condition:
- condition: template
value_template: '{{ is_true }}'
action:
- service: 'switch.turn_{{ mode }}'
target:
entity_id: switch.your_fan_plug
It doesn’t rely on an Input Boolean.
tried your .yaml, sadly didn’t turn fan back on, thank you for trying
123
(Taras)
July 30, 2024, 8:01pm
23
That surprised me so I tested the automation for myself (using light
and switch
entities that exist in my system and setting the time range to this afternoon).
I confirmed your result; it failed to turn the switch back on.
I checked the automation’s trace and discovered a typo in the second trigger’s is_true
template. Just two }}
characters in the wrong place rendered the template non-functional.
I removed the two offending characters, repeated the tests, and the automation now works exactly the way you requested.
I have corrected the original example I posted above (in case someone else wishes to use it). All that’s needed is to remove the two }}
characters shown below.
Anyway, even if you don’t use it, I can offer it as a solution to other users who may have the same requirements.
2 Likes
123:
alias: example
trigger:
- platform: state
entity_id: light.your_light
from: 'off'
to: 'on'
variables:
mode: 'off'
is_true: >
{{ today_at('00:30') <= now() < today_at('10:00')
and is_state('switch.your_fan_plug', 'on') }}
- platform: state
entity_id: light.your_light
from: 'on'
to: 'off'
variables:
mode: 'on'
is_true: >
{{ today_at('00:30') <= now() < today_at('09:45')
and is_state('switch.your_fan_plug', 'off') }}
and today_at('00:30') <= trigger.from_state.last_changed < today_at('09:45') }}
condition:
- condition: template
value_template: '{{ is_true }}'
action:
- service: 'switch.turn_{{ mode }}'
target:
entity_id: switch.your_fan_plug
123:
That surprised me so I tested the automation for myself (using light
and switch
entities that exist in my system and setting the time range to this afternoon).
I confirmed your result; it failed to turn the switch back on.
I checked the automation’s trace and discovered a typo in the second trigger’s is_true
template. Just two }}
characters in the wrong place rendered the template non-functional.
I removed the two offending characters, repeated the tests, and the automation now works exactly the way you requested.
I have corrected the original example I posted above (in case someone else wishes to use it). All that’s needed is to remove the two }}
characters shown below.
Anyway, even if you don’t use it, I can offer it as a solution to other users who may have the same requirements.
That works also, I now have 2 options that work