this post was submitted on 30 Jun 2023
0 points (NaN% liked)

homeassistant

12055 readers
36 users here now

Home Assistant is open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server. Available for free at home-assistant.io

founded 1 year ago
MODERATORS
 

I have a single mqtt topic that contains all my humidity/temperature sensors. Each message is simply a json containing the sensor values, a timestamp and sensor ID.

HA can read the topic just fine, but seems to have problems parsing out the device names. I managed to split humidity and tempature into to sensors (by the magic of defining the sensor twice), but I can't really distinguish between the different devices.

Is there a way to dynamically parse the device IDs and create sensors based on that? If necessary, I could do a bit of magic in Telegraf, but I assume HA can do that itself?

top 1 comments
sorted by: hot top controversial new old
[–] knapoc@lemmy.world 1 points 1 year ago* (last edited 1 year ago)

You mean that you just want to have one configuration entry? I doubt that it's possible.

What you could do is creating multiple entries, but you need filter within a template.

{% if value_json['tags'].path == '/mnt/hdd' %}
    {{ (value_json['fields'].used_percent | float(default=0)) | round(2) }}
{% else %}
    {{ states('sensor.disk_use_percent_sdb3') }}
{% endif %}

Having had a similar use case, I ended up configuring device specific topics within telegraf.