I’m completely new to Node RED and although it seems to be a nice system I’m struggling to use a specific variable/value in the JSON tree.
I have a flow that fetches the changed device status of a Sonoff S26R2 and this is the output:
How can I get that
powerState value to use in a mssage for e.g. debug, PushBullet message, etc.?
I tried to write these at such nodes:
But all leads to the output value
Can anyone explain me what I did wrong and how to get the
If you use node
the syntax is
in the next node, succes. I am new in node-red also!
I don’t have the time to check directly, but I believe I use a noce called like “Control device” or so. But your answer gives me a new clue to try out!
payload could be the solution.
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
Action I choose
- I set
Property to msg.payload.
Name can be anything but I gave it a recognizable name.
- The output will be just
3. Switch settings
Name I gave it a recognizable name.
- This time I only want to check for an
on state at the JSON data at
powerState. So at
Property I filled in:
- At the first rule I choose
String and then I filled in
- Then I added a second rule with the
+ add button below the list.
- Then I choose
String and again filled in
- At the bottom I left the dropdown at
checking all rules and left the
recreate message sequences unticked.
4. Debug settings for
This is just for the
on state, but the off state is only 2 letters difference.
Output has been set to
Expression and the contents is just the string
Switched on. I felt more comfortable to open the extended editor by clickking on the
... button, but I believe that is not necessary.
To I only ticked
Name I again filled in a recognizable name.
See my reply above. Without conversion from string to object it is not possible to call the value in your proposed way.