Finally decided to go to the dark side and check out this Sonoff stuff all the kids are talking about. Ordered in a few 433Mhz push buttons and the RF Bridge. Flashed the RF bridge with Tasmota to get away from the cloud service rubbish and gave it a test run. Each push button sends a signal to the RF bridge which in turn publishes a JSON string to the MQTT broker. Had fully intended to go from there into my Home Assistant server to control lighting, etc, but decided to see if I could get the SHAC to do the work instead. After a bit of tinkering came up with this Code: mqtt = require("mosquitto") client = mqtt.new() client.ON_CONNECT = function() -- log("connected") client:subscribe("tele/houserfb/RESULT") local mid = client:subscribe("tele/houserfb/RESULT", 2) end client.ON_MESSAGE = function(mid, topic, payload) -- next line turns JSON output from RF Bridge to LUA Table RFKey = "return "..payload:gsub('("[^"]-"):','[%1]=') Table=loadstring(RFKey)() -- Extract the RFKey number assigned in Tasmota RFButt = (Table.RfReceived.RfKey) if RFButt == 1 then light1= GetCBusState(0, 56, 20) if light1 == true then SetCBusState(0, 56, 20, false) else SetCBusState(0, 56, 20, true) end elseif RFButt == 2 then light2 = GetCBusState(0, 56, 32) if light2 == true then SetCBusState(0, 56, 32, false) else SetCBusState(0, 56, 32, true) end elseif RFButt == 3 then light3= GetCBusState(0, 56, 34) if light3 == true then SetCBusState(0, 56, 34, false) else SetCBusState(0, 56, 34, true) end end end broker = "xxx.xxx.xxx.xxx" -- MQTT broker address client:connect(broker) client:loop_forever()
Links to the bits I used RF Bridge - https://www.itead.cc/sonoff-rf-bridge-433.html RF Wall switch - https://www.itead.cc/smart-home/sonoff-t2eu-rf-86-type-433-wall-sticky-rf-remote.html
Just as a heads up since you are playing in this area - The Arlec Grid Connect gear available at Bunnings can be flashed with Tasomta as well. I have a four outlet powerboard, and a couple of plug modules flashed. At least they are certified for Aus
This is great. Damaxx has done the hard work here. My bits arrived from Bangood promptly and I was able to flash the bridge (not ota) and get it going. I've got the MQTT broker running on Raspberry Pi3. I have a three-button remote unit operating some blinds. I have the script running as a resident with 60 sec rest. It seems to work fine but not sure what Damaxx had intended in this regard? I've now ordered some more sticky RF remote controls.....
Another question - how might I add additional Tasmota flashed sonoff's (basics - not an RF bridge) into the above script - do I need a separate one running for each device or should they co-exist within the one script? also the question in # 4 remains unanswered but it is working fine... thanks
Not sure Phil as I haven't tinkered with other Tasmota products, but being MQTT I assume it would be similar - subscribe to the topic to read a button press and write to a topic for controlling an output. Don't believe there is any advantage of putting it in one script or many. I have my script as a resident script with no sleep interval as I want it to continually loop to capture any button press.
thanks for that. Just to confirm.... the shac needs to engage with the broker as 2 separate activities ie: subscribe (this thread) and publish (via another mechanism)? Separately, I have my resident script running with 30s sleep interval and it is working fine. This might warrant further thinking - maybe it should be an "init" script?
I've moved the script to "init" and it runs once when SHAC starts. Works fine but in the event of a power failure, it is important that network and MQTT broker are "up" before attempting to connect. I have used the < WaitForCBusStatus(30) == true > to introduce the delay.