PI MQTT broker connection to HA

I am running mosquitto on a Raspberry pi B+. I have HA installed on my laptop in a virtual env. I can

 su -s /bin/bash homeassistant
homeassistant@travis-Asus ~/.homeassistant $ ping 192.168.1.200
PING 192.168.1.200 (192.168.1.200) 56(84) bytes of data.
64 bytes from 192.168.1.200: icmp_seq=1 ttl=64 time=1.13 ms
64 bytes from 192.168.1.200: icmp_seq=2 ttl=64 time=1.39 ms

my configuration.yaml

    mqtt:
  broker: 192.168.1.200

#Switches go under here

switch:
  - platform: mqtt
    name: "cord1"
    state_topic: "stat/diana/cord1/power"
    command_topic: "diana/cord1/power"
    qos: 1
    payload_on: "On"
    payload_off: "Off"
    retain: true
#optimistic: false

# Example configuration.yaml entry mqtt_template

light:
  - platform: mqtt_template
    command_topic: "diana/cord1/"
    command_on_template: "on"
    command_off_template: "off"
    state_template: diana/cord1/STATE
```

both yaml entries point at the same switch.

My mosquitto.conf

pid_file /var/run/lib/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
connection_messages true
allow_anonymous true

My Sonoff settings

Sonoff Basic Module
Cord1

 MQTT parameters 

Host (domus1)
192.168.1.200

Port (1883)
1883


Client Id 
Cord1

User (DVES_USER)
openhabian    ===> (guess where I came from)

Password
•

Topic = %topic% (sonoff)
cord1

Full Topic (%prefix%/%topic%/)
diana/cord1/

All of this gives me 2 switches in the HA web UI they toggle but my light doesn’t come on.
MQTTlens subscribed to above topics receives nothing.

on my laptop where HA is installed:

.homeassistant # su -s /bin/bash homeassistant
homeassistant@travis-Asus ~/.homeassistant $ mosquitto_sub -h '192.168.1.200' -t '#' -v
diana/lights/cord1 0
diana/lights/cord1/LWT Offline
diana/lights/cord1/POWER 0
diana/cord1/LWT Online
cmnd/cord1/POWER OFF
cmnd/diana/lights/cord1 0
cmnd/diana/lights/cord1/POWER ON
cmnd/diana/lights/cord1/POWER/ ON
cmnd/diana/cord1/POWER On
cmnd/travalons_lamp/POWER/ ON
cmnd/tcord1/POWER OFF
cmnd/sonoff/POWER OFF
cmnd/sonoff/LWT Offline
stat/tcord1/POWER:state:default 0
tasmota/tele/%sonoff-A00EEAA%/LWT Offline
sonoff 1
%cmnd%/%sonoff%/POWER ON
%cmnd%/%sonoff%/POWER/LWT Offline
cord1/POWER/LWT Offline
diana/cord1/power on
cmnd/diana/cord1/POWER On
diana/cord1/RESULT {"POWER":"ON"}
diana/cord1/POWER ON
diana/cord1/RESULT {"POWER":"OFF"}
diana/cord1/POWER OFF
diana/cord1/RESULT {"POWER":"ON"}
diana/cord1/POWER ON
diana/cord1/RESULT {"POWER":"OFF"}
diana/cord1/POWER OFF
diana/cord1/power off
cmnd/diana/cord1/POWER On
cmnd/diana/cord1/POWER On
diana/cord1/power on
diana/cord1/power off

other subscriptions:
on HA machine and on PI through ssh

homeassistant@travis-Asus ~/.homeassistant $ mosquitto_sub -h ‘192.168.1.200’ -t ‘diana/cord1/*’ -v

and
openhabian@openHABianPi:/etc/mosquitto$ mosquitto_sub -h localhost -t ‘diana/cord1/#’ -v
diana/cord1/LWT Online
diana/cord1/power on

I can’t figure out why the commands don’t make it to the sonoff and toggle the light. (Or how I managed to format this post like this) Your thoughts are apprciated.

I think you need to match the case.

1 Like

It’s likely not the fix but I was experiencing similar issues. When I added a username and password to both Mosquitto and HA, it started working. I did leave in the “allow_anonymous true” statement though.