tetsuo13 / TeamsStatusPub

RESTful server from machine running Teams to provide sensor for Home Assistant
MIT License
2 stars 1 forks source link

Home Assistant uses "unavailable" when app isn't running #15

Open tetsuo13 opened 2 years ago

tetsuo13 commented 2 years ago

If the computer with TeamsStatusPub is rebooting or the app isn't otherwise running, Home Assistant logs the following messages:

[homeassistant.components.rest.data] Error fetching data: http://192.168.1.1:17493/ failed with [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.busy }}'

This causes the automation to_state to be "unavailable" causing the light.turn_unavailable service to be used which doesn't exist which ends up with the result of the light not being toggled on. This is what we want in the end but it's not elegant and causes a lot of entries in the log.

The other side to this is when the computer with TeamsStatusPub is rebooted or otherwise isn't running after the light has already been turned on, Home Assistant will encounter the same behavior and never turn off the light.

There should be a fallback to the binary sensor in cases where the computer isn't reachable.

tetsuo13 commented 1 year ago

With the 2023.4 release there's a new has_value function that might be relevant here.

https://www.home-assistant.io/blog/2023/04/05/release-20234/#new-has_value-function