Page 1 of 1

SONOFF BASICR3

Posted: Wednesday 10 April 2019 18:21
by msantic
https://www.itead.cc/sonoff-basicr3-wif ... witch.html
This is a WiFi Smart Switch with the DIY capability that makes it possible to control connected devices via the eWeLink directly from your phone, or ask it to turn on/off devices with Amazon Alexa and Google Assistant. Amazingly, it has a DIY mode that is the firmware can be user-defined. Built-in a web server that exposes the REST API, which allows you to connect the switch with your existing home automation system. Compatible with Vera, Fibaro, HomeSeer, Savant, HomeKit, etc.
pic.jpg
pic.jpg (44.57 KiB) Viewed 5627 times

Re: SONOFF BASICR3

Posted: Wednesday 03 July 2019 0:05
by chatainsim
It would be nice to have it in Domoticz.

Re: SONOFF BASICR3

Posted: Thursday 08 August 2019 21:06
by lwolf
I am not sure if it can be implemented the multicast-DNS based zeroconf Sonoff DIY mode handler routine inside a Domoticz Python plugin. But i have created an external DIY->MQTT translator application for testing.

https://github.com/enesbcs/sonoffdiy2mqtt

In the "sonoffdiy2mqtt.json" file the default mode is "mqtt_type": "domoticz" when the
Sonoff Device ID (ten character hexadecimal) has to be added to the "sonoff_device_id" fields and its correspondent, Domoticz Dummy device IDX has to be added in the same line to the "outlet0".
Necessarry Domoticz Hardwares: "MQTT Client Gateway with Lan interface" and "Dummy"

