Get msg.payload : undefined on all devices I have stored in HA

Node “events: state” returns only mag.payload : undefined.
Node is running. In HA, I see when I turn on and off a lamp as an example. I see this in Node-Red as well but I only get “undefined” when the event occurs.
I guess I should at least get a payload that says on or off.
Have tested different apps, different devices but get the same results all the time.
I am new to both HA and Node-Red so I would be very grateful if someone could give me some suggestions on what to do.

Hi,

Firstly let me thank you for making me install the nodered and have a play and learn something new

After a bit of playing I came up with this flow to dump all the sensor states

[{"id":"b65fd414.421408","type":"debug","z":"2f0ea9da.39cca6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":840,"y":160,"wires":[]},{"id":"e974961a.f82518","type":"ha-get-entities","z":"2f0ea9da.39cca6","server":"c0171960.d12c88","name":"","rules":[],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":650,"y":160,"wires":[["b65fd414.421408"]]},{"id":"7be43d53.0fb9a4","type":"inject","z":"2f0ea9da.39cca6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"sensors","payloadType":"str","x":470,"y":160,"wires":[["e974961a.f82518"]]},{"id":"c0171960.d12c88","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Hope this helps

As I said I am quite new to this so this is a bit above my paygrade :slight_smile:
Where do I place the code?
Do I need to replace anything in the code?
Get entities only gives me error!
Thanks for trying…

Hi,

No problem, we all need to start somewhere :slight_smile:

In terms of the example code flow … copy the code and import it into nodered

image

All the best !

Good! Now it works :slight_smile:
Discovered that the problem is that Tuya has a long response time! Can take up to 3 minutes before on / off changes in HA after I turned on / off a lamp or switch with my phone.
Do you have a solution for that :slight_smile:
Thanks for the script…

Good news,

Sorry I too am a new user, I’m just trying to learn more by solving other’s problems :slight_smile:

I would also point you to the Developer tools > states section and you need a firm understanding on how to build configuration.yaml

Maybe put nodered on the sideline and concentrate of HA first ?
Remember Rome wasn’t built in a day so this may take some time but as soon as you’ve learned the concepts you should be able to solve any problem

Good luck !