Toggle a relais / relay for 1 second over MQTT?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
shep
New user
Posts: 4
Joined: 06 Jul 2017, 04:34

Toggle a relais / relay for 1 second over MQTT?

#1 Post by shep » 06 Jul 2017, 04:41

Hi guys:

I'm relatively new to espeasy, and must say it is really great.

I've gone through the forum in hopes of being able to control my garage door over MQTT, but can't seem to get a rule right to pulse / toggle a relay for 500ms, or even 1 second to simulate a button press. I am running espeasy v2.0.0-dev10, on a Wemos D1 Mini with a relay connected to GPIO 5. If I issue an http command as in:

http://192.168.0.xxx/control?cmd=Pulse,5,1,500

The relay pulses quickly to simulate a pulse / button press on the garage control, but I can't seem to get this going with any rules over MQTT. I also have a reed switch connected on GPIO 12 also to indicate status of the door, ( either opened or closed ), and have seen a few posts such as this one:
https://www.letscontrolit.com/forum/vie ... 9&start=20

and have tried the following rule, but it will not pulse the relay with the v2.0.0-dev10 code:

""
on button#state do
if [relay#state] = 0
GPIO,12,1
else
GPIO,12,0
endif
endon

on relay#state do
if [relay#state] = 1
gpio,13,0
else
gpio,13,1
endif
endon

on relay#state do
if [relay#state] = 1
Publish /sonoff2/gpio/12,1
else
Publish /sonoff2/gpio/12,0
endif
endon
""

can anyone please help with a rule to pulse a relay for 500ms or 1 second to simulate a button press?

Thanks very much!

shep
New user
Posts: 4
Joined: 06 Jul 2017, 04:34

Re: Toggle a relais / relay for 1 second over MQTT?

#2 Post by shep » 06 Jul 2017, 04:47

Also, here are my devices:
1_delete.jpg
1_delete.jpg (146.53 KiB) Viewed 10314 times

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Toggle a relais / relay for 1 second over MQTT?

#3 Post by grovkillen » 06 Jul 2017, 06:06

Code: Select all

on button#state do
 if [relay#state]=0
  Pulse,12,1,500
 else
  GPIO,12,0
 endif
endon

on relay#state do
 if [relay#state]=1
  GPIO,13,0
  Publish /sonoff2/gpio/12,1
 else
  GPIO,13,1
  Publish /sonoff2/gpio/12,0
 endif
endon
Just some formation and clean up of code. You might want to try this and get back with information. I did this on my phone.

PS. I don't see a "button" as a device in the screenshot? It is somewhat hard to grip what you are trying to do here so please give as much information as possible. Some garage doors has the possibility to just add a switch which will just short two io. I don't think that need to be pulsed more than a reasonable time, this would do:

GPIO,12,1
Delay 1000
GPIO,12,0
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

shep
New user
Posts: 4
Joined: 06 Jul 2017, 04:34

Re: Toggle a relais / relay for 1 second over MQTT?

#4 Post by shep » 07 Jul 2017, 22:26

Hi grovkillen. Thank you very much for your reply! Basically, what I am trying to do is connect a relay to my garage door button, inline with the existing two wires to simulate the press on the garage door opener, I have a relay on GPIO-5, and a reed switch on GPIO-12 that determines if the door is open or closed. Below is the screenshot of the devices, and how the relay is currently configured. I did try your code example without any luck. I am NOT using a sonoff device, but just a standard relay.
1.jpg
1.jpg (110.46 KiB) Viewed 10255 times
2.jpg
2.jpg (122.93 KiB) Viewed 10255 times

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Toggle a relais / relay for 1 second over MQTT?

#5 Post by grovkillen » 08 Jul 2017, 08:22

Code: Select all

on button#state do
This piece of code will never fire off since you don't have a device called "button".
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

shep
New user
Posts: 4
Joined: 06 Jul 2017, 04:34

Re: Toggle a relais / relay for 1 second over MQTT?

#6 Post by shep » 08 Jul 2017, 17:52

Thanks grovkillen. appreciated. Any idea what the code might look like based on the devices attached to pulse the relay momentarily for 500ms over MQTT? The following http command works great: http://192.168.0.145/control?cmd=Pulse,5,1,500
Just need to find a way or rule to get it to pulse when a 1 is received over MQTT

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Toggle a relais / relay for 1 second over MQTT?

#7 Post by grovkillen » 09 Jul 2017, 22:48

You can send that command over MQTT as well.

Topic

Code: Select all

<your_device_name>/cmd
Payload (message)

Code: Select all

Pulse,5,1,500
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

werner_g
Normal user
Posts: 31
Joined: 11 Jun 2017, 14:19

Re: Toggle a relais / relay for 1 second over MQTT?

#8 Post by werner_g » 10 Jul 2017, 13:08

What I learnt moving to V2.0.0 is that you need to add 'MQTT Input' as a device to set a topic. And of cource Controller subscripe/publish if you want to have a feedback of the Relay-status. I use this little rule
on mqtt_relay#state do
if [mqtt_relay#state]=0
gpio,5,0
else
gpio,5,1
endif
endon
to get this feedback. Hope this helps.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Toggle a relais / relay for 1 second over MQTT?

#9 Post by grovkillen » 10 Jul 2017, 17:25

werner_g wrote: 10 Jul 2017, 13:08 What I learnt moving to V2.0.0 is that you need to add 'MQTT Input' as a device to set a topic. And of cource Controller subscripe/publish if you want to have a feedback of the Relay-status. I use this little rule
on mqtt_relay#state do
if [mqtt_relay#state]=0
gpio,5,0
else
gpio,5,1
endif
endon
to get this feedback. Hope this helps.
https://www.letscontrolit.com/wiki/inde ... _2.0.2B.29

If your have set up the controller setting to subscribe to <unit name>/# you can send pretty much any command from this list:

https://www.letscontrolit.com/wiki/inde ... _Reference

Just use this topic: <unit name>/cmd
Work this payload/message: Pulse,5,1,500
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

werner_g
Normal user
Posts: 31
Joined: 11 Jun 2017, 14:19

Re: Toggle a relais / relay for 1 second over MQTT?

#10 Post by werner_g » 11 Jul 2017, 18:50

I am wondering why this doesn't work here (PiDome MQTT):

Code: Select all

Controller Subscribe:	any/set/WM/Relay01/#
Controller Publish:	any/state/WM/%sysname%

Topic: any/set/WM/Relay01/cmd
payload: GPIO,5,1
the relay is not switching!

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Toggle a relais / relay for 1 second over MQTT?

#11 Post by grovkillen » 11 Jul 2017, 20:26

werner_g wrote: 11 Jul 2017, 18:50 I am wondering why this doesn't work here (PiDome MQTT):

Code: Select all

Controller Subscribe:	any/set/WM/Relay01/#
Controller Publish:	any/state/WM/%sysname%

Topic: any/set/WM/Relay01/cmd
payload: GPIO,5,1
the relay is not switching!
Does this work?

Code: Select all

Topic: any/set/WM/Relay01/cmd
payload: reboot
I mean, does any other cmd work using that topic?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

werner_g
Normal user
Posts: 31
Joined: 11 Jun 2017, 14:19

Re: Toggle a relais / relay for 1 second over MQTT?

#12 Post by werner_g » 11 Jul 2017, 21:26

also not.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Toggle a relais / relay for 1 second over MQTT?

#13 Post by grovkillen » 12 Jul 2017, 00:09

And you need the subscription topic to be a none default one?

If you subscribe to the default one:

Code: Select all

%sysname%/#
And then send the <name of unit>/cmd with payload gpio,5,1 still doesn't work?

Just to try I mean...
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

werner_g
Normal user
Posts: 31
Joined: 11 Jun 2017, 14:19

Re: Toggle a relais / relay for 1 second over MQTT?

#14 Post by werner_g » 12 Jul 2017, 09:08

quite funny, I tried several things, at least changing again to OpenHAB-MQTT and now it works like it has to do:

Controller Subscribe: any/set/WM/Relay01/#
Controller Publish: any/state/WM/%sysname%

any/set/WM/Relay01/cmd
GPIO,5,1
But still 'cmd Reboot' doesn't work. Not the showstopper, I'm happy it is now working the standard way without adding the device 'MQTT Import'

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Toggle a relais / relay for 1 second over MQTT?

#15 Post by grovkillen » 12 Jul 2017, 10:15

Good that it works now. What version are you on?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

werner_g
Normal user
Posts: 31
Joined: 11 Jun 2017, 14:19

Re: Toggle a relais / relay for 1 second over MQTT?

#16 Post by werner_g » 12 Jul 2017, 17:46

v2.0.0-dev10

Post Reply

Who is online

Users browsing this forum: No registered users and 37 guests