If inside the "sonoffdiy2mqtt.json" settings the "mqtt_type": "shelly" is setted then the sonoffdiy2mqtt script translates incoming mDNS messages to Shelly API compatible MQTT messages and paths, which can be intercepted by the Domoticz hardware "Shelly MQTT". ( https://github.com/enesbcs/Shelly_MQTT ) In this mode IDX is not required, but make sure to enable device self-learning.

Re: SONOFF BASICR3

Posted: Thursday 08 August 2019 22:34
by chatainsim
Nice, I'll give it a try next week.
How do you get the sonoff_device_id ?

Re: SONOFF BASICR3

Posted: Friday 09 August 2019 7:35
by lwolf
chatainsim wrote: Thursday 08 August 2019 22:34 Nice, I'll give it a try next week.
How do you get the sonoff_device_id ?
You have to run it once, does not matter if it is configured or not, but if it finds a DIY plug through local mDNS than it writes it's Device ID's which you can copy-paste into the .json settings file.

Re: SONOFF BASICR3

Posted: Monday 12 August 2019 9:42
by chatainsim
lwolf wrote: Friday 09 August 2019 7:35
chatainsim wrote: Thursday 08 August 2019 22:34 Nice, I'll give it a try next week.
How do you get the sonoff_device_id ?
You have to run it once, does not matter if it is configured or not, but if it finds a DIY plug through local mDNS than it writes it's Device ID's which you can copy-paste into the .json settings file.
Thanks, it's working fine.
The only thing is I'm not able to create a systemd script.
It start then stop immediately.
Do you know how to setup a correct systemd init file ?

Re: SONOFF BASICR3

Posted: Monday 12 August 2019 17:31
by lwolf
chatainsim wrote: Monday 12 August 2019 9:42
lwolf wrote: Friday 09 August 2019 7:35
chatainsim wrote: Thursday 08 August 2019 22:34 Nice, I'll give it a try next week.
How do you get the sonoff_device_id ?
You have to run it once, does not matter if it is configured or not, but if it finds a DIY plug through local mDNS than it writes it's Device ID's which you can copy-paste into the .json settings file.
Thanks, it's working fine.
The only thing is I'm not able to create a systemd script.
It start then stop immediately.
Do you know how to setup a correct systemd init file ?
Maybe the init file you have done tried to start before network/mqtt, which will not work.
Did you try the simple /etc/rc.local startup?
https://www.claudiokuenzler.com/blog/78 ... d-rc-local

Re: SONOFF BASICR3

Posted: Tuesday 13 August 2019 21:49
by chatainsim
I have some issue with the script.
Sometimes when I turn off the SonOff, it turn on again immediatly.
Same when I turn it on.

For MQTT I've setuped the Publish Topic to out, is it correct ?

Re: SONOFF BASICR3

Posted: Tuesday 13 August 2019 21:52
by chatainsim
lwolf wrote: Monday 12 August 2019 17:31
chatainsim wrote: Monday 12 August 2019 9:42
lwolf wrote: Friday 09 August 2019 7:35
You have to run it once, does not matter if it is configured or not, but if it finds a DIY plug through local mDNS than it writes it's Device ID's which you can copy-paste into the .json settings file.
Thanks, it's working fine.
The only thing is I'm not able to create a systemd script.
It start then stop immediately.
Do you know how to setup a correct systemd init file ?
Maybe the init file you have done tried to start before network/mqtt, which will not work.
Did you try the simple /etc/rc.local startup?
https://www.claudiokuenzler.com/blog/78 ... d-rc-local
The systemd script is started by hand network and mqtt is already started.

Code: Select all

pi@raspberrypi:~ $ sudo systemctl status sonoffdiy                                                                                                                
● sonoffdiy.service - System Sensor service
   Loaded: loaded (/etc/systemd/system/sonoffdiy.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2019-08-12 09:36:51 CEST; 1 day 12h ago
 Main PID: 30402 (code=exited, status=1/FAILURE)

août 12 09:36:48 raspberrypi systemd[1]: Started System Sensor service.
août 12 09:36:51 raspberrypi python3[30402]: sonoffdiy2mqtt.json can not be read!  [Errno 2] No such file or directory: 'sonoffdiy2mqtt.json'
août 12 09:36:51 raspberrypi python3[30402]: Traceback (most recent call last):
août 12 09:36:51 raspberrypi python3[30402]:   File "/home/pi/SRC/sonoffdiy2mqtt/sonoffdiy2mqtt.py", line 62, in <module>
août 12 09:36:51 raspberrypi python3[30402]:     if ssettings["mqtt_type"]=="domoticz":
août 12 09:36:51 raspberrypi python3[30402]: TypeError: list indices must be integers or slices, not str
août 12 09:36:51 raspberrypi systemd[1]: sonoffdiy.service: Main process exited, code=exited, status=1/FAILURE
août 12 09:36:51 raspberrypi systemd[1]: sonoffdiy.service: Unit entered failed state.
août 12 09:36:51 raspberrypi systemd[1]: sonoffdiy.service: Failed with result 'exit-code'.
Failed to find the sonoffdiy2mqtt.json
How to specified the path of sonoffdiy2mqtt.json in the python script ?

Re: SONOFF BASICR3

Posted: Tuesday 13 August 2019 22:13
by lwolf
chatainsim wrote: Tuesday 13 August 2019 21:49 I have some issue with the script.
Sometimes when I turn off the SonOff, it turn on again immediatly.
Same when I turn it on.

For MQTT I've setuped the Publish Topic to out, is it correct ?
Interesting i did not experienced it. How fast did you click its icon in Domoticz?
Publish is "domoticz/in" and Subscribe is "domoticz/out" but if you set the type to "domoticz" and leave Pub&Sub empty it will auto-fill them on startup, if you define topics in the opposite way, it may cause some troubles.

Re: SONOFF BASICR3

Posted: Tuesday 13 August 2019 22:25
by lwolf
chatainsim wrote: Tuesday 13 August 2019 21:52 août 12 09:36:48 raspberrypi systemd[1]: Started System Sensor service.
août 12 09:36:51 raspberrypi python3[30402]: sonoffdiy2mqtt.json can not be read! [Errno 2] No such file or directory: 'sonoffdiy2mqtt.json'
août 12 09:36:51 raspberrypi python3[30402]: Traceback (most recent call last):
août 12 09:36:51 raspberrypi python3[30402]: File "/home/pi/SRC/sonoffdiy2mqtt/sonoffdiy2mqtt.py", line 62, in <module>
août 12 09:36:51 raspberrypi python3[30402]: if ssettings["mqtt_type"]=="domoticz":
août 12 09:36:51 raspberrypi python3[30402]: TypeError: list indices must be integers or slices, not str
août 12 09:36:51 raspberrypi systemd[1]: sonoffdiy.service: Main process exited, code=exited, status=1/FAILURE
août 12 09:36:51 raspberrypi systemd[1]: sonoffdiy.service: Unit entered failed state.
août 12 09:36:51 raspberrypi systemd[1]: sonoffdiy.service: Failed with result 'exit-code'.[/code]

Failed to find the sonoffdiy2mqtt.json
How to specified the path of sonoffdiy2mqtt.json in the python script ?
The sonoffdiy2mqtt.json has to be located in the same directory as the sonoffdiy2mqtt.py. I guess that when the service starts the working directory is somewhere elsewhere, which i think i fixed in today commit.
https://github.com/enesbcs/sonoffdiy2mq ... 0c3bc7ea10

Re: SONOFF BASICR3

Posted: Wednesday 14 August 2019 12:48
by chatainsim
lwolf wrote: Tuesday 13 August 2019 22:13
chatainsim wrote: Tuesday 13 August 2019 21:49 I have some issue with the script.
Sometimes when I turn off the SonOff, it turn on again immediatly.
Same when I turn it on.

For MQTT I've setuped the Publish Topic to out, is it correct ?
Interesting i did not experienced it. How fast did you click its icon in Domoticz?
Publish is "domoticz/in" and Subscribe is "domoticz/out" but if you set the type to "domoticz" and leave Pub&Sub empty it will auto-fill them on startup, if you define topics in the opposite way, it may cause some troubles.
I've only clicked once. And set everything by default.
It's only the Domoticz conf for mqtt I'm not sure which kind of Pub topic I should set. Out, / or both ?

Thanks

Re: SONOFF BASICR3

Posted: Wednesday 14 August 2019 17:28
by lwolf
chatainsim wrote: Wednesday 14 August 2019 12:48 I've only clicked once. And set everything by default.
It's only the Domoticz conf for mqtt I'm not sure which kind of Pub topic I should set. Out, / or both ?
The Publish topic in Domoticz for the "MQTT Client Gateway" hardware is simple "out" this way the Domoticz publishing messages to domoticz/out topic which is the subscribe topic in the point of view of the sonoff, where it is receiving commands. Leaving "mqtt_topic_pub":"" and "mqtt_topic_sub":"" as empty is a good start point.
(Or you can try the shelly working-mode in which mode the topics are fixed so also can be left empty, altough an extra python plugin is needed, but there are no need of IDX creation as device detection is automatic.)

Re: SONOFF BASICR3

Posted: Wednesday 14 August 2019 18:53
by chatainsim
lwolf wrote: Tuesday 13 August 2019 22:25
chatainsim wrote: Tuesday 13 August 2019 21:52 août 12 09:36:48 raspberrypi systemd[1]: Started System Sensor service.
août 12 09:36:51 raspberrypi python3[30402]: sonoffdiy2mqtt.json can not be read! [Errno 2] No such file or directory: 'sonoffdiy2mqtt.json'
août 12 09:36:51 raspberrypi python3[30402]: Traceback (most recent call last):
août 12 09:36:51 raspberrypi python3[30402]: File "/home/pi/SRC/sonoffdiy2mqtt/sonoffdiy2mqtt.py", line 62, in <module>
août 12 09:36:51 raspberrypi python3[30402]: if ssettings["mqtt_type"]=="domoticz":
août 12 09:36:51 raspberrypi python3[30402]: TypeError: list indices must be integers or slices, not str
août 12 09:36:51 raspberrypi systemd[1]: sonoffdiy.service: Main process exited, code=exited, status=1/FAILURE
août 12 09:36:51 raspberrypi systemd[1]: sonoffdiy.service: Unit entered failed state.
août 12 09:36:51 raspberrypi systemd[1]: sonoffdiy.service: Failed with result 'exit-code'.[/code]

Failed to find the sonoffdiy2mqtt.json
How to specified the path of sonoffdiy2mqtt.json in the python script ?
The sonoffdiy2mqtt.json has to be located in the same directory as the sonoffdiy2mqtt.py. I guess that when the service starts the working directory is somewhere elsewhere, which i think i fixed in today commit.
https://github.com/enesbcs/sonoffdiy2mq ... 0c3bc7ea10
I confirm, it's fixed.
Now it's working fine with systemd!

Thanks

Re: SONOFF BASICR3

Posted: Wednesday 14 August 2019 18:56
by chatainsim
lwolf wrote: Wednesday 14 August 2019 17:28
chatainsim wrote: Wednesday 14 August 2019 12:48 I've only clicked once. And set everything by default.
It's only the Domoticz conf for mqtt I'm not sure which kind of Pub topic I should set. Out, / or both ?
The Publish topic in Domoticz for the "MQTT Client Gateway" hardware is simple "out" this way the Domoticz publishing messages to domoticz/out topic which is the subscribe topic in the point of view of the sonoff, where it is receiving commands. Leaving "mqtt_topic_pub":"" and "mqtt_topic_sub":"" as empty is a good start point.
(Or you can try the shelly working-mode in which mode the topics are fixed so also can be left empty, altough an extra python plugin is needed, but there are no need of IDX creation as device detection is automatic.)
I've setuped the Mqtt conf in Domoticz to Out.
And defined the ID of the Sonoff and IDX from Domoticz in json file.
But it's still sometimes turning it on again after a off and vice versa.
How can I degub the python script ?

Thanks

Re: SONOFF BASICR3

Posted: Wednesday 14 August 2019 20:50
by lwolf
chatainsim wrote: Wednesday 14 August 2019 18:56 I've setuped the Mqtt conf in Domoticz to Out.
And defined the ID of the Sonoff and IDX from Domoticz in json file.
But it's still sometimes turning it on again after a off and vice versa.
How can I degub the python script ?
I've found a possible mqtt bounce error, however my test device did not turn on/off, but maybe it will help you.
Please download fresh code from github and retry.
From now if you are adding "debug":1, line to sonoffdiy2mqtt.json than state changing will be reported to the console.

Re: SONOFF BASICR3

Posted: Thursday 15 August 2019 11:25
by chatainsim
lwolf wrote: Wednesday 14 August 2019 20:50
chatainsim wrote: Wednesday 14 August 2019 18:56 I've setuped the Mqtt conf in Domoticz to Out.
And defined the ID of the Sonoff and IDX from Domoticz in json file.
But it's still sometimes turning it on again after a off and vice versa.
How can I degub the python script ?
I've found a possible mqtt bounce error, however my test device did not turn on/off, but maybe it will help you.
Please download fresh code from github and retry.
From now if you are adding "debug":1, line to sonoffdiy2mqtt.json than state changing will be reported to the console.
Nice, it's working fine now.
Thank you for the good job!

Re: SONOFF BASICR3

Posted: Thursday 15 August 2019 17:44
by lwolf
chatainsim wrote: Thursday 15 August 2019 11:25 Nice, it's working fine now.
Thank you for the good job!
No problem, thank you for your feedback.