Issue with AVG group item

  • Platform information:
    • Hardware: RPi 3 B+
    • openHAB version: 2.5.12

I am using the AVG function to calculate the average of all my items (relative humidity). The AVG function ignores NULL state items. However, recently I realized that when one of my sensors went down, it was showing “nan” on ESPEASY web interface, but openhab (OH2.5.12) showed the last valid sensor reading on sitemap and the item state was stuck to that value (so it was not NULL), even though it had not updated for over 12 hours. Subsequently, this completely threw off the Average value of all the group items. I haven’t found a work around this yet. Any suggestions, tips or insight would be appreciated.

Item file (multiple sensors, so multiple items, but only showing one below):

Group F2_rh_group    //group for all RH sensors
Group:Number:AVG hu_average_g_item "hu_average_g_item [%.1f]" //this group item will calculate the avg values from its member items

Number f2_htc_112_rh "f2_htc_112_rh" (F2_rh_group, hu_average_g_item) {channel="mqtt:topic:MQTTBroker:F2_HTC_112:f2_htc_112_rh"}

Sitemap file:

Frame label="RH" 
Text item=hu_average_g_item label="hu_average_g_item"

Assuming the Item is updated periodically you can use Expire to cause the Item to revert to NULL or UNDEF when it hasn’t received an update after a set amount of time. Expire is part of core in OH 3. You’ll have to install the Expire binding in 2.5.

1 Like

MQTT binding can listen for LWT messages that your remote device has left with the broker. The broker will send those if the device dies.

Expire Binding worked flawlessly (OH2.5). Thank you Rich!

Actually the device itself stays powered ON (nodeMCU). But for some reason the SHT31 reading goes “nan” for relative humidity and temperature. Most of the time it comes back up after a power cycle. Only a few times I have had to replace the SHT31.

Thank you for pointing me towards LWT though. Haven’t used it before but I think I can use it as a solution for another problem, in case the device itself goes offline. Thank you so much!