Extracting value from MQTT payload

Hi there,

I’m making a garage door controller with an Electrodragon ESP based controller and ESPEasy. I’m using MQTT and have everything working fine and can turn both relays on with MQTT and receive the status back. The switches/inputs on the device (one anyway) will be used to track whether the door is up or down.

Problem is, I need to toggle the relay and I’m not sure down to do this. Maybe a script or automation but I’ve found that if you send /devicename/cmd with the payload pulse,13,1,2000, the relay will pulse for 2s which is perfect however, the relay state is no longer reported to HA (as I’m monitoring /devicename/relay1/state).

If I subscribe to /devicename/CMD, I get the following back when I publish the pulse command

pulse,13,1,2000

and then this when the relay turns off two seconds later.

{
"log": "GPIO 13 Pulsed for 2000 m",
"plugin": 1,
"pin": 13,
"mode": "output",
"state": 1
}

Anyone know how I could extract the data from both message to control the status of the GUI switch or is there a much simpler way?

SOLVED. In the rules section of ESPEasy, I simply added the following for my 'relay1 (GPIO13) that will control the garage door.

on relay1#state do
  if [relay1#state]=1
  timerSet 1,2 // 2 second timer
endon

on Rules#Timer=1 do
  gpio,13,0 // Turn off relay
endon

Now if I turn the relay on by any means, it goes off automatically after 2s. Perfect!