Simple event Limit rule

A simple event limit question, that I am assuming I’ve missed something very obvious.

Background (skip if TL;DR)
I’ve built an ESP32, with a 16x2 screen and 2 DHT11 humidity/temperature sensors. They are to monitor the environment I store my 3D printing filament in. The ESP32 communicates back to OH via MQTT. This all works well and I receive regular updates to the OH console.

The problem
When the humidity exceeds a nominated threshold, I want OH to notify me via email. The problem I have is that it continues to email me each time the humidity value changes. I want to limit the notifications to once per day.

I’ve changed my approach to match the design pattern here: Design Pattern: Event Limit and continue to experience the problem so I think it is something in the nested ‘IF’ statements I’ve put together.

Extract from .items file:

Number      Filament1_Humid             "humidity [%.1f%%]"                             {mqtt="<[mqttbroker:home/office/filament1humid:state:default]"}

Rules:

var boolean humidityalerted = false

rule "High Humidity for Filament 1" 
    when Item Filament1_Humid received update
    then
    if (Filament1_Humid.state as DecimalType > 70){
            if (!humidityalerted){ sendMail("<email address>", "Filament Humidity Alert", "Filament #1 Humidity now exceeds 60%") 
            humidityalerted = true
            }
    }
end

rule "Reset Filament alert" when Time Midnight then humidityalerted = false end

Any suggestions?

TIA.

Try that:
I have:

  • Tidied up a bit
  • Changed the variables names to convention
  • Changed the trigger of the first rule to ensure the state has changed before pooling the value
  • Added a val humidityTrigger so that can be changed easily at the top of the rule file and reused in other rules
  • Converted the state to a Number val in the first line of the rule
var boolean humidityAlerted = false
val Number humidityTrigger = 70

rule "High Humidity for Filament 1" 
when
    Item Filament1_Humid changed
then
    val humidity = Filament1_Humid.state as Number
    if (humidity > humidityTrigger) {
        if (!humidityAlerted) {
            sendMail("<email address>", "Filament Humidity Alert", "Filament #1 Humidity now exceeds " + humidityTrigger.toString + "%")
            humidityAlerted = true
        }
    }
end

rule "Reset Filament alert"
when
    Time Midnight
then
    humidityAlerted = false
end

Thanks so much! I will update and try it out.