Switch value not updating when operated from Domoticz

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
schizoidbunny
Normal user
Posts: 3
Joined: 16 Aug 2016, 15:57

Switch value not updating when operated from Domoticz

#1 Post by schizoidbunny » 16 Aug 2016, 16:19

Hi everyone,

I have flashed a couple of Sonoffs with ESP Easy and set them up with Domoticz to turn lamps on and off.

The Sonoff has a relay on gpio 12 and a momentary button on gpio 0.

I am using simple HTTP calls inside a dummy switch in Domoticz to control the relay (cmd=gpio,12,1 | cmd=gpio,12,0) on the board and have created a device tied to gpio 0 in ESP Easy with the corresponding IDX value.

I can control the relay from Domoticz and from the button. However, when I activate the relay from Domoticz, the value of the switch in ESP Easy is not updated. This means that I have to push the button twice for it to take action.

Example scenario

The light is off. The dummy switch in Domoticz shows it is off, the Switch device in ESP Easy has the value 0.
Now, I turn the light on in Domoticz by sending the HTTP call gpio,12,1 to ESP Easy. The light turns on. The value of the switch device tied to gpio 0 remains 0.
At this stage, if I want to turn off the light using the button on gpio 0, I have to press it twice : the first time, the value will switch from 0 to 1, triggering the gpio,12,1 call in Domoticz, but since the lamp is already on, nothing happens. Pressing the button a second time makes the value of the Device 0, triggering the gpio,12,0 call in Domoticz which turns the lamp off.


I have tried playing with rules to work around this and updated the Sonoff the the R120 release so I could try the new taskvalueset. In Domoticz, the HTTP call would trigger an event in the rules (cmd=event,switchon | cmd=event,switchoff)

on switchon do
gpio,12,1
taskvalueset,1,1,1
endon

on switchoff do
gpio,12,0
taskvalueset,1,1,0
endon

This does turn the lamp on and off and does update the value of the device. However, the device acts as if its value still was what it originally was before the taskvalueset instruction. So I still have to press the button twice to revert an action initiated from Domoticz.

Any help is appreciated! Eventually, I will not be using a momentary button but a regular on/off switch.

costo
Normal user
Posts: 490
Joined: 21 Nov 2015, 15:03

Re: Switch value not updating when operated from Domoticz

#2 Post by costo » 17 Aug 2016, 17:06

For the SonOff it is explained on the forum several times.

In Domoticz:
Switch type: On/Off
On Action: http://[localIP]/control?cmd=event,switchon
OffAction: http://[localIP]/control?cmd=event,switchoff


In ESPEasy on localIP webinterface:
Devices:
Task - Device - Name - Port - IDX/Variable - GPIO - Values
1 - Switch input - Switch1 - .. - 431 - GPIO-0 - Switch1:[0/1]
Pull Up [x] (probably not necessary)
Switch Type Switch
Switch Button Type: Push Button Active Low
Send Boot state [x]
Send Data [x]
Optional Settings:
Value Name 1: Switch1

in Rules:
-----------------------------------
on switchon do
gpio 12,1
gpio 13,0
inputswitchstate 0,1
endon

on switchoff do
gpio 12,0
gpio 13,1
inputswitchstate 0,0
endon

