Function node zwave

#1

Hello everyone

i need some help with a function node i need the (brightness: 88) and i cant see what im doing wrong
TypeError: Cannot read property 'new_state' of undefined

var temp=payload.event.new_state.attributes.brightness; var msg = {payload:temp}; return msg;

{"event_type":"state_changed","entity_id":"light.fibaro_system_fgd212_dimmer_2_level_3","event":{"entity_id":"light.fibaro_system_fgd212_dimmer_2_level_3","old_state":{"entity_id":"light.fibaro_system_fgd212_dimmer_2_level_3","state":"off","attributes":{"node_id":3,"value_index":0,"value_instance":1,"value_id":"72057594093076481","power_consumption":0,"friendly_name":"Conservatory Wall Lights","supported_features":33},"last_changed":"2018-09-14T15:54:26.450143+00:00","last_updated":"2018-09-14T15:54:29.211623+00:00","context":{"id":"cc8abcc7961e4d2a9ae3945d4352c035","user_id":"51cd628db86c457ea8d904f8e85ec031"}},"new_state":{"entity_id":"light.fibaro_system_fgd212_dimmer_2_level_3","state":"on","attributes":{"brightness":88,"node_id":3,"value_index":0,"value_instance":1,"value_id":"72057594093076481","power_consumption":0,"friendly_name":"Conservatory Wall Lights","supported_features":33},"last_changed":"2018-09-14T15:54:34.742960+00:00","last_updated":"2018-09-14T15:54:34.742960+00:00","context":{"id":"caf54b82fd6247d881254e39edeeb0fb","user_id":"51cd628db86c457ea8d904f8e85ec031"}}}}
`
9/14/2018, 4:54:36 PMnode: 4c0696d1.8f5fe8state_changed : msg.payload : Object

object
event_type: "state_changed"
entity_id: "light.fibaro_system_fgd212_dimmer_2_level_3"

event: object
entity_id: "light.fibaro_system_fgd212_dimmer_2_level_3"

old_state: object

new_state: object
entity_id: "light.fibaro_system_fgd212_dimmer_2_level_3"
state: "on"

attributes: object
<brightness: 88
<node_id: 3
<value_index: 0
<value_instance: 1
<value_id: "72057594093076481"
<power_consumption: 0
<friendly_name: "Conservatory Wall Lights"
<supported_features: 33
last_changed: "2018-09-14T15:54:34.742960+00:00"
last_updated: "2018-09-14T15:54:34.742960+00:00"

context: object
id: "caf54b82fd6247d881254e39edeeb0fb"
user_id: "51cd628db86c457ea8d904f8e85ec031"
`

0 Likes

#2

try adding msg

var temp=msg.payload.event.new_state.attributes.brightness;
var msg = {payload:temp};
return msg;
0 Likes

#3

"TypeError: Cannot read property 'new_state' of undefined"

im so confused

0 Likes

#4

Probably you don't get all the properties, try this:

if (typeof msg.payload.event !== "undefined" &&
    typeof msg.payload.event.new_state !== "undefined" &&
    typeof msg.payload.event.new_state.attributes !== "undefined") {
        var temp=msg.payload.event.new_state.attributes.brightness;
        var msg = {payload:temp};
        return msg;
}
0 Likes

#5

ok that worked
thankyou

is there any way of filtering the information due to i can only get the information from ha all events using the (entity_id: "light.fibaro_system_fgd212_dimmer_2_level_3")
all other information to output2

0 Likes

#6

Sure, have a look at the switch node.

0 Likes

#7

thankyou for all you help

i dont know how to use the switch i have inserted but no luck do you mind helping me

[{"id":"7e75be74.94f1a","type":"debug","z":"cf1115c.2dcd6e8","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","x":1040,"y":840,"wires":[]},{"id":"b84a7f9a.24408","type":"server-events","z":"cf1115c.2dcd6e8","name":"HA All Events","server":"d0be6c93.2903a","x":350,"y":840,"wires":[["4c0696d1.8f5fe8","9e27736a.a3f04","9497c511.5839d8","1bfeac00.16e134"]]},{"id":"29e7db9a.11e0a4","type":"function","z":"cf1115c.2dcd6e8","name":"","func":"var temp=msg.payload.event.new_state.attributes.brightness;\nvar msg = {payload:temp};\nreturn msg;","outputs":1,"noerr":0,"x":850,"y":840,"wires":[["7e75be74.94f1a"]]},{"id":"266fe257.12a6be","type":"function","z":"cf1115c.2dcd6e8","name":"","func":"if (typeof msg.payload.event !== \"undefined\" &&\n typeof msg.payload.event.new_state !== \"undefined\" &&\n typeof msg.payload.event.new_state.attributes !== \"undefined\") {\n var temp=msg.payload.event.new_state.attributes.brightness;\n var msg = {payload:temp};\n return msg;\n}","outputs":1,"noerr":0,"x":850,"y":800,"wires":[["7e75be74.94f1a"]]},{"id":"9497c511.5839d8","type":"traffic","z":"cf1115c.2dcd6e8","name":"","property_allow":"payload","filter_allow":"zwave.fibaro_system_fgd212_dimmer_2_node_3","ignore_case_allow":false,"negate_allow":false,"send_allow":false,"property_stop":"payload","filter_stop":"","ignore_case_stop":false,"negate_stop":false,"send_stop":false,"default_start":false,"differ":false,"x":610,"y":860,"wires":[["29e7db9a.11e0a4"]]},{"id":"1bfeac00.16e134","type":"switch","z":"cf1115c.2dcd6e8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"entity_id: \"zwave.fibaro_system_fgd212_dimmer_2_node_3","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":610,"y":800,"wires":[["29e7db9a.11e0a4"]]},{"id":"d0be6c93.2903a","type":"server","z":"","name":"Home Assistant","url":"http://hassio/homeassistant","pass":"2552f5070e7f7fcd90304b72d4ebbe4372e315c4256d75073da877b6424dcdcc"}]

0 Likes

#8

something like this:

zwave-switch

0 Likes

#9

thankyou very much

0 Likes

#10

do you have z wave lighting
whats you name im chris

0 Likes