Thanks for replying
Not sure I’m explaining myself very well, soz…
The script is triggered by an automation when the door changes to ‘open’.
For info, this is the automation and works fine…
- id: Welcome Home
alias: Welcome Home
trigger:
- platform: state
entity_id: sensor.frontdoorstatus
from: 'Closed'
to: 'Open'
condition:
condition: and
conditions:
- condition: state
entity_id: switch.hall_presence
state: 'off'
for: '00:20:00'
action:
- service: script.turn_on
entity_id: script.welcomehome
What I need the template to do is compare the time the vac status updated with the time the door changed to ‘closed’.
welcomehome:
sequence:
- service: script.turn_on
data:
entity_id:
- script.welcomehome_heaters
- script.welcomehome_lights
- service: logbook.log
data_template:
name: "Welcome Home Debug"
message: "Neato Last State Change: {{(states.vacuum.neato.last_changed)}}. Front door opened at {{(states.sensor.frontdoorstatus.last_changed)}}. Neato state is: {{states('vacuum.neato')}}"
- delay: 00:00:10
- service: notify.alexa_media_kitchen_echo
data: {
"message":"Welcome home! Its {{ (states('sensor.living_room_temp_sensor_zigbee'))}} degrees inside.
{% if (states.vacuum.neato.last_changed) > (states.sensor.frontdoorstatus.last_changed) %}
{%- if (is_state('vacuum.neato', 'unavailable')) -%}
The vac went offline at {{(as_timestamp(states.vacuum.neato.last_changed) | timestamp_custom('%I:%M %p'))}}. Its current state is {{states('vacuum.neato')}}. Probably got stuck on a sock then its battery went flat.
{%- elif (is_state('vacuum.neato', 'error')) -%}
The vac tried to eat something stupid and got stuck at {{(as_timestamp(states.vacuum.neato.last_changed) | timestamp_custom('%I:%M %p'))}}. Don't know where it is, you'll have to go find it. Its battery is only {{states('sensor.neato_battery')}} percent. Useless thing.
{%- elif (is_state('vacuum.neato', 'cleaning')) -%}
The vac is still going. Watch out!
{%- elif (is_state('vacuum.neato', 'docked')) -%}
Miraculously, the vac finished and went back to bed at {{(as_timestamp(states.vacuum.neato.last_changed) | timestamp_custom('%I:%M %p'))}}.
{%- endif -%}
{% endif %}
The script is executed as it should (ie, only when the door is to ‘open’ state and only if we’ve come in from outside (which is what the hall_presence automation condition does, as you can’t get to the door from the inside without triggering hall presence sensor), the problem is the content in the message and the first IF statement.
This is the bit that I’m stuck with…
{% if (states.vacuum.neato.last_changed) > (states.sensor.frontdoorstatus.last_changed) %}
Whats wrong with it is that states.sensor.frontdoorstatus.last_changed
will always be recent as the door state must have changed recently in order to trigger the script.
If we add another condition to the IF statement as suggested…
{% if ((states.vacuum.neato.last_changed) > ((states.sensor.frontdoorstatus.last_changed)) and is_state('sensor.frontdoorstatus', 'on') %}
This still won’t work because the whole thing only gets executed when the door is opened.
What I need is:
{% if ((states.vacuum.neato.last_changed) > 'the exact time the door last changed to closed' %}
rather than and is_state('sensor.frontdoorstatus', 'on')
which will won’t compare the times.
I’ve figured out that comparing times with <
and >
does work.
THANKS!!!