Spartan-II-117 / node-red-contrib-home-assistant-llat

Home Assistant + Node-Red
MIT License
31 stars 5 forks source link

Question about current-state-api node #26

Open jncanches opened 6 years ago

jncanches commented 6 years ago

Hi guys and thank you for this fork. The original one is pretty buggy :(

I posted an issue on original project that says:

Running a 0.3.2 node-red-contrib-home-assistant on an hassbian freshly installed. I have copied my node using import function of node-red and all my get current state nodes log "local state cache missing, sending empty payload". Of course those nodes break the flow :( I have spent hours searching how to correct that :( Any suggestion ? Environment : Node Red Version: 0.18.7 NR Home Assistant Plugin Version: 0.3.2 Is Node Red running in Docker: no

And I analysed a little bit the problem :

Ok, so I analyzed the code and done some tests. Since v0.3.0, the cache is created on rebbot by calling http:///api/states which returns all states of HA. On a RPI this call could be pretty long. During this, if a call to a api_current_state is made, it will return an empty payload because the cache has not set yet... OMY, cache should be built on the fly when calling api_current_state, not with a very big call at start up... I ended up revert back to 0.2.1 version. Perhaps I will have time to make a fork. I hope this will help some of you with this problem.

Do you think this problem has been solved in your project so I can use it ?

Great work guys !

Spartan-II-117 commented 6 years ago

I have not re-architectured the back-end of this project, nore do i have the skill to do so, if you have a PR to fix this issue, it will be considered. but it sounds like your method would be even slower as it would wait unit\til current-state was called to fetch the state. how long does it wait currently before it has the states working properly?

jncanches commented 6 years ago

Sorry for the delay. I don't have too much time. Thank you for your response. To answer your question, i have a huge HA configuration and about fifteen flows that starts with a current state node. My install runs on a raspberry pi 3b+ with both HA and nodered (hassbian, not hassio) Sometimes original version of this plugin, can take 2 or 3 minutes to get current-state response :-(

That's weird after all... Is anyone have the same problem on a similar configuration ?

(Sorry for my english mistakes, I'm french :-) )

Great work spartan

Spartan-II-117 commented 6 years ago

unfortunately making the change you suggest will make the flow more computationally heavy, since at every current_state node it will have to query home-assistant, rather than just check it's own state table. I have ~20 current state nodes in my flows, and they all work within a few seconds of node-red starting up, I run my install on an older mini computer with a decent processor and 8 GB of ram, so your best bet might be to migrate to a more powerful computer.

jncanches commented 6 years ago

I moved from an energy-eater computer to a raspberry in order to save the planet (and my bank account :p ) But anyway, I will give this fork a try. I made some major changes recently and my setup has significantly speed up. I will post result here.

Thanks for your feedback !

jncanches commented 6 years ago

For those who have troubles with that, see my comment/fix in https://github.com/Spartan-II-117/node-red-contrib-home-assistant/issues/34