433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
Moderator: leecollings
-
- Posts: 2
- Joined: Tuesday 07 August 2018 19:23
- Target OS: Linux
- Domoticz version:
- Contact:
433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
Hi all, I am planning to install some Sonoff Wifi switches and smart plugs in a room of my apartment. My initial idea was to control them using these 433Mhz wireless touch remotes which look like ordinary wall switches -
https://www.aliexpress.com/item/Vhome-W ... 4c4dcWQeNJ
Ideally these switches will send signals to a Sonoff RF bridge which will then communicate them to Domoticz via MQTT over wifi. In that way I can easily assign each wireless touch remote to a one or a group of devices in Domoticz.
I flashed the Sonoff RF bridge with the latest Tasmota firmware 6.1.1. The wireless remote switches were also all successfully learnt by the Sonoff RF bridge. When buttons on the remote were pressed. I could see MQTT messages in the console associated with those button. The problems I am facing now are:
1. The MQTT messages from the RF bridge were not seen in Domoticz. I gathered that this is due to the Sonoff RF bridge MQTT message format not being recognized by Domoticz? A Tasmota firmware modification is needed?
2. Assuming the previous problem was solved. How do I setup Domoticz such that a button press on the wireless remote toggles the state of a device, group, and scene?
I seem to get the feeling that the feature I mentioned is simply not possible with the current Tasmota firmware. Most questions on the forum talked about linking sensors via the RF bridge to Domotizc (kind or a similar to what I want to do here) or Domoticz controlling 433Mhz devices via the RF bridge.
Thank you.
Unfortunately I cannot provide any screenshots of the MQTT messages from the RF bridge. After a failed OTA update, my Sonoff RF bridge is completely dead. Even a direct flashing via a USB to serial connection didn't work. I have ordered a few more, should be here in a week or two...
https://www.aliexpress.com/item/Vhome-W ... 4c4dcWQeNJ
Ideally these switches will send signals to a Sonoff RF bridge which will then communicate them to Domoticz via MQTT over wifi. In that way I can easily assign each wireless touch remote to a one or a group of devices in Domoticz.
I flashed the Sonoff RF bridge with the latest Tasmota firmware 6.1.1. The wireless remote switches were also all successfully learnt by the Sonoff RF bridge. When buttons on the remote were pressed. I could see MQTT messages in the console associated with those button. The problems I am facing now are:
1. The MQTT messages from the RF bridge were not seen in Domoticz. I gathered that this is due to the Sonoff RF bridge MQTT message format not being recognized by Domoticz? A Tasmota firmware modification is needed?
2. Assuming the previous problem was solved. How do I setup Domoticz such that a button press on the wireless remote toggles the state of a device, group, and scene?
I seem to get the feeling that the feature I mentioned is simply not possible with the current Tasmota firmware. Most questions on the forum talked about linking sensors via the RF bridge to Domotizc (kind or a similar to what I want to do here) or Domoticz controlling 433Mhz devices via the RF bridge.
Thank you.
Unfortunately I cannot provide any screenshots of the MQTT messages from the RF bridge. After a failed OTA update, my Sonoff RF bridge is completely dead. Even a direct flashing via a USB to serial connection didn't work. I have ordered a few more, should be here in a week or two...
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
When I saw this, I immediately thought: 'Node-RED'.
As I've got a number of Sonoff (basic switch) modules, which I've flashed with Tasmota and which I've got linked to Domoticz (controlling lights), I decided to experiment with this. I bought a Sonoff RF Bridge on eBay, flashed it and started to play around. As you will have seen in the console, the RF Bridge produces a message of this format when a key of a paired remote is pressed:(sonoffB is the topic for my bridge.)
I realised that it would then be possible to build a Node-RED flow to control a number of Domoticz devices based on the value of RfKey, using the domoticz/in MQTT topic. (If you're not familiar with Node-RED - and I'm a bit of a novice - there's enough in the Domoticz wiki and Node-RED website to get you started.)
So far, I've just learned the buttons on a 2-button HomeEasy 433MHz remote, and created a Node-RED flow to control 2 light switches in Domoticz. This is what I've come up with:

This is the corresponding code, which can be imported into Node-RED:
The big advantage of this is that, using the Sonoff RF Bridge, you can control Domoticz devices* - e.g., light switches - using an RF remote.
(* these can be non-Sonoff devices as well as Sonoff).
As I've got a number of Sonoff (basic switch) modules, which I've flashed with Tasmota and which I've got linked to Domoticz (controlling lights), I decided to experiment with this. I bought a Sonoff RF Bridge on eBay, flashed it and started to play around. As you will have seen in the console, the RF Bridge produces a message of this format when a key of a paired remote is pressed:
Code: Select all
tele/sonoffB/RESULT = {"RfReceived":{"Sync":10280,"Low":380,"High":940,"Data":"514115","RfKey":1}}
I realised that it would then be possible to build a Node-RED flow to control a number of Domoticz devices based on the value of RfKey, using the domoticz/in MQTT topic. (If you're not familiar with Node-RED - and I'm a bit of a novice - there's enough in the Domoticz wiki and Node-RED website to get you started.)
So far, I've just learned the buttons on a 2-button HomeEasy 433MHz remote, and created a Node-RED flow to control 2 light switches in Domoticz. This is what I've come up with:

This is the corresponding code, which can be imported into Node-RED:
- Spoiler: show
The big advantage of this is that, using the Sonoff RF Bridge, you can control Domoticz devices* - e.g., light switches - using an RF remote.
(* these can be non-Sonoff devices as well as Sonoff).
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
... or you can do it in Python. I've produced an example Python script - see below.
Instead of publishing to the domoticz/in MQTT topic, the script gets the rfkey number (by subscribing to the tele/<sonoff>/RESULT topic), and uses the more 'conventional' JSON API to send commands to Domoticz.
Again, this script has only been set up for two buttons - it can be extended by adding more idx's (and different Domoticz commands - I've used switchlight and Toggle) in on_message.
Instead of publishing to the domoticz/in MQTT topic, the script gets the rfkey number (by subscribing to the tele/<sonoff>/RESULT topic), and uses the more 'conventional' JSON API to send commands to Domoticz.
Again, this script has only been set up for two buttons - it can be extended by adding more idx's (and different Domoticz commands - I've used switchlight and Toggle) in on_message.
- Spoiler: show
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
@spacestation: did you get anywhere with this?
-
- Posts: 2
- Joined: Tuesday 07 August 2018 19:23
- Target OS: Linux
- Domoticz version:
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
Hi MikeF,
Pardon my late reply. Firstly thanks for the suggestions and Node-Red codes! I just received my new batch of the Sonoff rf bridges two weeks ago and only managed to try out your suggestions over the weekend. I must say it worked a treat!!!
Currently I have the three 433Mhz wireless touch remotes paired to the rf bridge. The Node-Red code looks something like this -
I just needed to change the idx in the PreDomoticzCmdx to the appropriate number. It works exactly the same way for controlling groups and scenes just by entering their idx number and changing the payload.command to 'switchscene" .
I was wondering since each wireless remote broadcasts its unique identifier of some kind, is it possible to modify 'ChooseRFKey' to switch between those identifiers instead? In that case is it correct to say that there is no need for the rf bridge to learn the remotes and thus it will not be limited to only 16 remotes?
Once again thanks for the codes! Now room looks much cleaner with less wires running all over the place, the switches can be placed anywhere and they can be easily reconfigured!
Pardon my late reply. Firstly thanks for the suggestions and Node-Red codes! I just received my new batch of the Sonoff rf bridges two weeks ago and only managed to try out your suggestions over the weekend. I must say it worked a treat!!!
Currently I have the three 433Mhz wireless touch remotes paired to the rf bridge. The Node-Red code looks something like this -
I just needed to change the idx in the PreDomoticzCmdx to the appropriate number. It works exactly the same way for controlling groups and scenes just by entering their idx number and changing the payload.command to 'switchscene" .
I was wondering since each wireless remote broadcasts its unique identifier of some kind, is it possible to modify 'ChooseRFKey' to switch between those identifiers instead? In that case is it correct to say that there is no need for the rf bridge to learn the remotes and thus it will not be limited to only 16 remotes?
Once again thanks for the codes! Now room looks much cleaner with less wires running all over the place, the switches can be placed anywhere and they can be easily reconfigured!
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
Glad this is working for you.
Yes, I believe that each wireless remote broadcasts its unique identifier ("Data" in the MQTT payload?), but I just found it easier to code RFKey values in the PrepDomoticzCmd function. Not sure that there is no need for the RF bridge to learn the remotes though - I'm using it with a non-Sonoff remote to control a combination of Sonoff and non-Sonoff devices via Domoticz, and for this, the RF bridge publishes an MQTT topic (domoticz/in) whenever it recognises (learned) buttons pressed on the remote.
Yes, I believe that each wireless remote broadcasts its unique identifier ("Data" in the MQTT payload?), but I just found it easier to code RFKey values in the PrepDomoticzCmd function. Not sure that there is no need for the RF bridge to learn the remotes though - I'm using it with a non-Sonoff remote to control a combination of Sonoff and non-Sonoff devices via Domoticz, and for this, the RF bridge publishes an MQTT topic (domoticz/in) whenever it recognises (learned) buttons pressed on the remote.
-
- Posts: 26
- Joined: Wednesday 28 November 2018 19:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
Hello i struggle with this a long time.
Had my bridge laying in the corner for some time just because i could not make it work.
I have also a question about mu problem with my bridge in another topic (Just put it there today)
I tried this python script in domoticz but get this error message
2018-11-28 19:53:00.318 Error: EventSystem: Failed to execute python event script "Bridge"
2018-11-28 19:53:00.318 Error: EventSystem: File "<string>", line 24
2018-11-28 19:53:00.318 Error: EventSystem: print "message received " ,str(message.payload.decode("utf-8"))
2018-11-28 19:53:00.318 Error: EventSystem: ^
2018-11-28 19:53:00.318 Error: EventSystem: SyntaxError: invalid syntax
The print commands it gives an error.
Had my bridge laying in the corner for some time just because i could not make it work.
I have also a question about mu problem with my bridge in another topic (Just put it there today)
I tried this python script in domoticz but get this error message
2018-11-28 19:53:00.318 Error: EventSystem: Failed to execute python event script "Bridge"
2018-11-28 19:53:00.318 Error: EventSystem: File "<string>", line 24
2018-11-28 19:53:00.318 Error: EventSystem: print "message received " ,str(message.payload.decode("utf-8"))
2018-11-28 19:53:00.318 Error: EventSystem: ^
2018-11-28 19:53:00.318 Error: EventSystem: SyntaxError: invalid syntax
The print commands it gives an error.
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
Are you using Python 3? (I use Python 2.7)
- if so, you need to put brackets around the arguments of print statements, thus:
- if so, you need to put brackets around the arguments of print statements, thus:
Code: Select all
print ("message received " ,str(message.payload.decode("utf-8")))
-
- Posts: 26
- Joined: Wednesday 28 November 2018 19:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
Sorry for my late reply.
The answer to put brackets helps.
I had to do this to all the print messages.
Only it keeping telling me there is no poha module in the import line.
I installed the mqtt clients and also pip install poha-mqtt
But i stil keep this error.
I am not so familiar with this.
The only thing i try to do is put a light on and off with an 433 rf remote button.
The light works already fine with a sonoff touch with tasmote.
The answer to put brackets helps.
I had to do this to all the print messages.
Only it keeping telling me there is no poha module in the import line.
I installed the mqtt clients and also pip install poha-mqtt
But i stil keep this error.
I am not so familiar with this.
The only thing i try to do is put a light on and off with an 433 rf remote button.
The light works already fine with a sonoff touch with tasmote.
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
Are you using python3? If so, type
Then type
What do you get?
If you are using python3, then you need to change the first line of the python script to this:
Incidentally, what hardware / operating system / version of Domoticz are you using?
Code: Select all
python3
Code: Select all
import paho.mqtt.client
If you are using python3, then you need to change the first line of the python script to this:
Code: Select all
#!/usr/bin/env python3
-
- Posts: 26
- Joined: Wednesday 28 November 2018 19:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
This i get whwn i type this commands
- Attachments
-
- console.jpg (52.78 KiB) Viewed 9843 times
-
- Posts: 26
- Joined: Wednesday 28 November 2018 19:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
i see that if i only type python it say's me the version 2.7.9
And then import the client and i get the same as my last message
And then import the client and i get the same as my last message
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
If you get an error (not found) message when you type
then this means it hasn't been installed under python (2.7.9), only python3.
Code: Select all
python
import paho.mqtt.client
-
- Posts: 26
- Joined: Wednesday 28 November 2018 19:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
i don't get an error on both.
not on python and python3
so i asume it should be working.
Only in domoticz it say's in the log no module named paho.
not on python and python3
so i asume it should be working.
Only in domoticz it say's in the log no module named paho.
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
Can you post the script you are using here? (use a '</>' block)
-
- Posts: 26
- Joined: Wednesday 28 November 2018 19:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
It is what you posted here
<#!/usr/bin/python3
'''
Python script to read rfkey number from Sonoff 433MHz RF Bridge
and control corresponding Domoticz.
This example only set up for 2 devices; extend by adding idx's in on_message.
(Not very pretty code!)
'''
import paho.mqtt.client
import time
import json
### substitute your values here ###
broker_address="127.0.0.1" # port = 1883 by default
topic = "<sonoff topic>"
dom_cmd = "http://localhost:8080/json.htm?type=com ... cmd=Toggle"
idx1 = 0
idx2 = 0
###################################
def on_message(client, userdata, message):
print ("message received " ,str(message.payload.decode("utf-8")))
jsonData = json.loads(message.payload)
rfkey = jsonData['RfReceived']['RfKey']
print ("rfkey")
if rfkey == 1:
idx = idx7
elif rfkey == 2:
idx = idx2
else:
return
url = dom_cmd + "&idx=" + str(idx)
print ("url")
r = requests.get(url)
#print "message topic=",message.topic
#print "message qos=",message.qos
#print "message retain flag=",message.retain
print("creating new instance")
client = mqtt.Client("P1") #create new instance
client.on_message=on_message #attach function to callback
print("connecting to broker")
client.connect(broker_address) #connect to broker
client.loop_start() #start the loop
print("Subscribing to topic ") + topic
client.subscribe("tele/" + topic + "/RESULT")
time.sleep(2) # wait
client.loop_forever() #loop forever
time.sleep(2) # wait
client.loop_forever() #loop forever>
<#!/usr/bin/python3
'''
Python script to read rfkey number from Sonoff 433MHz RF Bridge
and control corresponding Domoticz.
This example only set up for 2 devices; extend by adding idx's in on_message.
(Not very pretty code!)
'''
import paho.mqtt.client
import time
import json
### substitute your values here ###
broker_address="127.0.0.1" # port = 1883 by default
topic = "<sonoff topic>"
dom_cmd = "http://localhost:8080/json.htm?type=com ... cmd=Toggle"
idx1 = 0
idx2 = 0
###################################
def on_message(client, userdata, message):
print ("message received " ,str(message.payload.decode("utf-8")))
jsonData = json.loads(message.payload)
rfkey = jsonData['RfReceived']['RfKey']
print ("rfkey")
if rfkey == 1:
idx = idx7
elif rfkey == 2:
idx = idx2
else:
return
url = dom_cmd + "&idx=" + str(idx)
print ("url")
r = requests.get(url)
#print "message topic=",message.topic
#print "message qos=",message.qos
#print "message retain flag=",message.retain
print("creating new instance")
client = mqtt.Client("P1") #create new instance
client.on_message=on_message #attach function to callback
print("connecting to broker")
client.connect(broker_address) #connect to broker
client.loop_start() #start the loop
print("Subscribing to topic ") + topic
client.subscribe("tele/" + topic + "/RESULT")
time.sleep(2) # wait
client.loop_forever() #loop forever
time.sleep(2) # wait
client.loop_forever() #loop forever>
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
OK, under the heading '### substitute your values here ###', you need to change the line
Go to the 'Configure MQTT' tab on your RF Bridge, and note the topic value there, and replace the above (including <> brackets).
- e.g., my MQTT topic is sonoffB, so for me this reads
Code: Select all
topic = "<sonoff topic>"
- e.g., my MQTT topic is sonoffB, so for me this reads
Code: Select all
topic = "sonoffB"
-
- Posts: 26
- Joined: Wednesday 28 November 2018 19:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
Ok,
Tomorrow i will give it a try.
Thank you.
Tomorrow i will give it a try.
Thank you.
-
- Posts: 26
- Joined: Wednesday 28 November 2018 19:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
Ok mi changed it but still get this
2018-12-16 19:22:00.718 Error: EventSystem: Failed to execute python event script "Bridge-test"
2018-12-16 19:22:00.718 Error: EventSystem: Traceback (most recent call last):
2018-12-16 19:22:00.718 Error: EventSystem: File "<string>", line 10, in <module>
2018-12-16 19:22:00.719 Error: EventSystem: ImportError: No module named 'paho'
2018-12-16 19:22:00.718 Error: EventSystem: Failed to execute python event script "Bridge-test"
2018-12-16 19:22:00.718 Error: EventSystem: Traceback (most recent call last):
2018-12-16 19:22:00.718 Error: EventSystem: File "<string>", line 10, in <module>
2018-12-16 19:22:00.719 Error: EventSystem: ImportError: No module named 'paho'
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz
I've noticed a couple more things in your version of the script:
- under '### substitute your values here ###', you have idx1 = 0 and idx2 = 0; you need to replace these with the actual Domoticx idx's of your devices
- and after 'if rfkey == 1:', you should have idx = idx1
- also, the line 'import paho.mqtt.client' should read 'import paho.mqtt.client as mqtt'
- under '### substitute your values here ###', you have idx1 = 0 and idx2 = 0; you need to replace these with the actual Domoticx idx's of your devices
- and after 'if rfkey == 1:', you should have idx = idx1
- also, the line 'import paho.mqtt.client' should read 'import paho.mqtt.client as mqtt'
Who is online
Users browsing this forum: No registered users and 1 guest