Google Home speaker broadcast

Hi everyone,
i 've created a rule to broadcast to my google home mini a message, when the pellet level is low in my boiler. The rule is below.

rule "Pellet Level Low TTS"
when
  Item Pellet_Level changed to 75
then
if ((hour >= 8)  || (hour <= 22)) { say("pellet level low", "voicerss:enUS", "chromecast:chromecast:c6443168cc4e99efe89a0ff0de161587")   
end

How i can set this up to broadcast the message only 3 times and then stop?
Thank you in advance

Are you sure the rule is working as intended?
Where does hour get its value?
I would expect the rule only to trigger once, as the Level would either rise from 74 to 75 and then from 75 to 76 or the level would fall from 76 to 75 and then from 75 to 74. If the Item value changes multiple times to 75 (e.g. because of measuring inaccuracy) maybe you should create a hysteresis.
Further create a counter and a timer to send the say command only between 8:00 and 22:00 and only 3 times:

var Boolean bPelletLow = false                         // signal for low level
var Timer tPelletAlert = null                          // timer for low level
var Number nCount = 0                                  // counter for low level

rule "set level low"
when
    Item Pellet_Level changed  
then
    if(bPelletLow) {                                   // already low
        if((Pellet_Level.state as Number) > 80) {      // received pellets
            bPelletLow = false
            tPelletAlert?.cancel
            nCount = 0
        }
    } else {                                           // not low
        if((Pellet_Level.state as Number) < 75) {      // and pellets low
            bPelletLow = true
            tPelletAlert?.cancel
            nCount = 0
            tPelletAlert = createTimer(now, [|         // create a timer
                if(now.getHourOfDay < 8)               // too early, reschedule later
                    tPelletAlert.reschedule(now.withTimeAtStartOfDay.plusHours(8))
                else if(now.getHourOfDay > 21)         // too late, reschedule tomorrow
                    tPelletAlert.reschedule(now.withTimeAtStartOfDay.plusHours(32))
                else {                                 // correct time...
                    say("pellet level low", "voicerss:enUS", "chromecast:chromecast:c6443168cc4e99efe89a0ff0de161587")
                    if(nCount < 2) {                   // how many times?
                        nCount += 1                    // count up and reschedule
                        tPelletAlert.reschedule(now.plusMinutes(60))
                    }
                }
            ])
        }
    }
end
1 Like