Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read an entity state #34

Closed
Sakke64 opened this issue Oct 3, 2023 · 7 comments
Closed

Read an entity state #34

Sakke64 opened this issue Oct 3, 2023 · 7 comments

Comments

@Sakke64
Copy link

Sakke64 commented Oct 3, 2023

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
Copy link
Owner

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
Copy link
Author

Sakke64 commented Oct 6, 2023

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
Copy link
Owner

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
Copy link
Author

Sakke64 commented Oct 9, 2023

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
Copy link
Owner

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

@Sakke64
Copy link
Author

Sakke64 commented Oct 11, 2023

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
Copy link
Author

Sakke64 commented Oct 11, 2023

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

@Sakke64 Sakke64 closed this as completed Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants