Sonoff reflect state of button to Domoticz

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
vojtishek
Normal user
Posts: 70
Joined: 12 Jan 2017, 08:00

Sonoff reflect state of button to Domoticz

#1 Post by vojtishek » 07 May 2017, 18:12

Hi all,

Maybe some of you have better experience than me.
I have a light connected to sonoff and using following settings to achieve that push button on sonoff will reflecting status in domoticz.
Unfortunately not working and push button didn´t change status in domoticz.

Image
Image
Image

Thanks for any tip/hint

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

Re: Sonoff reflect state of button to Domoticz

#2 Post by grovkillen » 07 May 2017, 19:16

Well the rule of the button never sends any status to your Domoticz server. You simply just change the GPIO status, that's it. I don't use Domoticz myself so I cant really help you in detail but to my knowledge the Domoticz server is able to talk to a MQTT server or if this is to complicated you might want to do a HTTP call from the ESPeasy rule to the Domoticz server?

A example rule:

Code: Select all

on Momentary#Switch do
 if [Momentary#Switch]=1
  gpio,12,1
  SendToHTTP <Domoticz Server IP>,<Port Number>,<Command For On>
 else
  gpio,12,0
  SendToHTTP <Domoticz Server IP>,<Port Number>,<Command For Off>
 endif
endon
More info Domoticz WIKI 1
More info Domoticz WIKI 2
More info ESPeasy WIKI 1
More info Domoticz WIKI 2
Last edited by grovkillen on 07 May 2017, 19:24, edited 1 time in total.
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:

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Sonoff reflect state of button to Domoticz

#3 Post by costo » 07 May 2017, 19:21

I think it works if you change the last part of your rules to:

on Momentary#Switch do
if[Momentary#Switch]=1
event lamp_on
else
event lamp_off
endif
endon

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

Re: Sonoff reflect state of button to Domoticz

#4 Post by grovkillen » 07 May 2017, 19:24

costo wrote: 07 May 2017, 19:21 I think it works if you change the last part of your rules to:

on Momentary#Switch do
if[Momentary#Switch]=1
event lamp_on
else
event lamp_off
endif
endon
Doooh! You´re right! :)

EDIT: ... or second thought, will it? Please confirm.
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:

Madbanana
Normal user
Posts: 13
Joined: 16 Oct 2016, 20:48

Re: Sonoff reflect state of button to Domoticz

#5 Post by Madbanana » 07 May 2017, 19:38

I have this working here with a Sonoff socket ...

My rule is the same as your third block in principle except I don't understand the need for your first and second...

on SW_1#Switch do
if [SW_1#Switch]=0
gpio,12,0
else
gpio,12,1
endif
endon

My device setup is the same as yours with IDX matching the switch in Domoticz.

My Domoticz setup is the same as yours.

One thing you could try - delete and then recreate the switch in Domoticz - I had to do this after one stopped working after a few months. No idea why.

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

Re: Sonoff reflect state of button to Domoticz

#6 Post by vojtishek » 07 May 2017, 21:43

Hi guys,

thanks for trying to help me find solution, really appreciate it.

@grovkillen
This seems to be solution, unfortunately still not able to force domoticz switch to change status based on Momentary button status.
I´ve found there is another command below which can be used somehow. Anyway when I pasted it in a format below, doesnt work.

Publish domoticz/in,{"idx":8,"command":"switchlight","switchcmd":"On"}

What I definitely know, that I need to study rules logic in esp and domoticz :).

@costo
Thanks but this will not achieve to change status in domoticz based on status of button in sonoff.

@Madbanana
Is this means that only this rule provided you functionality, that button of sonoff will change status of switch in Domoticz?

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

Re: Sonoff reflect state of button to Domoticz

#7 Post by danielchagasrs » 08 May 2017, 01:09

just use Sendtohttp with Toggle option... so, it wont care about the switch real status. It will only change it to oposite state. If it's on, then it will turn it off. If it's off, it will turn it on. Simple and efficient.

I'm using this settup for a time. I can turn on the living room light from a push button on the wall, and turn it off from a my phone, then turn it on from a push buttom on my bedroom, and turn it of from the living room button... I can have 2, 3, 10 push buttons, all changing the status of the same light.
It's quite simple.
====================
on YOUR_BUTTON_SWITCH#Switch do
sendtohttp,XYZ.XYZ.XYZ.XYZ,8080,/json.htm?param=switchlight&type=command&idx=AAA&switchcmd=Toggle
endon
====================

You can copy and paste the above code, just replace:
-> YOUR_BUTTON_SWITCH is your device name (the name you fill when you add a device on espeasy)
-> XYZ is the ip address of your domoticz server. Port is 8080 by default, if you havent changed it...
-> AAA is your swtch IDX, inside domoticz devices.

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

Re: Sonoff reflect state of button to Domoticz

#8 Post by vojtishek » 08 May 2017, 09:37

Thanks, this looks promisely.
Unfortunately following code cause that only values in espeasy changing accordingly. Domoticz not listening to those changes.
Switch in domoticz is with idx8 as on image at the beginning of my post. I'm adding screens of settings of switches in espeasy, maybe there is something wrong. Momentary is push button on sonoff.

Code: Select all

on lamp_on do
gpio,12,1
endon

on lamp_off do
gpio,12,0
endon

on Momentary#Switch do
if [Momentary#Switch]=1
event lamp_on
else
event lamp_off
sendtohttp,192.168.0.106,8080,/json.htm?
param=switchlight&type=command&idx=8&switchcmd=Toggle
endif
endon
Image
Image

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

Re: Sonoff reflect state of button to Domoticz

#9 Post by grovkillen » 08 May 2017, 11:16

Code: Select all

on lamp_on do
gpio,12,1
endon

on lamp_off do
gpio,12,0
endon

on Momentary#Switch do
if [Momentary#Switch]=1
event lamp_on
else
event lamp_off
endif
sendtohttp,192.168.0.106,8080,/json.htm?param=switchlight&type=command&idx=8&switchcmd=Toggle
endon
Have you tried to have the sendtohttp command after the if statement?
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:

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

Re: Sonoff reflect state of button to Domoticz

#10 Post by danielchagasrs » 08 May 2017, 12:22

Remove events lamp on and lamp off...

You are sending 2 commands to that same device...
Remove de if/endif session and leave only the sendtohttp.

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

Re: Sonoff reflect state of button to Domoticz

#11 Post by danielchagasrs » 08 May 2017, 12:28

on cozinha_btn_luz#Switch do
sendtohttp,192.168.25.150,8888,/json.htm?param=switchlight&type=command&idx=76&switchcmd=Toggle
endon

This is my rule, exactly as it is in espeasy, and it works perfectly. (Cozinha=kitchen and Luz=light)

You dont need if/else/endif or any other statements. Just send the toggle command and enjoy.

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

Re: Sonoff reflect state of button to Domoticz

#12 Post by danielchagasrs » 08 May 2017, 12:37

I can't send a picture now, but the settings for the device "momentary" should be:

Send boot state = no
Send data = no
Idx = any number (You won't create a virtual switch associated to the push buttom. You just create a switch for the light/relay. Since it wont send data to any domoticz virtual switch, you can set any idx number here, just uncheck the "Send data" )
Pull up = yes
Type = push button active low

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Sonoff reflect state of button to Domoticz

#13 Post by costo » 08 May 2017, 15:33

@ vojtishek

For me this works in Domoticz:


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

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

on Momentary#Switch do
if [Momentary#Switch]=1
event lamp_on
else
event lamp_off
endif
endon

Madbanana
Normal user
Posts: 13
Joined: 16 Oct 2016, 20:48

Re: Sonoff reflect state of button to Domoticz

#14 Post by Madbanana » 08 May 2017, 23:02

@vojtishek

My apologies, a typo in my rules - this is what I have:-

on SW_1#Switch do
if [relay#Switch]=1
gpio,12,0
else
gpio,12,1
endif
endon

This is all I have in rules - the pushbutton and Domoticz operates the relay correctly. Domoticz updates the state of the relay if it is changed by the pushbutton (takes a few seconds to update the web page).

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

Re: Sonoff reflect state of button to Domoticz

#15 Post by vojtishek » 09 May 2017, 20:54

danielchagasrs wrote: 08 May 2017, 12:28 on cozinha_btn_luz#Switch do
sendtohttp,192.168.25.150,8888,/json.htm?param=switchlight&type=command&idx=76&switchcmd=Toggle
endon

This is my rule, exactly as it is in espeasy, and it works perfectly. (Cozinha=kitchen and Luz=light)

You dont need if/else/endif or any other statements. Just send the toggle command and enjoy.
Thanks, I´ve tried following but without success.
If understand correctly then send to http should switch relay domoticz switch on/off according to momentary button.

Settings for button used in espeasy.
Rule modified

on lamp_on do
gpio,12,1
gpio 13,0
endon

on lamp_off do
gpio,12,0
gpio 13,1
endon

on Momentary#Switch do
sendtohttp,192.168.0.106,8080,/json.htm?
param=switchlight&type=command&idx=8&switchcmd=Toggle
endon

Just wondering if any other settings in domoticz needs to be modified.

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

Re: Sonoff reflect state of button to Domoticz

#16 Post by vojtishek » 09 May 2017, 20:59

costo wrote: 08 May 2017, 15:33 @ vojtishek

For me this works in Domoticz:


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

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

on Momentary#Switch do
if [Momentary#Switch]=1
event lamp_on
else
event lamp_off
endif
endon
Thanks, but not working for me, changing in espeasy change status of relay according to momentary but not in domoticz.
Kinda desperate right now :)

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

Re: Sonoff reflect state of button to Domoticz

#17 Post by vojtishek » 09 May 2017, 21:01

grovkillen wrote: 08 May 2017, 11:16

Code: Select all

on lamp_on do
gpio,12,1
endon

on lamp_off do
gpio,12,0
endon

on Momentary#Switch do
if [Momentary#Switch]=1
event lamp_on
else
event lamp_off
endif
sendtohttp,192.168.0.106,8080,/json.htm?param=switchlight&type=command&idx=8&switchcmd=Toggle
endon
Have you tried to have the sendtohttp command after the if statement?
Thanks, tried but without any effect

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

Re: Sonoff reflect state of button to Domoticz

#18 Post by danielchagasrs » 10 May 2017, 02:20

vojtishek wrote: 09 May 2017, 20:54

Thanks, I´ve tried following but without success.
If understand correctly then send to http should switch relay domoticz switch on/off according to momentary button.

on Momentary#Switch do
sendtohttp,192.168.0.106,8080,/json.htm?
param=switchlight&type=command&idx=8&switchcmd=Toggle
endon

Just wondering if any other settings in domoticz needs to be modified.

What are the settings for "Momentary" device inside espeasy?
I should not send data to domoticz, and IDX must be higher than 0 (any number will be fine). Enable the pull up option, and use "Input switch" as device type, and Active Low as the subtype.


If you need some help over Teamviewer, let me know (timezone here = GMT -3)

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

Re: Sonoff reflect state of button to Domoticz

#19 Post by vojtishek » 10 May 2017, 10:53

danielchagasrs wrote: 10 May 2017, 02:20
vojtishek wrote: 09 May 2017, 20:54

Thanks, I´ve tried following but without success.
If understand correctly then send to http should switch relay domoticz switch on/off according to momentary button.

on Momentary#Switch do
sendtohttp,192.168.0.106,8080,/json.htm?
param=switchlight&type=command&idx=8&switchcmd=Toggle
endon

Just wondering if any other settings in domoticz needs to be modified.

What are the settings for "Momentary" device inside espeasy?
I should not send data to domoticz, and IDX must be higher than 0 (any number will be fine). Enable the pull up option, and use "Input switch" as device type, and Active Low as the subtype.


If you need some help over Teamviewer, let me know (timezone here = GMT -3)
I've used the settings you recommend for "Momentary".
Situation is that relay changing 0/1 based on "Momentary" in espeasy, but not reflecting status in domoticz.

Really appreciate your help and If possible to make sharing screen session, then I will let you know when available.
Thanks a lot

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

Re: Sonoff reflect state of button to Domoticz

#20 Post by danielchagasrs » 10 May 2017, 17:39

I've used the settings you recommend for "Momentary".
Situation is that relay changing 0/1 based on "Momentary" in espeasy, but not reflecting status in domoticz.

Really appreciate your help and If possible to make sharing screen session, then I will let you know when available.
Thanks a lot
Hi. If you need help to setup your espeasy rule, send me message to combine a remote session over teamviewer or skype.
Whatsapp: +55 51 95294712
Skype: daniel-chagas
Usually, I'm home around 7pm (GMT -3, Brazilian time).

Daniel.

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

Re: Sonoff reflect state of button to Domoticz

#21 Post by vojtishek » 13 May 2017, 10:38

danielchagasrs wrote: 10 May 2017, 17:39
I've used the settings you recommend for "Momentary".
Situation is that relay changing 0/1 based on "Momentary" in espeasy, but not reflecting status in domoticz.

Really appreciate your help and If possible to make sharing screen session, then I will let you know when available.
Thanks a lot
Hi. If you need help to setup your espeasy rule, send me message to combine a remote session over teamviewer or skype.
Whatsapp: +55 51 95294712
Skype: daniel-chagas
Usually, I'm home around 7pm (GMT -3, Brazilian time).

Daniel.
That would be great Daniel.
I will let you know next week when available.
Thanks

wifiminime
New user
Posts: 1
Joined: 03 Jun 2017, 00:50

Re: Sonoff reflect state of button to Domoticz

#22 Post by wifiminime » 03 Jun 2017, 01:09

Hi,

I think the way it supposed to work is as follows:

The device you have added in ESPEasy firmware (devices) is a switch that can be controlled.
In Domoticz you create a virtual switch and enter the http cmd's to control the switch in your SONOFF device:

'On' action:
http://192.168.1.21/control?cmd=GPIO,12,1

similar for the 'off' action.
The virtual switch in domoticz has an IDX, find the number...(setup, devices)
now in your ESPEasy, tab:devices, edit switch, assign the same number for IDX as in Domoticz
enable "send-Data"'

pressing the button on your SONOFF will change the switch, the ESPEasy firmware will upon change immediatly try to update the IDX in domoticz, without any additional rules in your esp easy device

Make sure you have configured you esp "config"-tab correct configured to comunicate via domoticz (protocol, server ip, port, username, password)

Greetz

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

Re: Sonoff reflect state of button to Domoticz

#23 Post by vojtishek » 03 Jun 2017, 10:32

wifiminime wrote: 03 Jun 2017, 01:09 Hi,

I think the way it supposed to work is as follows:

The device you have added in ESPEasy firmware (devices) is a switch that can be controlled.
In Domoticz you create a virtual switch and enter the http cmd's to control the switch in your SONOFF device:

'On' action:
http://192.168.1.21/control?cmd=GPIO,12,1

similar for the 'off' action.
The virtual switch in domoticz has an IDX, find the number...(setup, devices)
now in your ESPEasy, tab:devices, edit switch, assign the same number for IDX as in Domoticz
enable "send-Data"'

pressing the button on your SONOFF will change the switch, the ESPEasy firmware will upon change immediatly try to update the IDX in domoticz, without any additional rules in your esp easy device

Make sure you have configured you esp "config"-tab correct configured to comunicate via domoticz (protocol, server ip, port, username, password)

Greetz
Hi,

yes, but that´s only valid for GPIO 12 which is relay inside sonoff. Momentary push button is on GPIO 0.
Virtual switch is created for relay only.

The goal is to reflect state of momentary push button to domoticz virtual switch for relay.

Unfortunately this doesn´t work. Values in espeasy changing accordingly as per rule below but not reflecting to domoticz.

Code: Select all

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

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

on Momentary#Switch do
if [Momentary#Switch]=1
event lamp_on
else
event lamp_off
endif
endon
Kinda desperate with that, but I like to play so sometime in future I will discover how to do that
:)

LisaM
Normal user
Posts: 513
Joined: 11 Apr 2017, 18:29

Re: Sonoff reflect state of button to Domoticz

#24 Post by LisaM » 04 Jun 2017, 00:50

vojtishek wrote: 03 Jun 2017, 10:32
wifiminime wrote: 03 Jun 2017, 01:09 Hi,

I think the way it supposed to work is as follows:

The device you have added in ESPEasy firmware (devices) is a switch that can be controlled.
In Domoticz you create a virtual switch and enter the http cmd's to control the switch in your SONOFF device:

'On' action:
http://192.168.1.21/control?cmd=GPIO,12,1

similar for the 'off' action.
The virtual switch in domoticz has an IDX, find the number...(setup, devices)
now in your ESPEasy, tab:devices, edit switch, assign the same number for IDX as in Domoticz
enable "send-Data"'

pressing the button on your SONOFF will change the switch, the ESPEasy firmware will upon change immediatly try to update the IDX in domoticz, without any additional rules in your esp easy device

Make sure you have configured you esp "config"-tab correct configured to comunicate via domoticz (protocol, server ip, port, username, password)

Greetz
Hi,

yes, but that´s only valid for GPIO 12 which is relay inside sonoff. Momentary push button is on GPIO 0.
Virtual switch is created for relay only.

The goal is to reflect state of momentary push button to domoticz virtual switch for relay.

Unfortunately this doesn´t work. Values in espeasy changing accordingly as per rule below but not reflecting to domoticz.

Code: Select all

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

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

on Momentary#Switch do
if [Momentary#Switch]=1
event lamp_on
else
event lamp_off
endif
endon
Kinda desperate with that, but I like to play so sometime in future I will discover how to do that
:)
Where's the (sys)logfile?

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

Re: Sonoff reflect state of button to Domoticz

#25 Post by vojtishek » 06 Jun 2017, 20:53

Finally it works using following formula

on Momentary#Switch do
if [relay#Switch]=1
gpio,12,0
else
gpio,12,1
endif
endon

I´ve bought new sonoff and test it nearby wifi, succesfully reflecting the status in domoticz.

Just one thing, there is delay around 7 seconds when status change in domoticz.
Do you have same experience?

Thanks a lot to everyone with all the help

adrianmihalko
Normal user
Posts: 51
Joined: 15 Sep 2016, 00:20

Re: Sonoff reflect state of button to Domoticz

#26 Post by adrianmihalko » 13 Dec 2017, 00:25

A very frustrating bug in my Sonoff switch:

after turning off (by button, or from esp easy) there is still a 25V AC voltage left in the connector (measured with DMM). Why?

I connected it to my christmas LED lights, but they are lighting even after turning off, because 25V AC is enough for them to be lit.

adrianmihalko
Normal user
Posts: 51
Joined: 15 Sep 2016, 00:20

Re: Sonoff reflect state of button to Domoticz

#27 Post by adrianmihalko » 13 Dec 2017, 08:34

me:
after turning off my Sonoff S20 (by button, or from app) there is still a 25V AC voltage left in the connector. Why?
I connected it to my christmas LED lights, but they are lighting even after turning off, because 25V AC is enough for them to be lit.

itead:
It's impossible, after turning off, there's no power to pass through
I have consulted our technical support, we suggest you to change to a light with larger power
We guess after turning off, it can still offer 25V AC

me:
It's impossible, after turning off, there's no power to pass through vs after turning off, it can still offer 25V AC
???
I think it's pretty dangerous, if it's turned off it should be turned off completely
not half-turned off
what if somebody touches the live wire of the connected device when it is turned off?

itead:
The technical support tell me that he guess it can offer
All appliances have standby current
Even a small bulb
It's very small current, no hurt to human beings


Meh. :evil:

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Sonoff reflect state of button to Domoticz

#28 Post by TD-er » 13 Dec 2017, 08:59

I think the advice of itead isn't that bad.
Could you try with a heavier load (about 50 - 100 Watt or something like that) if it still is not functioning like it should?
It may be that the relais in the Sonoff is not retracted far enough.
Also try to listen to the Sonoff if the low power Christmas lights are plugged in and the Sonoff is switched off. If you may hear a crackling sound, like electric sparks, you also know the relais is defective.

adrianmihalko
Normal user
Posts: 51
Joined: 15 Sep 2016, 00:20

Re: Sonoff reflect state of button to Domoticz

#29 Post by adrianmihalko » 13 Dec 2017, 09:10

It is silent as hell. 8-)

Of course heavier load it's not working (a tried with a normal bulb and a hair dryer).

But it is still frustrating. :roll:

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests