shaonianzhentan / node-red-contrib-ha-mqtt

在HomeAssistant中生成MQTT实体
https://github.com/shaonianzhentan/node-red-contrib-ha-mqtt
MIT License
37 stars 19 forks source link

Read an entity state #34

Closed Sakke64 closed 10 months ago

Sakke64 commented 10 months ago

Is there way to read and publish and entity (switch, sensor, ...) state to the MQTT broker asynchronously i.e. not based on entity state change but an external trigger? There is, for example, node "current state" node in the node-red-contrib-home-assistant-websocket palette for such reading. Unfortunately, my node-red installation is not on the HA machine but on the plain RPi OS client machine. So, is this possible one or other way for entitity nodes created by the node-red-contrib-ha-mqtt? Actual problem is, the HA on the other machine looses entities state always after some time period. Some sensors like temperature ones one updated regular way and state is maintained, but for example switches and numbers state are not updated on the client machine. For sure I can build some tricks to store states locally and update entities w/ a current state, but I'l like to use more elegant way. This is also some relatated to my other issue about the retain flag. I guess if retain flag would be supported, HA would maintain entities state, but I'm not 100% sure.

shaonianzhentan commented 10 months ago

Is there way to read and publish and entity (switch, sensor, ...) state to the MQTT broker asynchronously i.e. not based on entity state change but an external trigger? There is, for example, node "current state" node in the node-red-contrib-home-assistant-websocket palette for such reading. Unfortunately, my node-red installation is not on the HA machine but on the plain RPi OS client machine. So, is this possible one or other way for entitity nodes created by the node-red-contrib-ha-mqtt? Actual problem is, the HA on the other machine looses entities state always after some time period. Some sensors like temperature ones one updated regular way and state is maintained, but for example switches and numbers state are not updated on the client machine. For sure I can build some tricks to store states locally and update entities w/ a current state, but I'l like to use more elegant way. This is also some relatated to my other issue about the retain flag. I guess if retain flag would be supported, HA would maintain entities state, but I'm not 100% sure.

After restarting HA, there will indeed be a loss of entity status, which is caused by my mandatory specification of the retain flag. I will address this issue in future versions and let users choose their own implementation method

Sakke64 commented 10 months ago

Hi! Thank you, I'd appreciate if retain flag can be set per topic in the future. It seems entities state is lost in the HA even the HA do not restart. There is some other constraint (time, mqtt broker behaviour, ...?) what causes state loss in the HA. One odditional questions, where a node-red-contrib-ha-mqtt entity state is stored when the HA is not installe on the same machine? Is it possible to some way read an entity state from a memory?

shaonianzhentan commented 10 months ago

This node does not store state, and by default, restarting HA will lose all states. But you can use the discovery node to solve the problem of lost configuration. It subscribes to homeassistant/status and will reconfigure everything when it receives an online message sent by HA

Sakke64 commented 10 months ago

You mean Auto Discovery node? I'm using it already, but it doesn't help. That's why I'm thinking problem is not on the HA side.

shaonianzhentan commented 10 months ago

The new version has been fixed, check 'retain' in the device

Sakke64 commented 10 months ago

After one day, it seems this fix works perfectly so far! States has never been completely available after a night before this fix but now they are. Thank you very much!

Sakke64 commented 10 months ago

I just bought you a cup of coffee, or tea if you prefer, with a cake! :)