-
Notifications
You must be signed in to change notification settings - Fork 58
-
My goal is to generate a mobile notification when any device goes to an unavailable
state.
I suppose the first question is: Does pyscript get notified when a devices goes unavailable
?
Second: Is it possible to write a generic @state_trigger()
that captures when any device transitions to unavailable
?
Any thoughts/recommendations on how to best implement this would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
I would use an @event_trigger
if the goal is to watch ANY entity. And, yes, pyscript is notified on a state of unavailable
.
Replies: 2 comments 1 reply
-
I can't you fully answer that. I just made an app in pyscript, defining the different entities that should be watched...
I used trigger closures. Look at the docs.
It worked if I created a closere per entiity. But, I got stuck checking multiple entities in 1 trigger condition. See #231
So, it is possible yes.
Be aware, it can take a little time before the "unavailable" state is set. But, that probably depends what kind of entity you check.
e.g. I have DECONZ (zigbee) integration and hue spots connected to CONBEE2 stick.
When I power off the spots , it takes a few minutes before DECONZ "sees" that, and therefore Home assistant.
Beta Was this translation helpful? Give feedback.
All reactions
-
I would use an @event_trigger
if the goal is to watch ANY entity. And, yes, pyscript is notified on a state of unavailable
.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks! I ended up going your suggested route:
from homeassistant.const import EVENT_STATE_CHANGED
@event_trigger(EVENT_STATE_CHANGED)
def unavailable_checker(entity_id, new_state, old_state):
if state.get(entity_id) == "unavailable":
log.info(f"{entity_id} is unavailable.")
notify.mobile_app_my_phone(message=f"ALERT: {entity_id} is unavailable.")
Works like a charm!
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1