molnart
(Tibor Molnár)
April 2, 2024, 8:17pm
1
I am really lost with this automation I am trying to set up:
I want my shades to start tilting 30 minutes before my alarm (represented by sensor.next_alarm_time) goes off.
E.g. the shutters would tilt to 80% 30 mins before alarm, 60% 20 mins before, 40% 10 mins before. The automation should also check if the shutters are not tilted already, so that it does not close them instead.
How do I do that in a single automatiion, so I do not have to create 4 of them for every change? There are 4 shutters i’d like to automate this way and creating 16 separate automations seems overkill.
I have checked out this template, but besides being a bit overwhelming it does not seem to cover this scenario
Debugging:
At this point, I would like to mention that it is possible to increase the number of traces. The following lines must be added to the respective automation in the YAML code.
trace:
stored_traces: 20
See also: Troubleshooting automations - Home Assistant
In case of errors, I need at least the blueprint configuration in YAML format (no screenshot). And if necessary, please also upload a trace here. Thank you very much.
Changelog
(Full Changelog on Github)
2024.01.29-01:
Update…
So far I can’t even get the automation to trigger, what makes me seriously question myself as a HA user for the last 5 years:
value_template: {{as_timestamp(now()) >= (as_timestamp(states("input_datetime.shutter_alarm_test")) - 1800 )}}
(i have used a helper here that i can set manually, so i do not need to change my alarm time for testing purposes)
Any help in this is extremely appreciated.
isn’t your value_template currently being interpreted as a string?
shouldn’t it be:
value_template: "{{as_timestamp(now()) >= (as_timestamp(states('input_datetime.shutter_alarm_test')) - 1800 )}}"
?
or i personally prefer:
value_template: >
{{as_timestamp(now()) >= (as_timestamp(states('input_datetime.shutter_alarm_test')) - 1800 )}}
hopefully that gets you unstuck
if you still are stuck, perhaps post the automation that you’ve already written? prob better to tweak what you’ve got rather than recreate what you’ve already done.
but in terms of how to do it in one automation, i’d do something like this (obviously can optimize, but leaving pedantic for clarity purpose):
trigger:
- platform: template
value_template: " {{as_timestamp(now()) >= (as_timestamp(states('input_datetime.shutter_alarm_test')) - 1800 )}}"
id: "80"
- platform: template
value_template: " {{as_timestamp(now()) >= (as_timestamp(states('input_datetime.shutter_alarm_test')) - 1200 )}}"
id: "60"
- platform: template
value_template: " {{as_timestamp(now()) >= (as_timestamp(states('input_datetime.shutter_alarm_test')) - 600 )}}"
id: "40"
condition: []
action: []
then you can use trigger.id as the value to set the shade tilt to… and just check to see if the tilt % is beyond what the current tilt is.
1 Like
molnart
(Tibor Molnár)
April 2, 2024, 9:02pm
3
of course i have tested that template in the Templates section under developer tools and it evaluated correctly to true/false
yet the automation has no trace
but when you put it in the value_template, you need to instruct homeassistant whether to interpret the string vs accept the string litterally
molnart
(Tibor Molnár)
April 2, 2024, 9:33pm
5
ok, missed that. i suppose its done by the quotation marks, heh?
still it does not trigger the automation
value_template: >
"{{as_timestamp(now()) >= (as_timestamp(states('input_datetime.shutter_alarm_test')) - 1800 )}}"
too bad there is not a simple offset option for time related triggers in HA…
take a look at what i posted… do either of the two i posted… you did both.
either :
value_template: "{{as_timestamp(now()) >= (as_timestamp(states('input_datetime.shutter_alarm_test')) - 1800 )}}"
or
value_template: >
{{as_timestamp(now()) >= (as_timestamp(states('input_datetime.shutter_alarm_test')) - 1800 )}}
not both combined:
value_template: >
"{{as_timestamp(now()) >= (as_timestamp(states('input_datetime.shutter_alarm_test')) - 1800 )}}"
in terms of “simpler” offsets, i personally like:
{{ now() >= states('input_datetime.shutter_alarm_test') - timedelta(minutes=30) }}
i find that easier to grock.
molnart
(Tibor Molnár)
April 10, 2024, 7:58pm
8
ok, i thought the > is just a line break and has no impact on the template interpretation
finally got it working:
alias: Open bedroom shutters in the morning
description: ""
trigger:
- alias: 30 mins before garmin alarm
platform: template
value_template: >
{{as_timestamp(now()) >= (as_timestamp(states('sensor.next_alarm_time')) -
1800 )}}
id: 30min
- alias: 20 mins before garmin alarm
platform: template
value_template: >
{{as_timestamp(now()) >= (as_timestamp(states('sensor.next_alarm_time')) -
1200 )}}
id: 20min
- alias: 10 mins before garmin alarm
platform: template
value_template: >
{{as_timestamp(now()) >= (as_timestamp(states('sensor.next_alarm_time')) -
600 )}}
id: 10min
condition:
- condition: and
conditions:
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: template
value_template: >-
value_template: "{{ state_attr('cover.bedroom_blinds',
'current_tilt_position') == 100 or state_attr('cover.bedroom_blinds',
'current_tilt_position') is none }}"
enabled: false
action:
- choose:
- conditions:
- condition: trigger
id:
- 30min
sequence:
- if:
- condition: numeric_state
entity_id: cover.bedroom_blinds
attribute: current_tilt_position
below: 50
then:
- service: cover.set_cover_tilt_position
target:
entity_id:
- cover.bedroom_blinds
data:
tilt_position: 50
- conditions:
- condition: trigger
id:
- 20min
sequence:
- if:
- condition: numeric_state
entity_id: cover.bedroom_blinds
attribute: current_tilt_position
below: 100
then:
- service: cover.set_cover_tilt_position
target:
entity_id:
- cover.bedroom_blinds
data:
tilt_position: 100
- conditions:
- condition: trigger
id:
- 10min
sequence:
- if:
- condition: numeric_state
entity_id: cover.bedroom_blinds
attribute: current_position
below: 1
then:
- service: cover.set_cover_position
target:
entity_id:
- cover.bedroom_blinds
data:
position: 1
mode: single