Hi, I'm trying to change a command from true to on and from false to off in order to make a state node for alexa work but It doesn't change the message and still give back TRUE and FALSE, I'll attach some pics.
What did i do wrong?
Thanks
Hi, I'm trying to change a command from true to on and from false to off in order to make a state node for alexa work but It doesn't change the message and still give back TRUE and FALSE, I'll attach some pics.
What did i do wrong?
Thanks
is it a string true and false (see the a z ) or Boolean True and False?
You should be able to tell by looking at the debug message.
I really don't know, this is the message
30 Aug 23:01:28 - [warn] [alexa-smart-home-v3-state:Luce Cucina] Luce Cucina sta te node: msg.payload missing state element!
30 Aug 23:01:28 - [info] [debug:8164d137.6a184] false
30 Aug 23:01:40 - [warn] [alexa-smart-home-v3-state:Luce Cucina] Luce Cucina state node: msg.payload missing state element!
30 Aug 23:01:40 - [info] [debug:8164d137.6a184] true
30 Aug 23:01:28 - [warn] [alexa-smart-home-v3-state:Luce Cucina] Luce Cucina sta te node: msg.payload missing state element!
30 Aug 23:01:28 - [info] [debug:8164d137.6a184] false
30 Aug 23:01:40 - [warn] [alexa-smart-home-v3-state:Luce Cucina] Luce Cucina state node: msg.payload missing state element!
I checked, it's a string (switch?) not boolean
Try;
[{"id":"46272d11.0c1764","type":"inject","z":"c53060.842a0fa","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1090,"wires":[["7c2fb603.bd9348"]]},{"id":"3b944448.a4189c","type":"inject","z":"c53060.842a0fa","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1150,"wires":[["7c2fb603.bd9348"]]},{"id":"7c2fb603.bd9348","type":"change","z":"c53060.842a0fa","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"ON","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1120,"wires":[["dc0fb137.8cb1b"]]},{"id":"dc0fb137.8cb1b","type":"debug","z":"c53060.842a0fa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":620,"y":1120,"wires":[]}]
True & False are boolean operators NOT strings!
Ok it's working, thank you
I am having the same issue only with numbers. My issue is that some of my devices use TIP120's and others use relays. The logic for each is opposite 0= on for relay or 1 = on for TIPS
I made a simple change node to convert them (using numbers and it works to convert the 1 to a zero but not the other way)
I have attached a picture of the debug screen and the change node configuration. I have tried many types of message types and none seem to work.
What am I missing?
Consider what happens when you pass in 0. The first Change will change it to a 1. Unfortunately the second will then change it back to a 0.
OK thank you, so how do I create a something that will flip a 1 to a 0 and a 0 to a 1? this is a bit of an issue for me because of the different hardware that I've used. I'm planning on rebuilding most of these and going to strictly relays but until then is there a way to convert one to the other?
Try this
Or the same in a function
msg.payload = msg.payload ? 0 : 1
which relies on anything non zero being the same as true in a test
That worked! thank you very much! That helps with many of these nodes! I'm going to save that thing. Thanks
That (and similar) is the one bit of JSONata that I use regularly. The rest just does not seem to fit the shape of my brain.
last thing, how do I make the output numbers not strings?
multiply by 1
My Jsonata example does generate numbers, for me anyway
[{"id":"ec018307.e0a388","type":"debug","z":"514a90a5.c7bae8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":561,"y":480,"wires":[]},{"id":"2121b60e.d3670a","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":156,"y":441,"wires":[["55f36242.6a68dc"]]},{"id":"d916496a.267c58","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":154,"y":503,"wires":[["55f36242.6a68dc"]]},{"id":"55f36242.6a68dc","type":"change","z":"514a90a5.c7bae8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload=1 ? 0 : 1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":346,"y":480,"wires":[["ec018307.e0a388"]]}]
This may be a good case where converting the hw-specific outputs to a String (i.e. "on" or "off") would make your flows more maintainable... at least your other nodes won't have to wonder if they are testing for the string "1" or the number 1.
FYI, in JS you can also coerce numeric "strings" to numbers by using the unary +
function:
msg.payload = +msg.payload;
return msg;
Of course, if you do not always expect your payload to be a valid numeric string, you should check to see if the unary +
returns a NaN
(not a number).