#Hi I m making a device publish analog
1 messages · Page 1 of 1 (latest)
I've got a LoRa ultrasonic distance sensor that I've configured like so:
"state_topic": "lora/24e124713b444071",
"object_id": "24e124713b444071_distance",
"unit_of_measurement": "Millimetres",
"device_class": "distance",
"value_template": "{{ value_json['distance'] }}",
"name": "Garage Distance",
"platform": "mqtt"
}```
The MQTT discovery topic that's sent to is `homeassistant/sensor/24e124713b444071/garage_distance/config`
Values it sends are like `{ "battery": 95, "distance": 2286 }`
(Value is in millimetres there, it's above where I park my car so am using as a presence detection)
@distant bolt - few follow up questions:
- what is the json config which you have posted above? Where is it configured?
- the topic which you have ends with config. Is that the topic where the analog value needs to be reported.
- does this show up as a device on HA?
My requirement is similar, i have HCSR04 and was able to set up easily using esphome. However, I wanted to try arduino sketch programming and try to publish it myself.
You send that JSON to the topic ending /config with the "retain" value set (I just use mosquitto_pub but by any means is fine)
How that topic is constructed (along with the values in the JSON) are documented here:
https://www.home-assistant.io/integrations/mqtt/#discovery-topic
The state_topic attribute is where the data goes, and value_template tells HA how to parse it (my LoRa gateway sends JSON, your sensor might send raw values).
And yes, it becomes a "device": https://i.imgur.com/3VieNU9.png
If you have a device with multiple sensor values (say a combined temperature/humidity unit), you can combine them together. If the 16-character hex value in that topic (the 24e124713b444071, which is the unique ID for that LoRa device) is the same for each value, they'll become part of the same device
So for instance my interior climate sensors look like
homeassistant/sensor/24e124725c145810/dining_room_temperature/config
homeassistant/sensor/24e124725c145810/dining_room_humidity/config
etc
Which gives you a "device" that looks like this: https://i.imgur.com/ZUo6OxN.png