Closed sauntry closed 11 months ago
Thanks, if you want to submit a PR I'll take a look.
If a greater structure needs to be published how to ignore the whole structure? For example: I'm using CumulusMX to send the weather data to Home Assistant. If for example you only send key/value pairs then everything goes fine. But what if I want to use the auto discovery functionality of Home Assistant. See https://www.home-assistant.io/integrations/mqtt/ The auto discovery function automatically creates the sensors in HA. If you don't use the auto discovery you have to create extra yaml code to create all the sensors.
To automatically import the mqtt values in HA you need a mqtt file in CumulusMX like this one:
{"topics":
[
{
"topic": "homeassistant/sensor/cumulusmx/temp/config",
"retain": "true",
"data": " {
"name": "CumulusMX Temperature",
"state_topic": "homeassistant/sensor/cumulusmx/interval/state",
"value_template": "{{ value_json.temp }}"
}
},
{
"topic": "homeassistant/sensor/cumulusmx/hum/config",
"retain": "true",
"data": " {
"name": "CumulusMX Humidity",
"state_topic": "homeassistant/sensor/cumulusmx/interval/state"
"value_template": "{{ value_json.hum }}"
}
},
{
"topic": "homeassistant/sensor/cumulusmx/interval/state",
"retain": "false",
"data": " {
"temp": "<#temp>",
"hum": "<#hum>"
}"
}
]
}
The best would be to send the first two complete topics only once (because they don't ever change). From the third topic send only the key/value pairs which have changed. Is that possible with the suggested change?
Here's my 2 cents, since I opened this issue... I don't use Home Assistant, so perhaps I'm not completely understanding the issues you raise. The first seems to be concerning CumulusMX integration with HA through mqtt. That's perhaps best for another issue/request. This issue is concerning what triggers the update for individual topics for an Update.
I believe the second issue - only send the key/.value pairs that have changed - can already be addressed by having separate topics for each of the keys. You would have to account for that in each of the config topics (ie, by having state/temp and state/hum), and then a topic for each of those, along with my PR.
I understand the second issue could be addressed by dividing each key/value pair in a separate topic. In the first issue there are two topics which do not contain any CumulusMX web tags. Will those topics be send once or every time?
My guess is that, with my PR, if you include a blank doNotTriggerOnTags (ie, "doNotTriggerOnTags": "") in each of those config topics, it will be sent once each time CumulusMX is started. You are welcome to grab the PR and give it a go.
Implemented in v3.26.0
I recently started using the mqtt dataupdate feature, and I was surprised when the topic was being published every few seconds. After looking at the code, the mqtt topics are published whenever the station updates, and not when the actual tags used in any particular topic has changed.
Request: only publish a topic when the contents change (not including any time/date webtag).
Bonus: I have this implemented and ready to submit a PR if you want this change.