SHAC/Tasmota/homeassistant

Discussion in 'C-Bus Automation Controllers' started by philthedill, Jun 13, 2021.

  1. philthedill

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    104
    Likes Received:
    0
    Location:
    Melbourne
    I am working towards using homeassistant for my integration and visualization as it will pick up things like Sonos and television controls natively. It also has an inbuilt MQTT broker which I am struggling to get operating. Can anyone see a fauilt with this "event" script which works fine through my pi3 running mosquitto as MQTT broker.

    if
    GetCBusState(0, 59, 9) == true
    then
    status = "ON"
    else
    status = "OFF"
    end

    mqtt = require("mosquitto")
    client = mqtt.new()
    client.ON_CONNECT = function()
    local qos = 1
    local retain = true
    local mid = client:publish("cmnd/Tasmota_S26-6/POWER", status, qos, retain)
    end

    client.ON_PUBLISH = function()
    client:disconnect()
    end

    broker=("192.168.86.105")
    client:login_set("shac", "7372477372")
    client: connect(broker)
    client:loop_forever()

    I can see in homeassistant that the SHAC is logging in okay. I have proved that the device can be operated via home assistant. So it appears the message is not getting from SHAC to the home assistant broker for some reason. I have a separate user name for the SHAC from the target device - not sure if that is necessary.

    thanks in advance

    PTD
     
    philthedill, Jun 13, 2021
    #1
    1. Advertisements

  2. philthedill

    zei20t

    Joined:
    Aug 18, 2010
    Messages:
    127
    Likes Received:
    1
    Location:
    Sydney, Australia
    what version of HA are you running? docker? supervised? installed?

    im struggling to get my SHAC to talk to the integrated version of MQTT from the add-on store in supervised HA.

    using a docker with eclipse MQTT works flawlessly!
     
    zei20t, Jun 16, 2021
    #2
    1. Advertisements

  3. philthedill

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    104
    Likes Received:
    0
    Location:
    Melbourne
    HA core: 2121.6.5
    Supervisor -2021.06.03
    host OS 6.0
    SHAC 1.6.0

    Confirming SHAC logs into HA MQTT okay and disconnects after its publish. Everything else appears to check out which points me to an error in the script I originally posted
    MQTT explorer is seeing the Tasmota device and messages to and from
    MQTT explorer is NOT seeing the SHAC
     
    philthedill, Jun 17, 2021
    #3
  4. philthedill

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    163
    Likes Received:
    25
    Location:
    New Zealand
    when you say, "MQTT explorer is NOT seeing the SHAC" what do you mean exactly?

    i tested your above posted code, (just from shac to mqtt) i can see the topics and messages show up, toggle the group 0/59/9 and see the message change in the MQTT explorer.
     
    Pie Boy, Jun 19, 2021
    #4
  5. philthedill

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    104
    Likes Received:
    0
    Location:
    Melbourne
    thanks for testing the script - I think it is okay too. when I test sending a message from SHAC, I cannot see any "flashing" of any items on MQTT explorer. I am now wondering if the problem might be that I have other resident scripts connected to my other broker running on the pi3. Can the SHAC be connected to 2 brokers at the same time?
     
    philthedill, Jun 19, 2021
    #5
  6. philthedill

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    163
    Likes Received:
    25
    Location:
    New Zealand
    Yeah possibly multiple scripts using the same variable/s you could try using local which locks the variable down a local level, not global, see the below, this should avoid any other variables interfering with other things.
    variables can be global but they are not persistent, but it is possible that if you have an event script with small delay the variable could be available in duplicate locations/scripts at the same time, if you use local you would isolate the variable to its own area/script only

    also if you have multiple scripts connecting to the broker using the same credentials, this could also cause issues, most MQTT broker only allows one connection per device/login credentials
    one of two things will happen, either the last connection to be established takes priority, or Mqtt broker might close the connection.


    if
    GetCBusState(0, 59, 9) == true
    then
    status = "ON"
    else
    status = "OFF"
    end

    local mqtt = require("mosquitto")
    local client = mqtt.new()
    client.ON_CONNECT = function()
    local qos = 1
    local retain = true
    local mid = client:publish("cmnd/Tasmota_S26-6/POWER", status, qos, retain)
    end

    client.ON_PUBLISH = function()
    client:disconnect()
    end

    local broker=("192.168.86.105")
    client:login_set("shac", "7372477372")
    client: connect(broker)
    client:loop_forever()
     
    Pie Boy, Jun 19, 2021
    #6
  7. philthedill

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    104
    Likes Received:
    0
    Location:
    Melbourne
    I've shut pretty well everything down and restarted - no joy unfortunately but thank you for trying. I'll keep tinkering. this is the log from the home assistant MQTT broker... showing SHAC connecting and disconnecting.
    "
    1624067048: New connection from 192.168.86.73 on port 1883.
    1624067048: New client connected from 192.168.86.73 as mosq/?9iUepC]L8KmUrLeol (p1, c1, k60, u'shac').
    1624067076: New connection from 192.168.86.73 on port 1883.
    1624067076: New client connected from 192.168.86.73 as mosq/]mPvYvC1Mhm``ll[0e (p1, c1, k60, u'shac').
    1624067076: Client mosq/]mPvYvC1Mhm``ll[0e disconnected.
    1624067081: New connection from 192.168.86.73 on port 1883.
    1624067081: New client connected from 192.168.86.73 as mosq/DDp>sV[BetIEd?bUTR (p1, c1, k60, u'shac').
    1624067081: Client mosq/DDp>sV[BetIEd?bUTR disconnected.
    1624067088: New connection from 192.168.86.73 on port 1883.
    1624067088: New client connected from 192.168.86.73 as mosq/OW68krbBMmZO6V<S=i (p1, c1, k60, u'shac').
    1624067088: Client mosq/OW68krbBMmZO6V<S=i disconnected.
    1624067132: New connection from 172.30.32.2 on port 1883.
    1624067132: Socket error on client <unknown>, disconnecting.
    1624067157: New connection from 192.168.86.73 on port 1883.
    1624067157: New client connected from 192.168.86.73 as mosq/lY8x[>976RbwJojt4C (p1, c1, k60, u'shac').
    1624067157: Client mosq/lY8x[>976RbwJojt4C disconnected.
    1624067163: New connection from 192.168.86.73 on port 1883.
    1624067163: New client connected from 192.168.86.73 as mosq/CEChW6QE^V33Vb0m`5 (p1, c1, k60, u'shac')."
     
    Last edited: Jun 19, 2021
    philthedill, Jun 19, 2021
    #7
  8. philthedill

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    104
    Likes Received:
    0
    Location:
    Melbourne
    I've added a few delays in the event script now and can see the SHAC connecting to the Home assistant MQTT broker and then disconnecting. This confirms that the issue is in the script OR could it be an incompatibility between the SHAC mqtt client and the version of the Home Assistant which is 1.6.12? My other broker (the Pi3) is running 1.5.7 and is the one that works. When will Clipsal release a firmware upgrade for the SHAC? - it has been years.
     
    philthedill, Jun 20, 2021
    #8
  9. philthedill

    zei20t

    Joined:
    Aug 18, 2010
    Messages:
    127
    Likes Received:
    1
    Location:
    Sydney, Australia
    phil, im getting the same thing with the built-in MQTT broker in HA and my SHAC

    my SHAC shows connected for both scripts in the logs, but nothing passes through

    im using a dockered MQTT (eclipse moqsuitto) broker and its all good
     
    zei20t, Jun 21, 2021
    #9
  10. philthedill

    Damaxx

    Joined:
    May 12, 2008
    Messages:
    207
    Likes Received:
    32
    Thought I would give it a test to see if I could get it working and help out, but got the same issue - HA MQTT allows the SHAC to connect but published topics from the SHAC are not registered on the broker yet no errors.

    I run dockered MQTT broker normally and it's never skipped a beat so curious what it could be??
    Tested with other devices on my system and they worked fine with the HA MQTT. Can only assume it has something to do with the SHAC LUA library for MQTT.
     
    Damaxx, Jun 21, 2021
    #10
  11. philthedill

    zei20t

    Joined:
    Aug 18, 2010
    Messages:
    127
    Likes Received:
    1
    Location:
    Sydney, Australia
    ahh damn, so youre seeing the same thing?

    im glad its not just me :)
     
    zei20t, Jun 23, 2021
    #11
  12. philthedill

    ZacOlly

    Joined:
    Mar 16, 2019
    Messages:
    4
    Likes Received:
    3
    Hey,
    I was having the exact issue using SHAC and MQTT add-on in HA, looking for a stable solution for some customers who want more integration.
    Tried it with the test mosquitto broker and worked a treat.
    Thanks to @Narkov and @Damaxx who pointed me in the direction of trying an external broker.
    I'll be setting up a docker in the coming weeks to keep it all local.
     
    ZacOlly, Jun 23, 2021
    #12
    Damaxx likes this.
  13. philthedill

    philthedill

    Joined:
    Mar 21, 2010
    Messages:
    104
    Likes Received:
    0
    Location:
    Melbourne
    good (and bad) to see this traced back to a SHAC firmware problem- when will the next upgrade come?
     
    philthedill, Jun 28, 2021
    #13
  14. philthedill

    ZacOlly

    Joined:
    Mar 16, 2019
    Messages:
    4
    Likes Received:
    3
    SHAC is fine, issue is the MQTT add-on in HA, use a dockered broker or completely separate broker and it will work fine.
     
    ZacOlly, Jun 28, 2021
    #14
    zei20t likes this.
  15. philthedill

    zei20t

    Joined:
    Aug 18, 2010
    Messages:
    127
    Likes Received:
    1
    Location:
    Sydney, Australia
    hmm i wonder what the difference is between the HA addon and a dockered version. i may look into this further and see what happens
     
    zei20t, Jul 4, 2021
    #15
    1. Advertisements

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.