I have a sensor that I want to trigger an automation whenever it is NOT reporting “no error”; there is a long list of 20-30 error states it can report, too many to list individually in the automation.
What would be the best syntax to use to trigger an automation whenever the sensor changes from “no error” to any of the other error states?
This is what I have so far, but I need to turn it around so it reports the opposite.
TIA
- condition: state
entity_id: sensor.elmo_error
state: no_error
triggers:
- trigger: state
entity_id: sensor.elmo_error
not_to:
- no_error
If desired you can also add unavailable and unknown to the list of states to ignore.
Or approach it from the other direction:
triggers:
- trigger: state
entity_id: sensor.elmo_error
from:
- no_error
The outcomes from these two triggers will be similar but not exactly the same. Make sure you understand the implication of requiring the previous state to be “no_error”.
You can also use not_to in the second option to ignore other states, if desired.
Thanks; I have tried to blend that in to my automation, but even when the state is “no_error” it makes an announcement every 15 minutes stating “no error” - which I’d like to suppress.
The same happens whether I use not_to: or from:. I suspect I have got the trigger section wrong, but not sure how to correct it …
TIA
alias: Mower is Stuck - Elmo
description: ""
triggers:
- minutes: /15
trigger: time_pattern
- trigger: state
entity_id: sensor.elmo_error
not_to:
- no_error
- unavailable
- unknown
conditions:
- condition: time
after: "08:01:00"
before: "20:01:00"
actions:
- action: chime_tts.say
metadata: {}
data:
chime_path: /config/www/custom_audio/alert-ascending-chime-betacut-1-00-02.mp3
message: >
Elmo is reporting the following error: {{ states('sensor.elmo_error')
}}. Please clear the fault & re-start Elmo.
tts_platform: tts.elevenlabs
offset: -10
announce: true
fade_audio: true
volume_level: 0.6
voice: Daniel
target:
entity_id:
- media_player.office_echo
- action: notify.mobile_app_xyz_iphone_15_pro
metadata: {}
data:
message: "Elmo error: {{states('sensor.elmo_error')}}"
mode: single
Use a repeat until in your actions instead of the time pattern trigger.
The example in that link shows you exactly how to use it. Should be something like the below (though I might be wrong because my coffee still hasn’t kicked in):
alias: Mower is Stuck - Elmo
description: ""
triggers:
- trigger: state
entity_id: sensor.elmo_error
not_to:
- no_error
- unavailable
- unknown
conditions:
- condition: time
after: "08:01:00"
before: "20:01:00"
actions:
- alias: "Repeat the sequence UNTIL the conditions are true"
repeat:
sequence:
- action: chime_tts.say
metadata: {}
data:
chime_path: /config/www/custom_audio/alert-ascending-chime-betacut-1-00-02.mp3
message: >
Elmo is reporting the following error: {{ states('sensor.elmo_error')
}}. Please clear the fault & re-start Elmo.
tts_platform: tts.elevenlabs
offset: -10
announce: true
fade_audio: true
volume_level: 0.6
voice: Daniel
target:
entity_id:
- media_player.office_echo
- action: notify.mobile_app_xyz_iphone_15_pro
metadata: {}
data:
message: "Elmo error: {{states('sensor.elmo_error')}}"
- delay:
minutes: 15
until:
- condition: state
entity_id: sensor.elmo_error
state: no_error
mode: single
Note that this will cause your automation to run for a long-ish period of time. If HA is restarted during that period, your notifications will be interrupted. However, they should start coming in again after a restart, because you have no handling for when the state is from unavailable/unknown.
Then it explains why you’re being reminded of “no_error”. The Time Pattern Trigger doesn’t monitor the state of sensor.elmo_error, it simply triggers every 15 minutes and reports the sensor’s current value (even if it’s “no_error”).
You need to redesign your automation so that the repetitive notification occurs inside of actions (consider using a repeat). The State Trigger (configured as suggested above) will trigger only when appropriate and then the repeat posts a notification every 15 minutes. see ShadowFist’s example
EDIT
By the time I finished writing my post, ShadowFist already provided a working example.