Hello there,
Trying to create an automatically discovered binary_sensor here.
In the (partial) arduino code it is
#define smoke_topic "homeassistant/binary_sensor/smoke_1/state"
char state[] = "online";
client.publish(smoke_topic, String(state).c_str(), false);
And it is working, because here is the log of mosquitto:
1676020599: New connection from 192.168.0.103:60568 on port 1883.
1676020599: New client connected from 192.168.0.103:60568 as ESP8266Client (p2, c1, k15, u'mqtt_user').
1676020599: No will message specified.
1676020599: Sending CONNACK to ESP8266Client (0, 0)
1676020599: Received PUBLISH from ESP8266Client (d0, q0, r0, m0, 'homeassistant/binary_sensor/smoke_1/state', ... (6 bytes))
1676020599: Sending PUBLISH to 8xBErttyplVYvDpTgp72CB (d0, q0, r0, m0, 'homeassistant/binary_sensor/smoke_1/state', ... (6 bytes))
1676020599: Sending PUBLISH to mqttjs_18b8f4b1 (d0, q0, r0, m0, 'homeassistant/binary_sensor/smoke_1/state', ... (6 bytes))
6 bytes, online, that is a match
But in HA, I do not have anything automatically created.
Therefore I tried a manual configuration, like so:
In configuration.yaml
mqtt: !include mqtt.yaml`
In mqtt.yaml
# ----------------------------------------------------------------------------------------------------------------------------------
# Everything MQTT
# ----------------------------------------------------------------------------------------------------------------------------------
binary_sensor:
- name: smoke_rdc
state_topic: "homeassistant/binary_sensor/smoke_1/state"
expire_after: 15
icon: mdi:fire
payload_available: online
device_class: smoke
But whatever I publish on the topic, the state remains unavailable
Can someone please guide me?
EDIT: auto discover achieved but state is still unknown
One step at a time.
I change my sketch so now, at startup, it is publishing a config topic.
{"name": "smoke_1", "device_class": "smoke", "unique_id": "smoke_1", "state_topic": "homeassistant/binary_sensor/smoke_1/state"}
Therefore, the binary sensor is created automatically in HA, and I removed my manual config, great.
But, the same issue persists with the state of the sensor.
Looking in the documentation (because, yes, I do read doc and search forum)
It is not mandatory to provide more information than the state_topic.
Whatever I send, as plain text is not changing my sensor’s value.
Tried so far: true
, false
, on
, off
, online
, offline
, detected
, clear
I saw a lot of topic in the forum about template because of json and so on but I’m not sending any kind of json.
Additional question since I managed to do an auto discovered sensor. How do I make the state (if it is working one day) to expire?