Simple rule doesnt work

Hello all,
I would like to send a broadcast information if the range of my Zoe is going below a certain limit.
I would like to get this message just once and not all the time I used a boolean. Following you’ll see the rule.

var boolean MessageB = false

rule "RenaultZEService_Zoe_send_broadcast_if_under_certain_limit"
when
	Time cron "0 0/10 * * * ?" or 
	System started
    	
then
     if ((RenaultZEServices_Zoe_RemainingRange.state <= 100) && (!MessageB) ){             
        
        sendBroadcastNotification("Achtung! Restreichweite: " + RenaultZEServices_Zoe_RemainingRange.state +"km Ladestatus: " + RenaultZEServices_Zoe_ChargeLevel.state + "%"  )
        MessageB = true
        logInfo("RemainingRange", "Remaining Range: " + MessageB)
        
     } else (RenaultZEServices_Zoe_RemainingRange.state >= 100 && MessageB==true){
        MessageB = false

     }

Currently the range is below 100. I am receiving all 10 min the message, but this should not happen. I dont know why and where my mistake is.
Thanks in advance

Have you tried the same notation as in the else (missing if when using your condition?!? - else if (condition) or just else without condition), i.e. without the extra brakets and using a direct compare for the MessageB as well?

if (RenaultZEServices_Zoe_RemainingRange.state <= 100 && MessageB==false) {

Deleted, missread the code

yes, tried, but I am entering all the time in the if case.

Now I simply did the same with a Number. It works fine now, but I am still curious where my mistake was…

I’m using very similar boolean variables in my rules files and they work fine, but a quick search on here showed this:

Possibly the case for your issue?!?

Might be a reason. will try.

Thanks anyway

Is it remaining above 100? Is it possible that it’s flapping between over and under? Look at your events.log and/or add some logging so you see when the else is running.

1 Like

I used a number as a counter and that worked fine for me.

This is not formatted properly… use ‘else if’.

     } else if (RenaultZEServices_Zoe_RemainingRange.state >= 100 && MessageB == true) {
2 Likes

What shall I say: Not to see the wood for the trees…
Thanks @5iver now its fixed

1 Like

As already stated above in my first post

too many trees :wink: