bachya / ecowitt2mqtt

Send data from Fine Offset weather stations (Ecowitt, Ambient Weather, Froggit, etc.) to MQTT!
MIT License
210 stars 44 forks source link

Publish data as structured mqtt topic #1053

Closed mti-sk closed 1 month ago

mti-sk commented 1 month ago

Hello, I would like to request the possibility to publish data in MQTT in a structure. The project now publishes all parameters in one Topic, I would call it flat. Topic directly contains parameters. This way of storing data creates problems for post-processing, for example in the OpenHAB project. I have not yet figured out how to extract individual parameters. OpenHAB makes easier use of the mqtt topic structure. I would suggest adding a new parameter something like mqtt_struct <= ( flat | tree) flat - default, current functionality (all values ​​in one topic) tree or struct - new functionality of publishing data into a structure (each data as a separate structured mqtt topic) Now I will explain the processing from OpenHAB's point of view: I have a structure:

mqtt ----------> living_room -------------------------------> thermometer -------------------------------------------------- ----> temp =24 -------------------------------------------------- ----> humidity=60 If I want to pass the temperature, I use the mqqt path in OpenHAB: mqtt/living_room/thermometer/temp. This topic will directly return a single value of 24°C. But this is not possible with ecowitt2mqtt, because the project only publishes one topic with all the data. Topic ecowitt2mqtt returns JSON {"runtime": 1007.0, "baromabs": 1005, "temp": 25.38} The only way to process the data is to parse it using JSONPATH, but as I already wrote, in OpenHAB so far without success (for me). For OpenHAB, this structure would be more suitable: ecowitt2mqtt ----------------------->runtime=1007.0 ------------------------>baromabs=1005 ----------------------->temp=1005

Best regards

MQTT_Explorer example obrazek

endreszabo commented 1 month ago

I have a script that does exactly that. It takes a json and distributes its data in the way you described.

as per the KISS principle you should be using my script.

-- Endre

On July 30, 2024 09:47:34 mti-sk @.***> wrote:

Hello, I would like to request the possibility to publish data in MQTT in a structure. The project now publishes all parameters in one Topic, I would call it flat. Topic directly contains parameters. This way of storing data creates problems for post-processing, for example in the OpenHAB project. I have not yet figured out how to extract individual parameters. OpenHAB makes easier use of the mqtt topic structure. I would suggest adding a new parameter something like mqtt_struct <= ( flat | tree) flat - default, current functionality (all values ​​in one topic) tree or struct - new functionality of publishing data into a structure (each data as a separate structured mqtt topic) Now I will explain the processing from OpenHAB's point of view: I have a structure:

mqtt ----------> living_room -------------------------------> thermometer -------------------------------------------------- ----> temp =24 -------------------------------------------------- ----> humidity=60 If I want to pass the temperature, I use the mqqt path in OpenHAB: mqtt/living_room/thermometer/temp. This topic will directly return a single value of 24°C. But this is not possible with ecowitt2mqtt, because the project only publishes one topic with all the data. Topic ecowitt2mqtt returns JSON {"runtime": 1007.0, "baromabs": 1005, "temp": 25.38} The only way to process the data is to parse it using JSONPATH, but as I already wrote, in OpenHAB so far without success (for me). For OpenHAB, this structure would be more suitable: ecowitt2mqtt ----------------------->runtime=1007.0 ------------------------>baromabs=1005 ----------------------->temp=1005

Best regards

MQTT_Explorer example obrazek

-- Reply to this email directly or view it on GitHub: https://github.com/bachya/ecowitt2mqtt/issues/1053 You are receiving this because you are subscribed to this thread.

Message ID: @.***>

bachya commented 1 month ago

I agree with @endreszabo's overall philosophy: I don't think this library should be responsible for a generic DSL that outputs arbitrary data structures.

ecowitt2mqtt was designed around the concept of separate "publishers" being responsible for outputting gateway data in an appropriate single format: TopicPublisher outputs the gateway data directly to the broker, HomeAssistantDiscoveryPublisher outputs the gateway data according to the Home Assistant MQTT Discovery spec, etc. Therefore, I think a more appropriate approach would be to create a new publisher that outputs gateway data according to the openHAB spec.

mti-sk commented 1 month ago

Ok