Forward payload to "On tap" function

147 views
Skip to first unread message

Jan M

unread,
Jan 22, 2022, 11:16:10 AM1/22/22
to Routix
Hi, 

I'm facing a problem with my new Shelly devices (Gen2). In order to turn them on/off, I need to publish an MQTT message with the following payload: 
'{"id" : 123, "src" : "test", "method" : "Switch.Set",  "params" : {"id" : 0,  "on" : true}'
where the value of "on" changes to false for turning them off. 
I solved this by using the On-tap function:
event.preventDefault = true
app.publish('home/shelly1/rpc, '{"id" : 123, "src" : "sofa", "method" : "Switch.Set",  "params" : {"id" : 0,  "on" : true}', false, 0)

The status is reported on another topic and I can extract the correct value from the JSON. 

What I did not mange is to send the on/off command with the same button. In the configuration of the button, I set the ON command to true and the OFF to false. But how can I mange to access the value in the function? 
I'm looking for something like:
app.publish('home/shelly1/rpc, '{"id" : 123, "src" : "sofa", "method" : "Switch.Set",  "params" : {"id" : 0,  "on" : valuefromONOFFfield}', false, 0)
where valuefromONOFFfield is the value that is normally (i.e without the on tap) sent. 
Reply all
Reply to author
Forward
0 new messages