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

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


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



1 Like

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

1 Like