Reasonableness constraints

You can use a profile written in jruby (which works on openhab 3.4) or wait for openhab 4. The state of this in openhab4 is still up in the air. Currently there’s SCRIPT profile that can let you do this (not sure if it’s in M1 but for sure it’s in SNAPSHOT), but if my PR is accepted, this will go away and be replaced with a language-specific profile, i.e. JS, RB, DSL, etc. in its place.

Example with a jruby profile:

Your item definition:

Number:Temperature My_Temp_Sensor { channel="xxxxxxx" [profile="ruby:discard_anomalies" max=300] }

automation/ruby/profiles/my_profile_to_discard_bad_values.rb (you can name this file anything, of course - as long as it has a .rb extension, and reside somewhere inside automation/ruby/)

profile(:discard_anomalies) do |event, state:, configuration:|
  next true if state && state.to_f < configuration["max"] # Assuming you're getting a raw numeric value in an implicit unit of °F

  false # discard it
end

If the binding sends the state as QuantityType

Number:Temperature My_Temp_Sensor { channel="xxxxxxx" [profile="ruby:discard_anomalies" max="300 °F"] }

you could change the condition to:

profile(:discard_anomalies) do |event, state:, configuration:|
  next true if state && state < QuantityType.new(configuration["max"])

  false # discard it
end
1 Like