Extracting data from string - need help please

Hi community

I have a couple of Shellies to control my home and try to build an automation in Nodered using a Shelly Button 1 and two lights. I use MQTT to get the buttons data as per https://shelly-api-docs.shelly.cloud/#shelly-button1 it has different push types I want to make use of.

automation I try to build
Shortpush = S | If shortpush is reported toggle light 1
Double Shortpush = SS | If double shortpush is reported toggle light 2

The payload from the button is
msg_payload

First I use a switch node to check if the msg.payload is of type string.

Then I use two switch nodes (I could probably use one) to determine if the string contains S or SS

The issue
If I use shortpush light 1 toggles, If I use double shortpush light 2 toggles BUT light 1 toggles too. This is probably because the string SS containts the letter S as well.

I did some research (here and in the internet) but could not find the solution for it. Could you please help me to get this thing running? I do have basic-knowledge of Nodered but very little in terms of JSON etc.

BTW: I am very happy to be part of this community and can hopefully help others some day.

Kind regards from snowy Switzerland

Andrew

Hi…Just use the Json node to convert this into an object and then a switch node as I have shown in the code.

[{"id":"8b113ac0.358ce8","type":"json","z":"51045e07.bbf87","name":"","property":"payload","action":"","pretty":false,"x":330,"y":60,"wires":[["ed585a.f2f287a8"]]},{"id":"ed585a.f2f287a8","type":"switch","z":"51045e07.bbf87","name":"","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"S","vt":"str"},{"t":"eq","v":"SS","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":60,"wires":[[],[]]}]

image

1 Like

many thanks for the quick reply. It works! this helps me also for further automations including JSON-data :wink:

1 Like