MQTT Last Will Message

Discussion in 'C-Bus Automation Controllers' started by pspeirs, Feb 17, 2022.

  1. pspeirs

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    Hi All,

    Has anyone been able to get the LWT message working correctly with the MQTT broker?


    Code:
    
    client.ON_CONNECT = function()
        
        log(string.format("SHAC2MQTT - MQTT Client Connected to %s", mqtt_broker));
        log(client:will_set(mqtt_lwt_offline, mqtt_lwt_payload));
    
      blahh, blahh
    
    
    returns true, however if I disable the script I'm not getting ab LWT message back.



    Cheers,
    Paul
     
    pspeirs, Feb 17, 2022
    #1
  2. pspeirs

    Dasman

    Joined:
    May 5, 2011
    Messages:
    39
    Likes Received:
    5
    Location:
    Adelaide
    Dasman, Feb 18, 2022
    #2
  3. pspeirs

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    Hey there,

    Thanks for the quick response, I've quickly gone through your scripts and looks like quite a bit of work put into it, I'm doing something a little different but in terms of setting the lwt message it all looks the same. Basically, set the creds, set the lwt message and connect.

    I might install your scripts if I get time and see how it works as a whole, I haven't looked at it yet with wireshark either.
     
    pspeirs, Feb 18, 2022
    #3
  4. pspeirs

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    In conclusion, after looking at a wireshark trace, it appears the issue was between the chair and keyboard on this one. One other interesting thing to note is that stopping the script from running appears to do a graceful shutdown of any tcp functions as the MQTT broker sends the offline message immediately rather than waiting for the timeout period to expire. I see the connection close properly in wireshark as well.

    Looks like you've also set up home assistant based on your scripts. I'm bedding down the system and now using c-bus as almost a 3rd party plug in.

    Cheers,
    Paul
     
    pspeirs, Feb 20, 2022
    #4
  5. pspeirs

    Dasman

    Joined:
    May 5, 2011
    Messages:
    39
    Likes Received:
    5
    Location:
    Adelaide
    I was doing some investigation on what is involved with getting C-Bus connected to HA via MQTT, correct. My script only supports lighting at this stage, but i'd like to think it does it well. Will eventually get around to developing other aspects of C-Bus into it (Blinds etc)

    Let me know how you go with your script, and if you do use the HA script i have, I would be interested in some feedback on it
     
    Dasman, Feb 21, 2022
    #5
  6. pspeirs

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    I've actually had it running now for some time but was trying to figure out why the LWT wasn't working for me. The approach I took, and I can't claim all the credit for the script although it's been heavily modified since.

    I've created a UDP server running on the resident publisher script that gets the value from the cbus object. This way, I don't need to maintain a list of objects I want to process, I simply add a tag to the object, and it will automatically call an event script triggered by the keyword. You could probably integrate that into your solution fairly easily.

    I don't have the script up on github be can do so fairly quickly if you're interested.
     
    pspeirs, Feb 21, 2022
    #6
  7. pspeirs

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    Good thing you prompted me to upload the scripts to GitHub. The shac shat itself today and defaulted. Lost all configuration and it was back to factory. I didn’t have a recent backup although I thought I did, but at least I had the mqtt scripts. I guess now if the perfect time to flash the wall mount screen with original firmware and run the home assistant interface
     
    pspeirs, Feb 22, 2022
    #7
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.