SHAC and MQTT Scripts

Discussion in 'C-Bus Automation Controllers' started by pspeirs, Mar 6, 2022.

  1. pspeirs

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    Moving this thread public to share . . .


    Yes, at this point I'm not handling the ramp timing since I'm not sure that's something that Home Assistant can handle, its more of a C-Bus quirk I thought. In any case you would currently send ramp messages like:

    cbus/write/254/56/20/ramp 89
    cbus/write/254/56/20/switch OFF
    cbus/write/254/56/20/switch ON

    You would set up your switch yaml like the following . . .

    Code:
      - platform: mqtt
        name: 'Kitchen'
        command_topic: 'cbus/write/254/56/20/switch' # Topic to publish commands
        state_topic: 'cbus/read/254/56/20/state' # Topic to read the current state
        brightness_state_topic: 'cbus/read/254/56/20/level' # Topic to read the current state
        brightness_command_topic: 'cbus/write/254/56/20/ramp' # Topic to publish commands
        brightness_scale: 255
        on_command_type: brightness
        retain: false # or false if you want to wait for changes
        payload_off: 'OFF' # or "off", depending on your MQTT device
        payload_on: 'ON' # or "on", depending on your MQTT device
    
     
    pspeirs, Mar 6, 2022
    #1
  2. pspeirs

    znelbok

    Joined:
    Aug 3, 2004
    Messages:
    1,151
    Likes Received:
    17
    So no ramp timing in the payload. Would be nice to add it if possible as not everyone is using Home Assistant to communicate with C-bus.

    I would hope that scripting could accept just the ramp value and if present the ramp rate as well. That way is HA cant use it, its not needed and for others that can use it , its an option

    Thanks for the script though
     
    znelbok, Mar 7, 2022
    #2
  3. pspeirs

    Dasman

    Joined:
    May 5, 2011
    Messages:
    37
    Likes Received:
    5
    Location:
    Adelaide
    Getting the ramp rate data and including that as part of a payload with MQTT would be reasonably easy to do, but is there a method at the other end to interpret this data?

    My scripts that I have here create a JSON model that include values such as timestamp and the topic but I had code sitting in AWS which interpretted these values.
     
    Dasman, Mar 10, 2022
    #3
  4. pspeirs

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    248
    Likes Received:
    31
    Location:
    New Zealand
    If you want to pass the ramp rate, you can use event.datahex from the event script, the last 2 bytes are the ramp rate so if datahex was EFEF0008 ramp rate rate would be 0008, 8 sec

    require('socket').udp():sendto(event.dst .. "/" .. event.getvalue()..”/”..event.datahex, '127.0.0.1', 5432)

    then process it in cbus2mqtt script to send to MQTT topic.
     
    Pie Boy, Mar 10, 2022
    #4
  5. pspeirs

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    248
    Likes Received:
    31
    Location:
    New Zealand
    The conversion to extract the ramp rate in sec

    rrate = tonumber(string.sub(event.datahex, 5 , 8), 16 )
    log(rrate)
     
    Pie Boy, Mar 11, 2022
    #5
  6. pspeirs

    Dasman

    Joined:
    May 5, 2011
    Messages:
    37
    Likes Received:
    5
    Location:
    Adelaide
    There is also a dedicated function in Lua for this as well

    rrate = GetCBusRampRate(0, 56, 1)
     
    Dasman, Mar 15, 2022
    #6
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.