the following automation fails for me. It is to detect a long term absence automatically after 24hours of normal absence:
- alias: Mark person as extended away
trigger:
- platform: state
entity_id: input_select.presence_andre_preset
to: Abwesend
for:
hours: 24
- platform: state
entity_id: input_select.presence_maria_preset
to: Abwesend
for:
hours: 24
condition:
condition: and
conditions:
- condition: state
entity_id: 'input_select.automation_presence'
state: 'Automatik'
action:
- service: input_select.select_option
data_template:
entity_id: >
{% if trigger.entity_id == 'input_select.presence_andre_preset' %}
input_select.presence_andre_preset
{% else %}
input_select.presence_maria_preset
{% endif %}
option: Lange weg
The device tracker triggers my input_select option. If this is now triggered to “absence” (Abwesend) for 24hours I would like to get the according persons state to be moved to extended away (Lange weg).
Unfortunately this never triggers.
the condition is a multi-select switch which is set to “Automatik”. This condition is checked for other automations which work…
Anybody has an idea, why this doesnt trigger? I checked the state, it is definitely longer in the Abwesend state than 24hours.
I also have another script for forcing the update, which checks the last_changed timestamp - this would work as expected. It seems that the 24hours trigger in the automation doesnt work…
Thanks
Btw: this one triggers perfectly. It is for a similar purpose: when away the state is “just away”, after 10minutes it should switch to “away”
- alias: Mark person as away
trigger:
- platform: state
entity_id: input_select.presence_andre_preset
to: Gerade weg
for:
minutes: 10
- platform: state
entity_id: input_select.presence_maria_preset
to: Gerade weg
for:
minutes: 10
condition:
condition: and
conditions:
- condition: state
entity_id: 'input_select.automation_presence'
state: 'Automatik'
action:
- service: input_select.select_option
data_template:
entity_id: >
{% if trigger.entity_id == 'input_select.presence_andre_preset' %}
input_select.presence_andre_preset
{% else %}
input_select.presence_maria_preset
{% endif %}
option: Abwesend
I can’t spot anything wrong with the automation honestly? But I’ve never used hours to the extend of 24. This just makes me wonder - can you use 60 minutes, or do you have to write it as 1 hour(s)?
Maybe instead of choosing 24 hours, try it with days: 1
Will try. I have found a potential other cause: I disable the automation for a certain period of time between the 24hrs, then enable it again before the 24hrs are over (at least in the tested case).
I will check
for: “24:00:00”
as well as
for:
days: 1
I found the issue:
What happens is the following (example):
Being “Abwesend” at 7am
Automation to detect 24hours being “Abwesend” will be enabled at a later stage, e.g. 10am.
In this situation, the automation doesnt fire when reaching 7am the next day. I am able to fix this, but for me this is interesting as the trigger should look into the past.
@petro: You are the person I know who knows most of automations - sorry to involve you directly. Can you let me know if the case above is a bug or by design? I would file a bug if correct.
Summary: I do have a time based trigger in an automation to be in a specific state for x amount of time. The according automation is enabled AFTER the state is “reached”, but before the amount of time is reached.
I assume it is by design, but I am not sure … Thanks!
So, now another 24hours passed by, I tested the following:
- platform: state
entity_id: input_select.presence_andre_preset
to: Abwesend
for:
hours: 23
-> this worked (hours: 23)
- platform: state
entity_id: input_select.presence_andre_preset
to: Abwesend
for:
days: 1
-> DIDN’T work
- platform: state
entity_id: input_select.presence_andre_preset
to: Abwesend
for: "24:00:00"
-> DIDN’T work
Not sure, if it was the full day, as accidently in the first attempt I put 23 hours… I will check again with 24 hours. I am a bit concerned, that 'for: “24:00:00” ’ didnt work though…
The issue you are running into is that the way the for option in the state trigger works is, once the entity changes to the specified state, it must stay in that state for the period specified in the for option, AND while HA continues to run AND while the automation continues to be enabled. If HA restarts, or the automation is turned off and back on, the trigger is “reset”, meaning it starts over looking for the entity to change to the specified state, and then starts the time-based monitoring again. The trigger does not look back into the “history” of the entity. It only monitors the entity’s state changes while it is enabled.
It would seem that a History Stats entity would help here. If you configured it to indicate how long the given entity was in the desired state, then you could use a numeric_state trigger to trigger the automation once that value went above 24 hours.
I was about to tag you, but didn’t dare to and simply referred to the thread… but since you are here already do you have any guess why 23h works (which is also a pretty long time) and everything resembling a day does not? Is there some kind of overflow? A recorder issue?
No, there’s nothing wrong with specifying 24 hours. I haven’t tried to understand the previous posts entirely, but I suspect the problem was the trigger was getting reset (because the automation was being turned off and back on) before it could possibly reach 24 hours, hence it never got the chance to trigger.
this was the first issue, you are right - and I got it confirmed. Nevertheless, I tried to specify the 24hours in different ways as written above, and only one of the automations triggered…, the one with
Weird. I used 4 automations, which I simply copied and changed the “for” part. Now 24 hours didnt work, but 23 did… Something is happening here. Most likely on my side, seeing your results.
Not sure why it doesnt work for me. I didnt update to the latest build as I am on 104.3 at the moment.
I created a simple environment with one input_select to monitor, which is only taking manual input. The automations have not been switched off either… Big “?”… Will investigate further. Thanks for the help!
I can’t imagine how “for: {hours: 24}” doesn’t work. But just in case there is something unexpected I just set up a test. It has two automations. Each uses a state trigger watching for an input_select to change to a certain value. Each has a for option with hours, with one set to 23 and the other to 24. When they trigger they send a persistent notification. I’ll let you know what happens (in about 24 hours. )
And, FWIW, I just used the state trigger’s schema with “days: 1” and “hours: 24”, and not surprisingly they resulted in the same timedelta object:
According to the history (db) it does - it is a manual setting. But in the last test I made a mistake, so those dont provide correct results. I will now further debug my setting.
For the tests, I am only using input_selects with manual input to avoid any other mistake.
I am wondering as I simply copy and pasted the same automation 4 times, renamed them and changed the “for”-line. At the end one automation fired.
At the end I must have made a mistake - so thanks for your testing. It give me the confidence to find the bug in my coding/setup