Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 103358

Automated way to generate MQTT Sensors?

$
0
0

Hi,

I was reading the MQTT discovery docs but I am unsure if this matches my case…

I am populating a mqtt topic with weather forecast values through json-string:

  "wetter_vorhersage": {
    "vorhersage_1h": {
      "clouds": 27,
      "humidity": 63,
      "pressure": 1029,
      "wind_deg": 122,
      "rain": 0,
      "snow": 0,
      "dew_point": 5.7,
      "temp": 12.6,
      "feels_like": 11.5,
      "wind_speed": 4.2
    },
    "vorhersage_2h": {
      "clouds": 26,
      "humidity": 62,
      "pressure": 1029,
      "wind_deg": 124,
      "rain": 0,
      "snow": 0,
      "dew_point": 5.8,
      "temp": 12.9,
      "feels_like": 11.9,
      "wind_speed": 4.5
    },
...

Of course I can configure each sensor manually in configuration.yaml as follows:

 - platform: mqtt
   state_topic: hzg/status
   name: "wv1_clouds"
   unit_of_measurement: "%"
   force_update: true
   value_template: '{{value_json.wetter_vorhersage.vorhersage_1h.clouds}}'

But with adding forecast hours (up to 24) you can imagine this is not really useable- besides the issue when something changes. then I have to edit at least 24 items.

The MQTT messages are fully configurable for me- so I can easily change them to match the needs of HA discovery. Just: how to?
As far as I understood I need to have a state topic where the sensor will send its configuration structure.
And once a message was send in configuration topic HA is supposed to read the data from state topic.

For my case it appears to use the multiple values section. I might be able to re-configure my mqtt messages to match the need of HA.
So I will need a configuration and a state topic for every forecast hour, right? Will be 48 topics for 24h forecast…

But I did not get it how to tell HA to read the sensors. How does HA know it has to read the configuration topic? And how does HA know it has to count (hour++) them?

Is there a step-by-step eample how to use?
Thanks a lot!

/KNEBB

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 103358

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>