I have set up some sensors as template sensors with a trigger at startup. Due to some issues with the times that some of the values used in these sensors are being updated, i now realise I need to wait maybe 10 minutes after HA startup to populate these.
I have installed the Uptime integration and so am attempting to use this but cannot work out the syntax of the trigger. I have seen value templates to calculate minutes between now and the sensor.uptime but cannot find any examples of defining this in a trigger.
My current attempt (with the startup trigger still in place) is below:
- trigger:
- trigger: time_pattern
# This will update every night
hours: "0"
minutes: "01"
- trigger: homeassistant
event: start
- trigger: numeric_state
entity_id: sensor.uptime
value_template: "{{ now() - state.state|as_datetime | timedelta( minutes ) }}"
above: 10
sensor:
- name: sun_sunrise
device_class: timestamp
state: >- # "{{ (state_attr('sun.sun','next_rising') | as_datetime | as_local).isoformat() }}"
{% set day = (as_timestamp(states('sensor.date_time_iso'))
| timestamp_custom("%Y-%m-%d", true) ) | string %}
{% set sday = (as_timestamp(state_attr('sun.sun','next_rising'))
| timestamp_custom("%Y-%m-%d", true) ) | string %}
{% if day != sday %}
{% set time = (as_timestamp(state_attr('sun.sun','next_rising'))
| timestamp_custom("%H:%M:%S", true) ) | string %}
{{ (strptime(day+' '+time,'%Y-%m-%d %H:%M:%S') | timestamp_local) | as_datetime | as_local).isoformat() }}
{% else %}
{{ as_timestamp(state_attr('sun.sun','next_rising')) | timestamp_local | as_datetime | as_local).isoformat() }}
{% endif %}