Sonoff DIY non complicated

Moderator: leecollings

Post Reply
frankdep
Posts: 12
Joined: Saturday 14 September 2019 10:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Sonoff DIY non complicated

Post by frankdep »

Hi, Just wanted to share my experience in activating a Sonoff BasicR3 in domoticz. Looking on the internet I found many complex solutions (Tasmota, MQTT, eWelink ...) all working but complicated. Since 2019 sonoff offers the DIY where you can simply post http requests to control the device.
references : http://developers.sonoff.tech/sonoff-di ... tocol.html and https://sonoff.tech/product-review/prod ... evice-yes/
In fact it comes to 5 actions :
1. put the DIY bridge in the Sonoff device and restart pairing
2. connect to 'http://10.10.7.1/' (password 12345678) and enter your WIFI network and password.
3. restart (link is blinking twice) and find the ipaddress of the Sonoff ESP device (eg. 192.168.178.193)
4. create a dummy switch in domoticz (eg. Plug1)
5. create a script to post request (dzvents example below)

Hope this helps.


dzvents script (devices part is normally sufficient, extended with error check) :
return {
on = {
devices = {'Plug1'},
httpResponses = {'Resp_on', 'Resp_off'}, -- must match with the callback passed to the openURL command
customEvents ={'Check_on','Check_off'},
},
execute = function(domoticz, item)
if (item.isDevice) then
if item.state == "On" then comm = "on" else comm = "off" end
domoticz.openURL({
url = 'http://192.168.178.193:8081/zeroconf/switch',
method = 'POST',
callback = 'None',
postData = {['deviceid']='', ['data']={['switch']= comm }}
})
domoticz.emitEvent('Check_'..comm, domoticz.time.rawTime ).afterSec(1) --check if OK after one second
print("Plug1 command send = "..comm)
end
if (item.isCustomEvent) then
if item.trigger == "Check_on" then comm = "on" else comm = "off" end
domoticz.openURL({
url = 'http://192.168.178.193:8081/zeroconf/info',
method = 'POST',
callback = 'Resp_'..comm,
postData = {['deviceid']='', ['data']={}}
})
print("Plug1 status requested info for status = "..comm)
end
if (item.isHTTPResponse) and (item.isJSON) then -- check after 1 second if error or status switch is different than requested
print("HTTPResponse is "..item.trigger.." , error is "..item.json.error.." status is "..item.json.data['switch'])
if item.trigger == "Resp_on" then comm = "on" else comm = "off" end
if (not item.ok or (item.json.error ~= 0) or item.json.data['switch']~= comm) then
domoticz.openURL({
url = 'http://192.168.178.193:8081/zeroconf/switch',
method = 'POST',
callback = 'None', -- only one retry
postData = {['deviceid']='', ['data']={['switch']= comm }}
})
print("ERROR on Plug1, Retry once : Plug1 command send = "..comm)
end
end
end
}
Roots
Posts: 1
Joined: Monday 24 January 2022 17:59
Target OS: -
Domoticz version:
Contact:

Re: Sonoff DIY non complicated

Post by Roots »

Thank you this works like a charm!
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Sonoff DIY non complicated

Post by jake »

To say that this is less complicated....

As soon as you have mqtt up and running, you can use it for other automations as well, like ZigBee and zwavel
jvm1000
Posts: 4
Joined: Thursday 21 June 2018 14:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sonoff DIY non complicated

Post by jvm1000 »

Thank you this works perfectly with a BASICR3 :D :D :D
panosk
Posts: 2
Joined: Wednesday 04 May 2022 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sonoff DIY non complicated

Post by panosk »

Hi to all !
Ok I know that this is an old thread but I just bought my (new?) MINIR3 and I realized that it only responds to this :

{
"deviceid": "1001717xxx",
"data": {
"switches": [
{ "switch": "off", "outlet": 0 }
]
}
}

My knowledge is not enough to modify the script
Could somebody help?
Attachments
ScreenShot36-2.jpg
ScreenShot36-2.jpg (30.99 KiB) Viewed 2209 times
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests