Page 1 of 1

Control relay with physical locally button

Posted: 16 Nov 2017, 23:22
by QcVictor
Hi Guys
I'use with success an relay with esp8266 + domoticz for controlling dry contact, I need to add a button locally like press physical button and relay change state without need network access, the best will be updated status in domoticz....
Not sure how to do that, if somebody as already experienced this kind of setup ?
Regard, Vic

Re: Control relay with physical locally button

Posted: 17 Nov 2017, 04:31
by budman1758
There are a few ways to make that happen. Mostly depends on your hardware. If you want a pushbutton switch you will need to set it up on another GPIO and set up a rule to toggle the relay. If using a on-off switch you can probably use it to control the relay and set up a task on the GPIO that controls the relay that monitors the high or low state of the pin.

The Wiki is your friend.....

https://www.letscontrolit.com/wiki/inde ... rial_Rules
https://www.letscontrolit.com/wiki/index.php/Switch

Re: Control relay with physical locally button

Posted: 17 Nov 2017, 16:43
by QcVictor
Ok I attached Momentary Button and expect toggle between on/off switch relay, any clue for rules ?

Re: Control relay with physical locally button

Posted: 17 Nov 2017, 16:54
by grovkillen
Budman gave you the correct link.... But since you missed the info anyway, here you go - direct link : https://www.letscontrolit.com/wiki/inde ... long_press

Re: Control relay with physical locally button

Posted: 17 Nov 2017, 18:06
by QcVictor
I tried with this rules:

Code: Select all

on Button#Status=1 do
  if [Relay#Status]=0
    gpio,15,0
  else
    gpio,15,1
  endif
endon
nothing work!
Here's my setup:
Device1
Device: Switch input
Name: Relay
Delay: 0
IDX/Var: 1
1st GPIO: GPIO-15
Pull UP: Yes
Inversed: No
Switch Type: Switch
Switch Button Type: Normal Switch
Send Boot State: Yes
Send Data: Yes
Value Name 1: Switch

Device2
Device: Switch input
Name: Button
Delay: 0
IDX/Var: 150
1st GPIO: GPIO-2
Pull UP: Yes
Inversed: No
Switch Type: Switch
Switch Button Type: Normal Switch
Send Boot State: No
Send Data: No
Value Name 1: Switch

Re: Control relay with physical locally button

Posted: 17 Nov 2017, 18:47
by grovkillen

Code: Select all

on Button#Status do
  if [Button#Status]=1
    gpio,15,0
  else
    gpio,15,1
  endif
endon
The relay doesn't need to be a device. Please study the wiki.

Re: Control relay with physical locally button

Posted: 17 Nov 2017, 19:41
by QcVictor
tks Grovkillen for your help, rule doesn't work
I should see in the log rule started ?

Code: Select all

2180454 : WD : Uptime 36 ConnectFailures 0 FreeMem 22048
2185128 : SW : State 0
2185128 : EVENT: Button#Button=0.00
2186744 : SW : State 1
2186744 : EVENT: Button#Button=1.00
2198148 : SW : State 0
2198149 : EVENT: Button#Button=0.00
2199865 : SW : State 1
2199865 : EVENT: Button#Button=1.00
2210455 : WD : Uptime 37 ConnectFailures 0 FreeMem 22048

Re: Control relay with physical locally button

Posted: 17 Nov 2017, 20:09
by grovkillen
You are naming the value "button" as well! Change value name to "status" as stated in the rule.

PS: GPIO 15 is not the best to use with relays (https://www.letscontrolit.com/wiki/inde ... figuration)

Re: Control relay with physical locally button

Posted: 17 Nov 2017, 22:26
by QcVictor
Awsome it's working, many tks Grovkillen.
So where I put the request for update the status in domoticz? something like that

Code: Select all

SendToHTTP 10.0.0.18:8080/json.htm?type=command&param=udevice&idx=55&nvalue=1

Re: Control relay with physical locally button

Posted: 17 Nov 2017, 22:48
by grovkillen
I'm not a Domoticz user but yes you may use a http command.

Re: Control relay with physical locally button

Posted: 17 Nov 2017, 23:38
by QcVictor
I have a strange character after "command" in the log and of course doesn't work

Code: Select all

15878769 : ACT : gpio,15,1
15878771 : SW : GPIO 15 Set to 1
15878776 : ACT : SendToHTTP 10.0.0.18:8080/json.htm?type=command¶m=udevice&idx=55&nvalue=0

Re: Control relay with physical locally button

Posted: 18 Nov 2017, 01:14
by budman1758
Try this as your sendto.....

SendToHTTP 10.0.0.18,8080,/json.htm?type=command¶m=udevice&idx=55&nvalue=0

Re: Control relay with physical locally button

Posted: 18 Nov 2017, 01:25
by QcVictor
found in the wiki rules turnaround where is said to use this syntax

Code: Select all

 SendToHTTP 10.0.0.0,8080,/json.htm?type=param=switchlight&command&idx=55&switchcmd=On
I tried but nothing update in domoticz and
unfortunately I just want update the status not toggle the switch

Re: Control relay with physical locally button

Posted: 18 Nov 2017, 07:28
by enesbcs
QcVictor wrote: 18 Nov 2017, 01:25 unfortunately I just want update the status not toggle the switch
I do not think that you can update switch status without actually switching it...
Perhaps you can use Selector switch in domoticz, with different actions at different levels, or you can update a User variable, that you can manage in the Domoticz side in LUA.
In LUA then you can use "UpdateDevice".

Re: Control relay with physical locally button

Posted: 18 Nov 2017, 14:35
by QcVictor
yeah, got it working just use this syntax and all good

Code: Select all

SendToHTTP 10.0.0.18,8080,/json.htm?param=udevice&type=command&idx=55&nvalue=1

Re: Control relay with physical locally button

Posted: 21 Nov 2017, 23:44
by kimot
Put it next line after you change gpio status.
But I use different command:

Code: Select all

SendToHTTP 192.168.1.253,8080,/json.htm?type=command&param=switchlight&idx=26&switchcmd=On
You mus send command for report "off" status too

Code: Select all

SendToHTTP 192.168.1.253,8080,/json.htm?type=command&param=switchlight&idx=26&switchcmd=Off