Re: MQTT DASH Xiaomi Smart Button

257 views
Skip to first unread message
Message has been deleted

Andrzej Gromczyński

unread,
Feb 21, 2021, 5:38:10 AM2/21/21
to Routix
sorry for duplication a little problem with LTE connection :(
niedziela, 21 lutego 2021 o 11:35:41 UTC+1 Andrzej Gromczyński napisał(a):
Hello, 
 I am successfully using the MQTT Dash app with Mosquito and Zigbee2MQTT but ran into a problem. I have a xiaomi smart Buton, which publishes "single", "double", "triple", "quadruple", "many", "hold" and "release" states in its toppic in the action section and it's ok ... very nice I intercept this data into the text control and get the appropriate reaction, now I would like to capture what I have on the panel, e.g. double, in ON Receive, and pass the appropriate action to another Topic. for example: 

 if ("xxxx" == "single") 
{
     app.publish ('zigbee / SW2CH / state', '{"state_l2": "ON"}', false, 0); 
}
.....
 and so on ... maybe a Switch and a Case, but I have no idea how to get the information from the text field where I get the script according to $ .action? How to solve this and what variable to read from the text field to get the value of $ .action ... ?? Thank you for your help.

Routix.net

unread,
Feb 21, 2021, 5:45:45 AM2/21/21
to Routix
Can you please explain in more details this?:

> how to get the information from the text field where I get the script according to $ .action?

Andrzej Gromczyński

unread,
Feb 21, 2021, 6:36:30 AM2/21/21
to Routix
Hello and thank you for your quick reply. So yes, I have a Zigbee Xiaomi WXKG01LM button that I joined to mosquitto via zigbee2Mqtt and it works,
 I get a message in the

 zigbee / xiaomi topic {"action": "value", "battery": 98, "linkquality": 98, "voltage": 2997} 

 Action value takes the prescription of pressing the value: single, double, triple, quadruple, many, hold and release, 
this data is displayed in the text control using extract from JSON $ .action, 

it causes the string to be changed to action: value. now I want to redirect the appropriate action after receiving a certain value value so that when
 I receive a single post the appropriate message in the zigbee / switch / set topic for example: 

 I press the xiaomi button, I receive action = single and through On Receive I publish the controls in 
/ zigbee / switch / set {"state_l1": "ON"} 

= double publish / zigbee / switch / set {"state_l2": "ON"} 
 = triple I publish / zigbee / switch / set {"state_l1": "ON", "state_l2": "ON"} 
 = quadruple i publish / zigbee / switch / set {"state_l1": "OFF"} 

 and so on ... for mana, release it works fine when the message single, double and td comes in when I have 

ON RECEIVE written in app.publish ('zigbee / switch / set', '{"state_l1": "ON"}', false, 0); 

 but any attempts with if to check the value that came to the text control with action fail if I knew what variable is responsible 

for displaying the value from $ .action in the text field it might be possible to use

 IF (xxxx == single) app. publisch 
 or Switch Case e.g .: Switch"variable" 
case single 
        app.publish ...... 
         break 
case double 
        app.publish ..... 
        break 
.....

 and so on I don't know java script very well I hope I have described it clearly. Thank you for your help

Andrzej Gromczyński

unread,
Feb 21, 2021, 9:35:41 AM2/21/21
to Routix
IMG_20210221_152921.jpg
press Xiaomi  data change ok:  single , double , triple .....

IMG_20210221_152951.jpg

Thanks for help

Vadim Mostovoy

unread,
Feb 22, 2021, 2:53:36 AM2/22/21
to sunr...@gmail.com, Routix
Ahhh. There should be a "Help" button in the script editor window, which leads to a web page.

So, you can use "event.payload", which contains received raw data, in your case it's JSON string.
You need first convert your data to javascript object and then you can use it.
E.g.:

var obj = JSON.parse(
event.payload);
switch(obj.action) {
    // do what you need
}

Of course it's better to wrap json parsing into try ... catch.

--
Thanks,
Vadim Mostovoy


--
You received this message because you are subscribed to the Google Groups "Routix" group.
To unsubscribe from this group and stop receiving emails from it, send an email to routix+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/routix/27829b3c-a454-4b42-8451-9881b7369fddn%40googlegroups.com.

Andrzej Gromczyński

unread,
Feb 22, 2021, 3:06:38 PM2/22/21
to Routix
Hello
Thanks a lot, now I know how to combine with this case
Greetings. 

Andrzej Gromczyński

unread,
Feb 22, 2021, 3:43:28 PM2/22/21
to Routix
Hello

Unfortunately, Switch ... case did not work well, as well as Try ... catch,
but the combination If .. else if works very well

Thanks a lot for the guidance, now the Xiaomi Mi button works exactly as I wanted :)
Reply all
Reply to author
Forward
0 new messages