MQTT and HASSIO

Like many other posts I am really confused about MQTT, sonoffs and HassIO.
I have a ubuntu machine running as my MQTT broker in my home network on 192.168.1.38 using the standard port 1883.

I have 7 sonoff devices which are all auto detected and controlled by Tasmota inside HASSIO.
I have enabled MQTT on the Sonoffs and can see the messages going back and forwards in MQTT.FX

BUT

I cannot see any of these devices appearing in HASSIO itself. I set an automation script to force auto discovery

# Example automations.yaml entry
- alias: "Enable MQTT discovery for all devices"
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: mqtt.publish
      data:
        topic: "sonoffs/cmnd/SetOption19"
        payload: "1"

- alias: "Power state on HA start-up"
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: mqtt.publish
      data:
        topic: "sonoffs/cmnd/state"
        payload: "" 

I have hard coded and removed ‘switch’ sections in configuration.yaml
Nothing ever lets me control the devices from the overview window of HASSIO.
If I hard code, I see the devices as switches on a panel, but nothing works. You click on a switch, it slides grey to blue, nothing happens and a second or two later it slides back to off.

I have sonoff-Tasmota 6.5.0 on all devices.

As two examples I have setup MQTT one sonoff as Topic = man_cave and the second as Topic=garage_light . The full topic is the default "%topic%/%prefix%/

In the tasmo admin panel in HASSIO if I select list devices, it shows their friendly names
ManCaveLight IP address, state, versions 6.5.0 etc

If I then click the cog wheel on the devices and select MQTT I see:

MQTT Host 192.168.1.38 Port 1883
MQTT Client Name = DVES_97252D
username and password are both as expected
MATT Topic = man_cave MQTT FullTopic=%topic%/%prefic%/
Group topic = sonoffs Button Topic and Switch Topic are both 0
Prefix 1: Command = cmnd Prefix 2:State =stat Prefix 3:Telemetry = tele
State Text: OFF = OFF State Text: ON = ON

I have hundreds of messages in MQTT Lens

some are under “man_cave/stat/STATUS1”

some are under “garage_light/stat/STATUS1” e.g.
{“StatusSTS”:{“Time”:“2019-03-20T00:51:12”,“Uptime”: “0T00:44:41”,“Vcc”:3.259,“SleepMode”: “Dynamic”,“Sleep”:50,“LoadAvg”:19,“POWER1”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“TheBunns”, “BSSId”:“E8:FC:AF:FF:6F:CB”,“Channel”:11,“RSSI”:50,“LinkCount”:1,“Downtime”:“0T00:00:04”}}}

but right after starting HASSIO I got a few entries like:

homeassistant/light/97542D_L1_1/config
I also got only once messages as follows:

cmnd/sonoff_1/POWER with the message being OFF
cmnd/sonoff_5/POWER with the message also being OFF

I happen to know that I set sonoff_1 as my garage light and sonoff_5 as my man_cave light.

with entries for sensor, switch and light on the same topic

Never seen these again after start up.

So my questions are:

  1. How do I make sure these are seen in HASSIO?
  2. Setting Option 19 is often mentioned, but I cannot see this under any menu item in the sonoff configuration, either by directly accessing the device on port 80, or using tasmota admin in HASSIO.
  3. How do I get then name these devices in future automation?

I used to have this automation running

- id: '1530933735131'
  alias: Garage Lights On
  initial_state: 'on'
  trigger:
  - entity_id: sensor.garage_door_status
    from: closed
    platform: state
    to: open
  condition:
  - after: '15:00:00'
    before: 03:00:00
    condition: time
  action:
  - data:
      entity_id: switch.garage_lights
    service: switch.turn_on
