I’m facing a similar issue when it comes to using a calculated value for “delay” in an automation script, so sorry to hijack that thread.
The following automation works perfectly fine
- alias: TEST Automation Delay
trigger:
platform: sun
event: sunset
offset: '+00:05:00'
action:
- service: switch.turn_on
entity_id: switch.MySwitch
- delay:
**minutes: 120**
- service: switch.turn_off
entity_id: switch.MySwitch
Now I just wanted to replace the part marked in bold with a calculated value.
I came up with
{{((((as_timestamp(states.sun.sun.attributes.next_dawn)) - (as_timestamp(states.sun.sun.attributes.next_dusk))) / 60 ) / 4) | int }}
which works perfectly fine in http://MyHomeAssistantBox:8123/dev-template and returns 124.
But how to use it in the delay context?
I’ve tried the following without success:
minutes: "{{((((as_timestamp(states.sun.sun.attributes.next_dawn)) - (as_timestamp(states.sun.sun.attributes.next_dusk))) / 60 ) / 4) | int }}"
and
minutes: '{{((((as_timestamp(states.sun.sun.attributes.next_dawn)) - (as_timestamp(states.sun.sun.attributes.next_dusk))) / 60 ) / 4) | int }}'
both result in
ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: expected int for dictionary value @ data[‘action’][1][‘delay’][‘minutes’]. Got None. when Checking Config.
minutes: {{((((as_timestamp(states.sun.sun.attributes.next_dawn)) - (as_timestamp(states.sun.sun.attributes.next_dusk))) / 60 ) / 4) | int }}
throws no errors when checking config, but reloading automation throws:
ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: invalid key: “OrderedDict([(’((((as_timestamp(states.sun.sun.attributes.next_dawn)) - (as_timestamp(states.sun.sun.attributes.next_dusk))) / 60 ) / 4) | int’, None)])”
Is this possible at all?
Thanks,
Tom