bellrichm / WeeWX-MQTTSubscribe

A WeeWX service and driver that receives data from MQTT.
GNU General Public License v3.0
52 stars 13 forks source link

contains_total not working #110

Closed jmceara closed 3 years ago

jmceara commented 3 years ago

Hi! It's my first time trying this driver and it's almost working, except for rain observation.

My rain sensor (coming from rtl_433) is reporting an topic called 'rain_mm' and it's cumulative. I mean, it doesn't reset, just increase as rain. For my weewx configuration, I've setup this:

 # The topics to subscribe to.
    [[topics]]
        unit_system = METRIC
        use_topic_as_fieldname = true
        use_server_datetime = True
        [[[rtl_433/devices/Fineoffset-WHx080/temperature_C]]]
            name = outTemp
        [[[rtl_433/devices/Fineoffset-WHx080/humidity]]]
            name = outHumidity
        [[[rtl_433/devices/Fineoffset-WHx080/rain_mm]]]
            name = rain
            contains_total = True

The problem is that this is not working. My sensor is reporting 8.1 to MQTT broker, but weewx is showing 55mm/h! And keeps increasing if I left like this. Note that my database is fresh-new (New install, I'm deleting/recreating database during tests), so it's not old data. Also my Weewx is set to correct units (METRIC).

bellrichm commented 3 years ago

Take a look at http://weewx.com/docs/customizing.htm#units It sounds like you might have a mix of ‘METRIC’ and ‘METRICWX’ data reporting. Let’s leave the unit_system as ‘METRIC’, but override the units of the rain field to mm by setting ‘units = mm’ in the rain_mm section. This will convert the rain from mm to cm and all the data will now be in the correct units for the METRIC unit_system.

        [[[rtl_433/devices/Fineoffset-WHx080/rain_mm]]]
            name = rain
            contains_total = True
            units = mm

While we are debugging, I am going to focus on getting the rain value correct. This is what MQTTSubscribe ‘controls’. If we get that correct, WeeWX will ‘magically’ compute the rainRate.

bellrichm commented 3 years ago

I thought you also had wind data, which is I said to add the units = mm. But if all you have is the temperature and rain, you could change the unit_system to METRICWX. Your call rich

jmceara commented 3 years ago

I've set individual topic unit and it's working. Sorry for this 'wrong issue report'. Is there any other place to ask questions about this plugin? I would like to know if is possible to use two different callback types for the same configuration. In my MQTT broker, I have some sensors as individual topics and another ones in json format. If possible to use both? As I understood, message_callback configuration is global, I mean, for all topics in weewx configuration, right?

bellrichm commented 3 years ago

No worries about opening this issue. You are correct, as of now the type is global. I’ve thought about supporting multiples, but no one had asked for it. Feel free to open another issue asking for this feature. In the meantime, although not ideal, you should be able to get around it by running MQTTSubscribe as both a driver and a service. For questions, suggestions, etc., feel free to open an issue, start a discussion in github, or post on WeeWX google group. I monitor them all. rich

agrieco commented 3 years ago

Forgive the hopping on a closed issue- but I'm having a related/same problem:

Here is my config:

    [[topics]]
        # Units for MQTT payloads without unit value.
        # Valid values: US, METRIC, METRICWX
        # Default is: US
        unit_system = US

        [[[weather/3149/humidity]]]
            name = outHumidity
        [[[weather/3149/temperature_F]]]
            name = outTemp
        [[[weather/3149/wind_avg_mi_h]]]
            name = windSpeed
        [[[weather/3319/rain_mm]]]
                name = rain
                contains_total = True
                units = mm

And here is the logs that are coming in. The rain value never goes off of 0.0

Jan 31 15:27:54 weather rtl_433[324]: {"time" : "2021-01-31 15:27:54", "model" : "Acurite-Rain899", "id" : 3319, "channel" : 0, "battery_ok" : 0, "rain_mm" : 75.946, "mic" : "CHECKSUM"}
Jan 31 15:27:55 weather weewx[1485] DEBUG user.MQTTSubscribe: (Driver) MessageCallbackProvider data-> incoming topic: weather/3319/rain_mm, QOS: 0, retain: 0, payload: 75.946
Jan 31 15:27:55 weather weewx[1485] DEBUG user.MQTTSubscribe: (Driver) TopicManager data-> incoming weather/3319/rain_mm: rain: 0.0

Can someone help me understand what I'm doing wrong?

bellrichm commented 3 years ago

@agrieco, 2 log lines is not much to go on. I’m guessing you have a payload of type ‘individual’. If so, you need the option use_topic_as_fieldname. So something like

    [[topics]]
        # Units for MQTT payloads without unit value.
        # Valid values: US, METRIC, METRICWX
        # Default is: US
        unit_system = US
        use_topic_as_fieldname = True

        [[[weather/3149/humidity]]]
            name = outHumidity
        [[[weather/3149/temperature_F]]]
            name = outTemp
        [[[weather/3149/wind_avg_mi_h]]]
            name = windSpeed
        [[[weather/3319/rain_mm]]]
                name = rain
                contains_total = True
                units = mm

If that doesn’t work, let’s open another issue. I’ll need to see the log from startup through a few loops while it is raining and with debug = 1.

agrieco commented 3 years ago

@agrieco, 2 log lines is not much to go on. I’m guessing you have a payload of type ‘individual’. If so, you need the option use_topic_as_fieldname. So something like

    [[topics]]
        # Units for MQTT payloads without unit value.
        # Valid values: US, METRIC, METRICWX
        # Default is: US
        unit_system = US
        use_topic_as_fieldname = True

        [[[weather/3149/humidity]]]
            name = outHumidity
        [[[weather/3149/temperature_F]]]
            name = outTemp
        [[[weather/3149/wind_avg_mi_h]]]
            name = windSpeed
        [[[weather/3319/rain_mm]]]
                name = rain
                contains_total = True
                units = mm

If that doesn’t work, let’s open another issue. I’ll need to see the log from startup through a few loops while it is raining and with debug = 1.

Thanks for the prompt response. with this change, I was able to get values mapped, but how they were being mapped (rates vs total) was still off. I'm investigating to figure that out further. Will open a new issue if I get stuck. THANK YOU