In my installation when I receive signal from flood sensor I will activate blinging led.
Because I have many sensors I have several similar sections:
rule "FloodAlarm_BathroomLower_Activated"
when
Item FloodSensorLazienkaDolna changed from OFF to ON or
Item FloodSensorLazienkaDolna changed from NULL to ON
then
<activate blinking led>
floodAlarmIsActivated = true
...
end
// FloodAlarm activation BathroomUpper (edge activated)
rule "FloodAlarm_BathroomUpper_Activated"
when
Item FloodSensorLazienkaGorna changed from OFF to ON or
Item FloodSensorLazienkaGorna changed from NULL to ON
then
<activate blinking led>
floodAlarmIsActivated = true
...
end
âŠ
Iâve found script that implement blinking behaviour
but I do not add the same code for each sensor - I would have one place where I put âblinking logicâ script, I do not want to put such part in each rule:
Thank you.
I also found out that I can use time based trigger that start every second and inside that triger check if variable floodAlarmIsActivated is set to true and then on or off LED. I know that cron is limited to second but in this example it is not a problem. I think it should work.
rule "Apagado de alarma automĂĄtica"
when
Item Detector_Gas changed to OFF
then
Alarma.sendCommand(OFF)
if(TimerH != null) {
TimerH.cancel
TimerH = null
}
end
is it really a âgoodâ idea to run a rule every other second?
By toggling this virtual item it basically spams my logs which also doesnât really look healthy
2021-01-22 18:26:18.989 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Blinker' changed from ON to OFF
2021-01-22 18:26:19.001 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'Blinker' received command ON
2021-01-22 18:26:19.006 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Blinker' changed from OFF to ON
2021-01-22 18:26:19.500 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'Blinker' received command OFF
2021-01-22 18:26:19.505 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Blinker' changed from ON to OFF#
````
Any ideas?
Well, in general itâs not really âbadâ. But itâs not great. We should endeavor to avoid writing rules that do nothing most of the time. This is also sometimes called polling. Itâs much better to instead react to events and only do work when necessary instead of always doing something even when you donât need to. The code tends to be simpler to understand and maintain and you avoid being wasteful with resources.
However, is it really bad to do this? No, not really. Youâll be spamming the logs, sure and that can add up to wearing out an SD card a little faster. And youâll be using probably a barely measurable more amount of energy per day. But those are not really that bad of a problem.
So what is someone to do? You have a number of options actually. A couple are:
Create another Switch Item to enable the Blinker. Add a Condition to the rule so it only runs when that Switch is ON.
the intent was to have a blinker item that I can use with a logic and to make icons blink on the UI (for example an alarm) without using much logic - instead I would have just used a logical and with the blink to let my icon toggle visibility.
but yes I could somehow write a rule that makes sure the âblinkerâ will only start when any alarm item goes on and then using the approach you have provided.
Thanks for sharing your thoughts - always appreciated!