Is it possible to log a warning when the condition is not met? I have a temperature sensor that starts sending bogus values when the battery is getting low (even though the battery channel doesn’t indicate the battery has dropped much), so I want to filter out the bad values, but also warn me so I know to go replace the battery. Thanks
Possible, sure, but that may not be what everyone wants, so it would need to be configurable, which adds to the complexity.
A much better way is to create a separate item that filters out the correct range, so when that item gets updated, you know it’s getting the wrong data, and you can simply create a rule on item update to send you an alert.
Yes, that’s what I do today - was just wondering if I could simplify to reduce items and use this add-on. Maybe not.
@binderth I’ve just added filtering on delta percentage
The State Filter Profile fails for me when the Quantity Type is dBm.
This is the error message:
2024-12-28 16:25:11.035 [WARN ] [transport.mqtt.internal.Subscription] - A subscriber of type 'class org.openhab.binding.mqtt.generic.ChannelState' failed to process message '7B2274656D7065726174757265223A352E382C2268756D6964697479223A39322C2262617474657279223A38312C2272737369223A2D38337D' to topic 'shelly_blegateway/ec355f38dafe/sensor'.
There is a sensor which sends a JSON message to MQTT connected to openHAB by a Generic MQTT Thing.
The channel is configured like this:
- id: rssi3
channelTypeUID: mqtt:number
label: rssi3
configuration:
stateTopic: shelly_blegateway/ec355f38dafe/sensor
transformationPattern:
- JSONPATH:$.rssi
unit: dBm
and the item is a Number:Power with unit dBm
The JSON message is:
{"temperature":15.2,"humidity":64,"rssi":-42}
I have tried several conditions in the profile configuration e.g
$DELTA_PERCENT > 10
$DELTA > 5 dBm
> 10%
but all fail with the same error.
I have also tried setting the rssi to a positive value.
Please post the item definition so I can try to reproduce it
You’re on openhab 4.3?
Did you try without a profile?
The item is defined in the UI. I don’t know how to get a textual definition, but karaf says this:
OutdoorSensor3_rssi (Type=NumberItem, State=-91 dBm, Label=OutdoorSensor3_rssi, Category=network, Tags=[Power, Measurement], Groups=[SwitchBot_Outdoor_Meter3])
Yes I’m on 4.3
With the default profile it works OK
I have other Things/channels for which the state profile is working e.g. Number:Temperature, Number:Dimensionless
I can reproduce this issue. It seems to happen with dBm unit, but not others, e.g. “W”. Investigating!
OK, the reason it doesn’t work, is because the profile tries to perform previous_value - new_value calculation, and in this case it tries to do, e.g. 10 dBm - 5 dBm and the result is not in the same unit. In fact, this caused an error. See https://ham.stackexchange.com/questions/17591/adding-and-subtracting-db-dbm-dbi-values
The solution is to not assign a unit in the Thing / channel, and only assign the unit on the item. This also means that your profile filter will be unit-less, so you can do > 10% or $DELTA > 10.
Thanks for the explanation.
I removed the unit from the Thing, and the error went away, but the filter does not pass anything if the value is set to a negative value.
Setting the profile back to default, and set the item to positive (via MQTT), then set the profile back to State Filter, all works as expected.
But after setting the item to negative, no more changes are accepted.
Even setting $DELTA_PERCENT > 1 does not work.
This is a bug in the profile when using delta percent. Thanks for finding it! I’ll post a fix shortly.
@DavidR could you please test this:
- Uninstall the built-in Basicprofile transformation addon
- Rename this file by removing the extra
.txtextension - Drop it in your conf/addons folder (pick the one that matches your OH version 4.3.x / 5.x)
org.openhab.transform.basicprofiles-5.0.0-SNAPSHOT.jar.txt (61.0 KB)
org.openhab.transform.basicprofiles-4.3.1-SNAPSHOT.jar.txt (60.9 KB)
Yes this works. Thank you.
I’m on openHAB 4.3.0 - Release Build, so used the 4.3.1 jar
And using openHABian build on RPI so my addons folder is /usr/share/openhab/addons
@DavidR the fix for negative input will be included in 4.3.2
I’ve just come to realise that the DELTA_PERCENT will hit a division-by-zero error when it encounters an input that’s zero.
So when the input is zero, the delta percent for the next input will be calculated as (X - 0) * 100 / 0. I’m not quite sure how to deal with this. If we reject the next input, then it will always get stuck at zero.
On the other hand, we could reject Zero itself as a valid input when a Delta percent calculation is involved. If there are no objections to this, I’ll implement it.
Hi @jimtng :
I have upgraded 4.3 and start to use the basic profile for filtering invalid values.
For temperature it works great, however I couldn’t seem to get humidity to work:
Number:Temperature ToolshedTemperature "Toolshed Temperature [%.1f %unit%]" (gToolshedWeatherSensor) {channel="miio:lumi:xxxxxxxx:temperature"[profile="basic-profiles:state-filter", conditions="> -30 °C", "< 50 °C"], unit="°C"}
Number:Dimensionless ToolshedHumidity "Toolshed Humidity [%.1f %unit%]" (gToolshedWeatherSensor) {channel="miio:lumi:xxxxxxxx:humidity"[profile="basic-profiles:state-filter", conditions="> 0 %", "< 100 %"], unit="%"}
I suspect something to do with the item type Number:Dimensionless, do you have a hint how to make it work for humidity as well?
Many thanks!
> 10 % is a special syntax for percentage delta filtering. Try removing the percent sign
@somy
EDIT:
It seems that this is a bug. I failed to anticipate that it would clash with QuantityType with percent as unit.
Please try the following:
-
Uninstall basicprofiles addon
-
Download and rename this file to remove its
.txtextensionorg.openhab.transform.basicprofiles-4.3.2-SNAPSHOT.jar.txt (61.0 KB)
-
Drop it in your
/addonsfolder -
Change your filter conditions to the following:
conditions="$INPUT > 0 %", "$INPUT < 100 %" -
No need to change the conditions in the other item that already worked
Please let me know if this solved the problem.