hass-node-red icon indicating copy to clipboard operation
hass-node-red copied to clipboard

Switches created in NR marked unavailable in global context after node red restart

Open dpgh947 opened this issue 6 months ago • 2 comments

Describe the bug

This is a strange problem, not sure where the problem lies, so I'm starting here: I use the "expose as" settings on nodes that support it a lot, it creates a switch in HA which can be used to disable the node (for example, events: state node), this gives an easy way to turn NR automation routines on/off from HA.

I also make use a lot of the entity states available under global context (for example, global.homeassistant.homeAssistant.states["switch.automatic_study_light_control"].state) to get an entity state in various nodes without having to use a separate "current state" node. I have noticed that the state of all these switches created by "expose as" is showing "unavailable" in the global context after a node red addon restart (EG: for an upgrade). Any explicit get for a state returns the current setting in HA as expected, it is just the global context value that is out of step. If I then restart HA, they all get set correctly.

To Reproduce

Create an "expose as" switch on an events state node. Look at the state in HA and in the global context (Global - homeassistant - homeAssistant - states). Note how the switch disables the node. Then restart the node red addon, and look at the states again. HA will say ON or OFF as expected, the context will say unavailable. If you toggle the switch in HA, it corrects the context, as does an HA restart.

Expected behavior

The global context values for these switches should reflect the HA values after a node red restart, shouldn't be "unavailable".

Screenshots

No response

Example Flow

No response

Environment Information

Version: 0.65.1

Home Assistant version: 2024.8.1 Companion version: 4.0.1

Node-RED version: 4.0.2 Docker: yes Add-on: no

Node.js version: v18.20.3 arm64 linux OS: Linux 6.6.31-haos-raspi arm64

Additional context

No response

dpgh947 avatar Aug 12 '24 14:08 dpgh947