Fellow HA´ers,
As a last resort, I need your help on the below:
I am extensively using sunset and sunrise as triggers for various automations. I use the UI to configure automations, and have the offset for my automations “hardcoded” in the UI for automations. In order for my wife to change certain settings, I want the offset´s to be accesible by using a helper, which can be changed through a card on lovelace.
Here is my code in automation.yaml:
- id: '1590563700083'
alias: TEST use Helper Input time for offset sun event
description: TEST use Helper Input time for offset sun event
trigger:
- event: sunset
offset: "{{ states('input_datetime.test_input_time') }}"
platform: sun
condition: []
action:
- data:
message: Test Notification triggered by sunset with offset
service: notify.mobile_app_iphone_john
The Developer Tools - Templates shows the correct value which was set:
-------------screenshot-------------
But when I do the configuration check, I get the following error:
Invalid config for [automation]: offset {{ states(‘input_datetime.test_input_time’) }} should be format ‘HH:MM’ or ‘HH:MM:SS’ for dictionary value @ data[‘trigger’][0][‘offset’]. Got None.
I am afraid I get either stuck in the Quote tombola, or offset for sun can simply not be given as an input like this.
However, you can easily do an offset from the sun’s elevation. Using the elevation has the advantage of providing a consistent light level, which a time offset doesn’t.
@Tinkerer Thanks for superfast response. I will dig into using the elevation instead (as my automations are related to “darkness”, such might become more accurate.
Just as a confirmation, what I was trying to achieve, was to substitue the +/-HH:MM:SS value of offset with a “helper” value. The below code actually works, where the offset is a fixed value.
So, I cannot substitue the string of “-00:20:00” with {{states(‘input_datetime.test_input_time’) }} ?
- id: '1590563700083'
alias: TEST use Helper Input time for offset sun event
description: TEST use Helper Input time for offset sun event
trigger:
- event: sunset
offset: -00:20:00 # WORKS OK
# offset: "{{ states('input_datetime.test_input_time') }}" # DOES NOT WORK
platform: sun
condition: []
action:
- data:
message: Test Notification triggered by sunset with offset
service: notify.mobile_app_iphone_john
Sorry for using the thread but I actually tried to build something similar. Now I know why it doesn’t work, which is a pity because the sunset alone is not always enough but also other features like cloudy, partlycloudy or rainy. My consideration was more like this here.