I'm trying to get Node-Red to report node state back to the Alexa app. I think i have most of it done but struggling with a debug error that says " msg.payload missing state element!""
The problem seems to be with my change command. I'm changing the value from my fibaro home controller which reports (true/false) to Alexas On/Off commands.
In the change settings i have the True/False set as a boolean and replaced with Json:
{
"acknowledge": true,
"payload": {
"state": {
"power": "ON"
}
}
}
It seems to output correctly in the debug but also shows the error and doesn't actually change the app at all so something is not quite right.
The alexa app is an iphone app where you control all of your devices, but it shows state also.
The message going into the change node is a simple true/false depending on if the light is on or off. Obviously this needs to be change to a ON/OFF for alexa to understand.
Excellent! Thanks you!
I think it's working, sort of as my Alexa app says that the light is currently on...However it's always on and wont detect the off change.
You can replace the change node with the function node altogether. But yes sorry I made the assumption that msg.payload is either true or false, which this test is looking for:
s = m ? "ON" : "OFF"
It is a shorthand version of if else and, ie: if msg.payload is true then "ON"
What is the incoming payload ?
Ok, I have removed the change node now and its hit and miss. Sometimes it works, sometimes it doesn't.
I think this is because the incoming message is a boolean true/false, not a string.
Is there a way to pick up on the boolean instead?
Thanks!
Edit, I can confirm this as the info under my TKB (hallway) node shows triggered when i turn the light on/off. However with your function script after the node it changes it to [object object] which when i look online means it's expecting a string but getting something else (boolean)
Are you sure these are the only messages that you receive from the mqtt/TKB node ?
Because it sounds like you receive additional/different messages and the test would fail.
You could change the function node to capture only true/false