I saw a remark that the output of the eWeLink CUBE add-on in Node-RED doesn’t output a Javascript object. It does output a string. See Not getting any events in Node-Red - #7 by csongor.varga And that appearantly is the culprit.
It turns out easy to solve: just use the node that converts a JSON string to Javascript objects and then use the rest of the code.
Below is a visual representation of how I solved it. Maybe this explanation can help others to get started. I hope eWeLink will improve the output of their nodes to get objects instead of strings. In that way the JSON conversion won’t be necessary anymore.
1. The flow
- At the left you see the “event - state” node. The device involved here is called “Maanlampjes” (litterally translated too “Little moon lights”, as they look like the half of a moon).
- Then you see the JSON converter.
- Then it splits up to a debug node and a switch node.
- The first debug node just outputs all payload data that the JSON converter converted.
- The switch checks whether the device has been switched on. Appearantly the iHost doesn’t send an “off” state, it only sends “on” or no “powerState” at all.
- Then the “on” part of the switch goes to a debug node which only outputs a text “Switched on”.
- The “not on” part of the switch goes to a debug node which only outputs a text “Switched off”.
2. JSON converter settings

- You can convert to a string and Javascript object, but I only need the Javascript object and so at
ActionI chooseAlways convert to JavaScript Object. - I set
Propertyto msg.payload. - The
Namecan be anything but I gave it a recognizable name. - The output will be just
msg.payloadagain, but then converted into a Javascript Object.
3. Switch settings
- At
NameI gave it a recognizable name. - This time I only want to check for an
onstate at the JSON data atpowerState. So atPropertyI filled in:msg.payload.power.powerState. - At the first rule I choose
==, thenStringand then I filled inon. - Then I added a second rule with the
+ addbutton below the list. - Then I choose
!=, thenStringand again filled inon. - At the bottom I left the dropdown at
checking all rulesand left therecreate message sequencesunticked.
4. Debug settings for on state

This is just for the on state, but the off state is only 2 letters difference.
-
Outputhas been set toExpressionand the contents is just the stringSwitched on. I felt more comfortable to open the extended editor by clickking on the...button, but I believe that is not necessary. - At
ToI only tickeddebug window. - At
NameI again filled in a recognizable name.

