I have the MQTT server setup in Hass.io and the sonoff talking to it. I can’t get the switch to show up on the main page or in the Developer tools states. I made sure no other “switch:” commnd is in the config file. Has anyone else run into this issue or can see an obvious problem here?
Config
mqtt:
broker: core-mosquitto
username: !secret mqtt_user
password: !secret mqtt_password
discovery: true
discovery_prefix: homeassistant
switch:
- platform: mqtt
name: “Outdoor Christmas lights”
command_topic: “cmnd/sonoff/power”
state_topic: “stat/sonoff/POWER”
qos: 1
payload_on: “ON”
payload_off: “OFF”
retain: true
- platform: wake_on_lan etc…
Hass.io Mosquitto (v4) Log:
1543426914: New connection from 192.168.1.167 on port 1883.
[INFO] found DVES_USER on local database
1543426915: New client connected from 192.168.1.167(ip of sonoff) as DVES_1079CA (c1, k10, u’DVES_USER’)
I made those changes but no luck showing up on the interface. I looked at my States page and notice the outdoor christmas lights are there but only in the group.all_switches:
group.all_switches off entity_id: switch.ge_14291_inwall_smart_switch_switch,switch.masterbath_switch,switch.outdoor_christmas_lights,switch.rachioe80267_in_standby_mode,switch.wake_on_lan,switch.zone_1__front_drip,switch.zone_10__backyard_west_lawn,switch.zone_11,switch.zone_12__back_drip_garden,switch.zone_13,switch.zone_14__backyard_west_middle,switch.zone_2__front_lawn_east_driveway,switch.zone_3__east_lawn,switch.zone_4__west_driveway_lawn,switch.zone_9__back_drip_trees order: 0 auto: true friendly_name: all switches hidden: true
Question: if you can’t get the switch to show up, how do you know that HASSIO and sonoff are talking? I run my broker on a separate device, but I think your broker needs to be identified by an IP address where you have “core-mosquitto”. Do you have any other MQTT devices that work?
I think I know because the Hass.io Mossquito add-on has a log section that reported this, that 192.168.1.167 is the sonoff switch.
Hass.io Mosquitto (v4) Log:
1543426914: New connection from 192.168.1.167 on port 1883.
[INFO] found DVES_USER on local database
1543426915: New client connected from 192.168.1.167(ip of sonoff) as DVES_1079CA (c1, k10, u’DVES_USER’)
Thanks. So the switch is connecting to the broker, but I’m guessing HA isn’t connecting to the broker. I think it’s because there is no IP specified. You should see a designation in the broker log for HA just like there is for the sonoff switch. Do you see the IP of HASSIO in the broker log?
Thank you so much! That was it. I think I assumed by setting up the mosquitto mqtt in hassio that my home assistant was automatically subscribed. I entered the correct IP (MQTT), user and password in the config file and now it is subscribed and the switch is showing up. Cheers and happy holidays.
day1ok,
Would you please show what the new definition of “Outdoor Chrismas lights” switch looks like? I cannot seem to get my virtual MQTT switch to show up in UI.
What do you mean by definition? My entity was defined as “switch.outdoor_christmas_lights” in the “states” section under developer tools. I used this name and added it to my config file under my “switches:” group to have it show up on my UI.