Hi all,
Hope you can help me with the bellow.
Scenario:
Have a garden light system that I can control via IFTTT
Automations are setup to turn on and off based on some triggers and rules and everything works
Now want to simply understand when the garden lights are on or off based on automation activation since I can’t pull garden lights for state
Following a very simple idea I configured a MQTT binary sensor so when the automations would turn lights on it will also publish ON to MQTT using “mytopic” and when the automations turn the lights off would then publish OFF to MQTT using the same topic
All of this seems pretty simple right!? But the damn binary sensor won’t update and will always be off.
Configuration:
HA 0.84.2 running on docker
mqtt:
discovery: true
discovery_prefix: homeassistant
binary_sensor:
- platform: mqtt
name: "garden_back_lights"
device_class: light
state_topic: "home-assistant/garden/lights"
Automations configuration:
- id: '1544892982419'
alias: Turn on garden lights at sunset
trigger:
- event: sunset
platform: sun
condition: []
action:
- data:
event: HA_garden_all_lights_on
value1: 'NULL'
service: ifttt.trigger
- data:
payload: 'ON'
retain: 'true'
topic: home-assistant/garden/lights
service: mqtt.publish
subscribe to the topic manually and verify that the message is being published. Start there.
Also, could you format your yaml so syntax can be checked? Right now it’s confusing. It would also help to see both automations, on and off.
You might also consider using qos
to ensure the message is being successfully sent.
QOS levels in MQTT
Thanks. Have turned mqtt logger to debug and the message is there.
Working on correcting the format.
Format updated on original post.
Regarding the message I think it is being posted since in the log I get
18-12-17 20:59:53 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on home-assistant/garden/lights: ON
everything looks good so I’m kinda stumped. Do you need a binary sensor? or do you just want to know the state?
You could just use a plain mqtt sensor
sensor:
- platform: mqtt
name: "garden_back_lights"
state_topic: "home-assistant/garden/lights"
and when it appears on the front end it just shows the current message. On or Off.
So switching to a sensor it reports all the time the state as unknown even after publishing on to the MQTT topic.
And finally got it
After putting the password on the MQTT configuration it started working.
mqtt:
discovery: true
discovery_prefix: homeassistant
password: !secret mqtt_password
Anyone knows why?
If you created a password then you have to have a user/password in order to subscribe to the topics. That’s why nothing was working.
it’s a security thing.
Thanks. IMHO documentation should list this has mandatory then…
gpbenton
(Graham)
December 17, 2018, 10:25pm
10
It could be more clear, but it is only mandatory if you use the embedded broker. External broker’s do not require a password.
1 Like
only if you’ve not set up a password. The issue here is there’s so much ‘plug&play’ now that its extremely easy to get lost in the docs.