'''

Do you have the MQTT integration? Does it list the devices?
SetOption19 On is entered in the console of the device… but you have an automation doing that.
When you added the MQTT integration, did you check the box for Discovery?
You can remove the Integration (if it exists), Restart HA, Add Integration again with discovery checked (restart again) does that fix it?

You said you don’t have any MQTT settings in config? No mqtt: section and no MQTT switches? Good. (If you do have them then remove them). If your broker is not the Hass.io addon and not on the same device, you will need the mqtt section.

Looks like everything else is good.

I have the MQTT Integration. It lists no devices
Instead is says MQTT: configuration.yaml
and has a “>” that if I click on it changes to a windows that says “This integration has no devices”

I so have an MQTT section in configuration.yaml
it says

mqtt:
  broker: 192.168.1.38
  port: 1883
  client_id: home-assistant
  username: hassio
  password: !secret MQTT_Password
  keepalive: 60
  protocol: 3.1.1

My broker is external on a ubuntu machine. HASSIO is on a raspberry PI at 192.168.1.35

How do you remove an integration?
Dumb question, I spotted the waste paper basket

not so dumb
I hit delete, had it confirm deleted, restarted and …it is still there

I ran status 0 on my sonoff and got:

01:28:24 CMD: status 0
01:28:24 MQT: man_cave/stat/STATUS = {"Status":{"Module":1,"FriendlyName":["ManCaveLight"],"Topic":"man_cave","ButtonTopic":"0","Power":0,"PowerOnState":3,"LedState":1,"SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0}}
01:28:24 MQT: man_cave/stat/STATUS1 = {"StatusPRM":{"Baudrate":115200,"GroupTopic":"sonoffs","OtaUrl":"https://github.com/arendst/Sonoff-Tasmota/releases/download/v5.14.0/sonoff.bin","RestartReason":"Software/System restart","Uptime":"0T01:22:12","StartupUTC":"2019-03-19T23:06:12","Sleep":50,"CfgHolder":4617,"BootCount":123,"SaveCount":530,"SaveAddress":"F5000"}}
01:28:24 MQT: man_cave/stat/STATUS2 = {"StatusFWR":{"Version":"6.5.0(release-sonoff)","BuildDateTime":"2019-03-19T12:24:10","Boot":4,"Core":"2_3_0","SDK":"1.5.3(aec24ac9)"}}
01:28:24 MQT: man_cave/stat/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"SysLog":0,"LogHost":"domus1","LogPort":514,"SSId":["TheBunns","indebuurt2"],"TelePeriod":300,"Resolution":"558180C0","SetOption":["540A0009","280500000100000000000000000000000000","00000201"]}}
01:28:24 MQT: man_cave/stat/STATUS4 = {"StatusMEM":{"ProgramSize":507,"Free":496,"Heap":14,"ProgramFlashSize":1024,"FlashSize":1024,"FlashChipId":"1440E0","FlashMode":3,"Features":["00000809","0FDAE394","000783A0","23B617CE","00003BC0"]}}
01:28:24 MQT: man_cave/stat/STATUS5 = {"StatusNET":{"Hostname":"man_cave-1325","IPAddress":"192.168.1.51","Gateway":"192.168.1.2","Subnetmask":"255.255.255.0","DNSServer":"192.168.1.2","Mac":"5C:CF:7F:97:25:2D","Webserver":2,"WifiConfig":2}}
01:28:24 MQT: man_cave/stat/STATUS6 = {"StatusMQT":{"MqttHost":"192.168.1.38","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_97252D","MqttUser":"hassio","MqttCount":1,"MAX_PACKET_SIZE":1000,"KEEPALIVE":15}}
01:28:25 MQT: man_cave/stat/STATUS7 = {"StatusTIM":{"UTC":"Wed Mar 20 00:28:24 2019","Local":"Wed Mar 20 01:28:24 2019","StartDST":"Sun Mar 31 02:00:00 2019","EndDST":"Sun Oct 27 03:00:00 2019","Timezone":"+01:00","Sunrise":"06:53","Sunset":"19:02"}}
01:28:25 MQT: man_cave/stat/STATUS10 = {"StatusSNS":{"Time":"2019-03-20T01:28:25","Switch1":"ON"}}
01:28:25 MQT: man_cave/stat/STATUS11 = {"StatusSTS":{"Time":"2019-03-20T01:28:25","Uptime":"0T01:22:13","Vcc":3.216,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":44,"POWER1":"OFF","Wifi":{"AP":1,"SSId":"TheBunns","BSSId":"E8:FC:AF:FF:6F:CB","Channel":11,"RSSI":100,"LinkCount":1,"Downtime":"0T00:00:04"}}}
01:29:00 MQT: man_cave/tele/STATE = {"Time":"2019-03-20T01:29:00","Uptime":"0T01:22:48","Vcc":3.217,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":49,"POWER1":"OFF","Wifi":{"AP":1,"SSId":"TheBunns","BSSId":"E8:FC:AF:FF:6F:CB","Channel":11,"RSSI":100,"LinkCount":1,"Downtime":"0T00:00:04"}}
01:29:00 MQT: man_cave/tele/SENSOR = {"Time":"2019-03-20T01:29:00","Switch1":"ON"}

So I managed to restart twice, did not get to add the integration as it was still there but now I have icons for all my sonoffs under the integration. The only change I made was to add the following to my configuration.yaml

mqtt:
  discovery: true
  discovery_prefix: homeassistant    

Now I can turn these lights ON and OFF from ‘integrations’ and from ‘tasmo admin’ but they are not on the Overview page. Do I have to manually add them?

wait a minute…they just turned up…it took a while

Ah… yeah… you’re using an external broker so has to be configured and discovery: true in config…

One question: These used to be ‘discovered’ as switches. Now the entities are discovered as ‘light’ so my automation needs to be rewritten to

- id: '1530933735131'
  alias: Garage Lights On
  initial_state: 'on'
  trigger:
  - entity_id: sensor.garage_door_status
    from: closed
    platform: state
    to: open
  condition:
  - after: '15:00:00'
    before: 03:00:00
    condition: time
  action:
  - data:
      entity_id: light.garagelight
    service: light.turn_on
- id: '1530936913609'
  alias: Garage Lights Off
  initial_state: 'on'
  trigger:
  - entity_id: sensor.garage_door_status
    from: open
    platform: state
    to: closed
  condition:
  - after: '15:00:00'
    before: 03:00:00
    condition: time
  action:
  - delay: 00:05:00
  - data:
      entity_id: light.garagelight
    service: light.turn_off

right? I checked in ‘entities’ and I dont see these listed under switches, only under ‘lights’ with the friendly name garagelight even though I called it Garage_Light in the MQTT settings.

See here… you can fix it…

I think you can do the reverse as well…

Thanks David, every seems to be working now, just about to head home and see if my automation works again!

1 Like

All working!!