Sonoff - Tasmota - RF 433MHz push buttons and C-Bus

Discussion in 'C-Bus Automation Controllers' started by Damaxx, Jan 16, 2021.

  1. Damaxx

    Damaxx

    Joined:
    May 12, 2008
    Messages:
    226
    Likes Received:
    47
    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()
    
     
    Damaxx, Jan 16, 2021
    #1
    philthedill likes this.
  2. Damaxx

    Damaxx

    Joined:
    May 12, 2008
    Messages:
    226
    Likes Received:
    47
  3. Damaxx

    znelbok

    Joined:
    Aug 3, 2004
    Messages:
    1,151
    Likes Received:
    17
    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
     
    znelbok, Jan 18, 2021
    #3
    philthedill and Damaxx like this.
  4. Damaxx

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    140
    Likes Received:
    3
    Location:
    Melbourne
    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.....
     
    philthedill, Feb 5, 2021
    #4
  5. Damaxx

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    140
    Likes Received:
    3
    Location:
    Melbourne
    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
     
    philthedill, Feb 13, 2021
    #5
  6. Damaxx

    Damaxx

    Joined:
    May 12, 2008
    Messages:
    226
    Likes Received:
    47
    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.
     
    Damaxx, Feb 13, 2021
    #6
  7. Damaxx

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    140
    Likes Received:
    3
    Location:
    Melbourne
    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?
     
    philthedill, Feb 13, 2021
    #7
  8. Damaxx

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    140
    Likes Received:
    3
    Location:
    Melbourne
    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.
     
    philthedill, Feb 14, 2021
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.