on Switch1#Switch do
if [Switch1#Switch]=1
event switchon
else
event switchoff
endif
endon
-------------------------------

GPIO13 is the green Led in the SonOff.

edit: b.t.w. I am not the maker of this script someone else on the forum published it first.

schizoidbunny
Normal user
Posts: 3
Joined: 16 Aug 2016, 15:57

Re: Switch value not updating when operated from Domoticz

#3 Post by schizoidbunny » 04 Sep 2016, 11:32

Thank you so much! I'll test this as soon as I'm back from vacation.

rt45433
Normal user
Posts: 3
Joined: 06 Aug 2016, 21:13

Re: Switch value not updating when operated from Domoticz

#4 Post by rt45433 » 04 Sep 2016, 12:40

Hi there, I am also trying to accomplish the same task. I have used the rules as suggested above which is turning it on and off through domoticz, but i am still having to press the button on the sonoff twice after it has been switched off from domoticz, it seems that the inputswitchstate 0,1 is not updating the switch status. Is there anything i need to double check or do? Pressing the button on and off on the sonoff is working with the rules posted above. It is not updating the status of the switch input when turned on/off with domoticz,

Can anyone please help with this? Also is there a way to have the dummy switch in domoticz to turn on when the switch is pressed on the sonoff as a two way status?

costo
Normal user
Posts: 490
Joined: 21 Nov 2015, 15:03

Re: Switch value not updating when operated from Domoticz

#5 Post by costo » 04 Sep 2016, 16:19

You probably have a naming issue, different names in the rules section that are not the same as in the device section.

Or if you mean the status of the switch in ESPEasy in the devicetab, then you have to refresh your screen in the browser.

rt45433
Normal user
Posts: 3
Joined: 06 Aug 2016, 21:13

Re: Switch value not updating when operated from Domoticz

#6 Post by rt45433 » 04 Sep 2016, 21:28

Thanks for the reply

Here is the rule code, I have also taken a screenshot of the devices, would it be possible to have a look to see if I have gone wrong somewhere. All my names looks to be correct. If I turn off the switch in domoticz, i then have to press the switch twice on the sonoff for it to switch again.

on switchon do
gpio 12,1
inputswitchstate 0,1
endon

on switchoff do
gpio 12,0
inputswitchstate 0,0
endon

on sw_1#Switch1 do
if [sw_1#Switch1]=1
event switchon
else
event switchoff
endif
endon
Attachments
Screen Shot 2016-09-04 at 20.13.30.png
Screen Shot 2016-09-04 at 20.13.30.png (72.76 KiB) Viewed 9317 times

costo
Normal user
Posts: 490
Joined: 21 Nov 2015, 15:03

Re: Switch value not updating when operated from Domoticz

#7 Post by costo » 05 Sep 2016, 12:42

Rules and names seems to be good. (if i substitute the names you used in my rules & device, it works)

Do you have these actions in domoticz?

On Action: http://192.168.178.111/control?cmd=event,switchon
Off Action: http://192.168.178.111/control?cmd=event,switchoff

If that is also good then you can probably show a picture how your Switch device is configured.

b.t.w. I do not have the relay task in my devices as the control over the relais is done by the script.
So you probably should remove task1, the relais

schizoidbunny
Normal user
Posts: 3
Joined: 16 Aug 2016, 15:57

Re: Switch value not updating when operated from Domoticz

#8 Post by schizoidbunny » 11 Sep 2016, 22:59

The script works for me when using a momentary button, but it I'm running into a wall when trying to use it with a regular on/off switch. Any ideas?

costo
Normal user
Posts: 490
Joined: 21 Nov 2015, 15:03

Re: Switch value not updating when operated from Domoticz

#9 Post by costo » 12 Sep 2016, 00:56

schizoidbunny wrote:The script works for me when using a momentary button, but it I'm running into a wall when trying to use it with a regular on/off switch. Any ideas?
This script is written to work only with a momentary push button (as is found at GPIO0 on a sonoff switch), it will not work with a normal switch.
So either you change the script to work (also) with a normal switch or you change your normal switch into a momentary pushbutton.
The last is probably the easiest for someone who is running into a wall with the script ;)

beou
Normal user
Posts: 8
Joined: 12 Nov 2016, 17:34

Re: Switch value not updating when operated from Domoticz

#10 Post by beou » 05 Jan 2017, 17:08

costo wrote:For the SonOff it is explained on the forum several times.

In Domoticz:
Switch type: On/Off
On Action: http://[localIP]/control?cmd=event,switchon
OffAction: http://[localIP]/control?cmd=event,switchoff


In ESPEasy on localIP webinterface:
Devices:
Task - Device - Name - Port - IDX/Variable - GPIO - Values
1 - Switch input - Switch1 - .. - 431 - GPIO-0 - Switch1:[0/1]
Pull Up [x] (probably not necessary)
Switch Type Switch
Switch Button Type: Push Button Active Low
Send Boot state [x]
Send Data [x]
Optional Settings:
Value Name 1: Switch1

in Rules:
-----------------------------------
on switchon do
gpio 12,1
gpio 13,0
inputswitchstate 0,1
endon

on switchoff do
gpio 12,0
gpio 13,1
inputswitchstate 0,0
endon

on Switch1#Switch do
if [Switch1#Switch]=1
event switchon
else
event switchoff
endif
endon
-------------------------------

GPIO13 is the green Led in the SonOff.

edit: b.t.w. I am not the maker of this script someone else on the forum published it first.

Hello costo!! The rules you suggested works very well!! As i have tested, if for some reason the domoticz gets offline (for example no power to the Rasp PI), then the sonoff plug cannot work any more!! Can you imagine a rule scenario that allows the sonoff to be controlled even with no connection to the domoticz? For example the user wants to switch on or off using the pushbutton.

danielchagasrs
Normal user
Posts: 20
Joined: 09 Jan 2017, 20:20
Location: Porto Alegre / Brazil

Re: Switch value not updating when operated from Domoticz

#11 Post by danielchagasrs » 09 Jan 2017, 20:37

I spent hours trying, but no matter what I change, I'm always stuck with the problem of having to press the button twice, when triggerd by domoticz.
Here is my setup at this time:

<< DOMOTICZ: >>
kitchen dummy switch, IDX 76
actions:
On: http://192.168.25.156/control?cmd=event,kitchenon
Off: http://192.168.25.156/control?cmd=event,kitchenoff
======================================
======================================
ESP devices:

Name: kitchen_light:
Type: input switch (normal switch, inversed),
IDX: 76
GPIO: 14
Send data = on
Value name: Switch
---------------------
Name: kitchen_btn:
Type: Push button type input switch (push btn, active low).
IDX: 76
GPIO: 3
Send data = on
Value name: Switch
-----------------------
<< RULES: >>
on kitchen_btn#Switch do
if [kitchen_btn#Switch]=1
event kitchenon
else
event kitchenoff
endif
endon

on kitchenon do
gpio,14,0
inputswitchstate,3,1
endon

on kitchenoff do
gpio,14,1
inputswitchstate,3,0
endon

===========================
What am I doing wrong?
I tried taskvalueset... it changes the value under devices tab, but still need to press twice to take the action.
inputswitchstate doesnt do anything.

danielchagasrs
Normal user
Posts: 20
Joined: 09 Jan 2017, 20:20
Location: Porto Alegre / Brazil

Re: Switch value not updating when operated from Domoticz

#12 Post by danielchagasrs » 09 Jan 2017, 21:19

I just had an idea, and it worked for me... maybe it's not the best solution, but it's simple and works fine.

========================
on kitchen_btn#Switch do
if [kitchen_light#Switch]=0
gpio,14,0
else
gpio,14,1
endif
endon
========================

It's a very basic toggle event...

Before this, I tried this one:
">>>>>>>>>>>>>
on kitchen_btn#Switch do
SendToHTTP domoticz_ip,8080,/json.htm?type=command&param=switchlight&idx=174&switchcmd=Toggle
endon
"<<<<<<<<<<<<<
but the "&param=" gets replaced by a weird symbol and the toggle doesn't work...

vojtishek
Normal user
Posts: 70
Joined: 12 Jan 2017, 08:00

Re: Switch value not updating when operated from Domoticz

#13 Post by vojtishek » 03 Feb 2017, 13:27

Hi all,

regarding momentary push button, It can be wired to the Sonoff to turn it off/on or pair a remote control to it.
You just need to solder it on contacts on current momentary button.
But be aware, it will not allow you to use classic wall switch, you need something like a "doorbell switch".

Whole job described here

http://support.iteadstudio.com/support/ ... /page/last

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests