Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Generic trigger for when any device goes unavailable? #209

Answered by dlashua
kmorris81 asked this question in Q&A
Discussion options

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.

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
0 replies
Comment options

I would use an @event_trigger if the goal is to watch ANY entity. And, yes, pyscript is notified on a state of unavailable.

You must be logged in to vote
1 reply
Comment options

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!

Answer selected by kmorris81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /