Get data out of object

This should be quite easy, but I don't see what's going wrong.

I receive an object. In this object you have the element 'Label' and 'CurrState'.

When labels has the value Sensor and Currstate is True, I just want to pass a '1' to trigger the next action.

I thought I could 'acces' the element label like Payload.Label, but that does not seems to be the case.

Here are some sreenshots;

  1. What my object looks like:
    image

  2. My actual function, just looking if sensor is in it. If it is I would expect a 1 at the output...
    This needs to be expand by also verifying the CurrState
    image

  3. What my function gives as output....
    image

[{"id":"ae21c3f.f339a4","type":"zwave-in","z":"154afdd3.672442","name":"MyStick","controller":"49a56b32.da7d44","x":157,"y":117,"wires":[["443ab2c6.2e546c","6951552d.f93a1c"]]},{"id":"6951552d.f93a1c","type":"debug","z":"154afdd3.672442","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":562,"y":115,"wires":},{"id":"443ab2c6.2e546c","type":"function","z":"154afdd3.672442","name":"test","func":"var x = payload.label;\n\nif (x== "Sensor") {\n var msg_o = {payload : 1}\n} else {\n var msg_o = {payload : 0}\n}\nreturn msg_o;\n\n\n","outputs":1,"noerr":0,"x":361,"y":170,"wires":[["64a6f96c.218658"]]},{"id":"64a6f96c.218658","type":"debug","z":"154afdd3.672442","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"Sensor","x":554,"y":178,"wires":},{"id":"49a56b32.da7d44","type":"zwave-controller","z":"","port":"/dev/ttyACM0","driverattempts":"3","pollinterval":"10000","allowunreadyupdates":false,"networkkey":"","logging":true}] Blockquote

Thx for having a look

You realise that there is a rather nice icon on the RHS of the line you highlight that lets you copy the path to the element?

Nope. It is msg.payload.label

Also, case is important in JavaScript so Payload wouldn't work anyway.

Hi,
thanks.

I did copy it, because first I used it like you mentioned.
But the result was not ok either.

Know I don't have the fault anymore, but my payload is 'undifined'?
I removed the ELSE, because othersiwe I get the 'undifined' after every message, now I get the undifened after the 'sensor' message.

So it is well reading msg.payload.label, but why don't I receive a nice '1'?

That’s a different error, this time caused by your output variable which you should declare as an object.

so try adding this line at the start of your function

var msg_o = {};

@NickB the highlighted debug messages are showing msg.Sensor - which is not defined in the message your Function node is returning.

Thanks to all. I've got it

@knolleary , I totally went wrong on msg.sensor. I just wanted to display a name on my debug node calling sensor. Offcourse the whole meaning is different like that.