A little late to the party, but having just sorted this myself thought I would put the information somewhere, this looked ideal, even though the title is Blockly, and my solution uses dzvents, but I used this thread to get the data coming into domoticz, then butchered some dzvents code to get it working in my setup.
This is for a three way sonoff rf touch switch via a sonoff RF hub but I see no reason why the elseifs can't be extended for every RF transmitter you want to use via the hub, or cut out if you only have one switch. I am not impressed by touch switches, there is no way of feeling for the switches in the dark and they are not very sensitive to touch, I think the front panel is too thick on the sonoff switches as the switches themselves are fine with the front panel off. Single switches are probably a lot better for this, three way, not so much. The hub also takes a while to report a switch press, probaly half a second or so, noticably slower than an RfxTrx433.
I tried setting the dz.devices as local variables to make the code more readable and two of the three switches refused to work, the elseif statement was parsed but the toggle command was not sent, removed the variables and it works fine hence the comments so I know which code is operating which bulb, no idea why it didn't work as I use local variables in other code and it works fine, I am not a programmer so I'm probably missing something simple, I also prefer using idx numbers instead of names as I have had this break in the past, can't remember why though.
The following stuff will need changing to match yours actual values: devices = { 123 } is the idx of the fake electricity meter that the hub sends the rf codes to, 1385128, 1385124, 1385122 are the actual RF codes the switch sends, if you log into the rf hub you can see these on the console window when operating a switch if you are looking for an easy way to get them as they don't get reported in the Domoticz log normally. 100, 200 and 300 represent the idx for each device that we want to switch, change all of these to match your values.
Code: Select all
return {
on = { devices = { 123 } },
execute = function(dz, bridge)
--switch 1 sends code 1385128 if we receive that toggle bulb 1 that has idx of 100
if bridge.actualWatt == 1385128 then
dz.devices(100).toggleSwitch()
--switch 2 sends code 1385124 if we receive that toggle bulb 2 that has idx of 200
elseif bridge.actualWatt == 1385124 then
dz.devices(200).toggleSwitch()
--switch 3 sends code 1385122 if we receive that toggle bulb 3 that has idx of 300
elseif bridge.actualWatt == 1385122 then
dz.devices(300).toggleSwitch()
end
end
}