Rule not firing?

Hi All

This rule isnt firing, I am seeing no syntax errors and really its just an expansion of something I had that worked

I have a Switch proxy item called ‘Scene_Watch_Vero’

And this rule, which when turning on you see in the logs but you dont see logs for the individual items turning on. Any thoughts?

var Timer fade_timer = null
var Number  percent = 0

rule "Watch a Vero Movie, Dim the Lights and Turn All AV Equipment on"
when
        Item Scene_Watch_Vero changed to ON
then
    var String scene = "Vero Scene"
    //Switch on TV
    if (TVStatus.state == OFF) {
        TV.sendCommand("TVOnOff")
        logInfo(scene, "TV switched On")
    }
    //Switch On AVR
    if (Main_Zone_Power.state == OFF) {
        Main_Zone_Power.sendCommand(ON)
        logInfo(scene, "AVR switched on")
    }
    //Change AVR Scene to Movie
    if ((Zone_1_Scene.state != "Scene 1" || Zone_1_Scene.state != "Scene 2")) {
         Zone_1_Scene.sendCommand("Scene 3")
         logInfo(scene, "AVR Scene set to Vero")
    }
    //Slowly Dim the Lights if they are above 50%
    if (LivingRoomSw1.state == ON) {
        if (fade_timer === null) {
           percent = LivingRoomDim1.state as Number
           fade_timer = createTimer(now.plusMillis(200), [ |
                if (percent > 0) {
                    percent = percent - 5
                    if (percent < 0) percent = 0
                    LivingRoomDim1.sendCommand(percent)
                    fade_timer.reschedule(now.plusMillis(200))
                } else {
                    fade_timer = null
                }
            ])
        }
    }
end


rule "When Kodi PLayer changed to PLAY"
when
        Item myKodi_control changed to PLAY
then
        LivingRoomSw1.sendCommand(OFF)
end



rule "When Kodi Player changed to PAUSE"
when
        Item myKodi_control changed to PAUSE
then
        LivingRoomDim1.sendCommand(5)
end



rule "When Kodi Player changed to STOP"
when
        Item myKodi_control changed to STOP
then
 //Slowly Brighten the Lights at the end of the Movie
    if (LivingRoomSw1.state == OFF) {
        if (fade_timer === null) {
           percent = LivingRoomDim1.state as Number
           fade_timer = createTimer(now.plusMillis(200), [ |
                if (percent = 0) {
                    percent = percent + 20
                    if (percent < 0) percent = 0
                    LivingRoomDim1.sendCommand(percent)
                    fade_timer.reschedule(now.plusMillis(200))
                } else {
                    fade_timer = null
                }
            ])
        }
}

end

If none of the conditionals evaluate to true, the rule won’t log anything. You could place a logInfo statement at the beginning of the rule to definitively show whether it’s executing or not.

1 Like

Hi Mark

Like so? Nothing shows in the log indicating its firing on the conditions

The first condition is true


openhab> smarthome:status TVStatus
OFF
openhab>

var Number percent = 0
var Timer fade_timer = null

rule "Watch a Vero Movie, Dim the Lights and Turn All AV Equipment on"
when
        Item Scene_Watch_Vero changed to ON
then
    logInfo(scene, "scene")
    var String scene = "Vero Scene"
    //Switch on TV
    if (TVStatus.state == OFF) {
        TV.sendCommand("TVOnOff")
        logInfo(scene, "TV switched On")
    }
    //Switch On AVR
    if (Main_Zone_Power.state == OFF) {
        Main_Zone_Power.sendCommand(ON)
        logInfo(scene, "AVR switched on")
    }
    //Change AVR Scene to Movie
    if ((Zone_1_Scene.state != "Scene 1" || Zone_1_Scene.state != "Scene 2")) {
         Zone_1_Scene.sendCommand("Scene 3")
         logInfo(scene, "AVR Scene set to Vero")
    }
    //Slowly Dim the Lights if they are above 50%
    if (LivingRoomSw1.state == ON) {
        if (fade_timer === null) {
           percent = LivingRoomDim1.state as Number
           fade_timer = createTimer(now.plusMillis(200), [ |
                if (percent > 0) {
                    percent = percent - 5
                    if (percent < 0) percent = 0
                    LivingRoomDim1.sendCommand(percent)
                    fade_timer.reschedule(now.plusMillis(200))
                } else {
                    fade_timer = null
                }
            ])
        }
    }
end

Ok, I might’ve missed this the first time.

What is scene used in your logInfo statements? I don’t see it declared as a variable in your rule.

logInfo(scene, "scene")

logInfo expects a string as the first argument. Such as…

logInfo("scene", "scene")

the variable for scene is in the top of the rule Mark :slight_smile:

Yes is it but it is defined AFTER you use it…

Swap the two lines

    var String scene = "Vero Scene"
    logInfo(scene, "scene")

OK, ive made the change. unforuntely nothing is displayed in the log :confused:

Something seems odd. Prior to you making that last change, there should’ve been an error logged when the rule executed (due to the variable scene not being defined in the call to logInfo).

Sorry for missing the definition of scene earlier. Reading skills are so important. :roll_eyes:

You trigger is a changed trigger
Are you sure that the item is changed to ON

1 Like

Im so stupid! Slaps forehead :frowning:
Should havbe been ‘received command’ not changed to

Sorry for wasting your time guys :confused:

Its running through now!

The dimming of the lights correctly functions when you hit play, by dimming them to 0. What doesnt occur is the dimming up to 80%

It should trigger when you STOP a movie.

As seen here:

08:51:08.007 [INFO ] [smarthome.event.ItemStateChangedEvent] - myKodi_stop changed from OFF to ON

rule "When Kodi Player changed to STOP"
when
        Item myKodi_stop changed to ON
then
 //Slowly Brighten the Lights at the end of the Movie
    if (LivingRoomSw1.state == OFF) {
        if (fade_timer === null) {
           percent = LivingRoomDim1.state as Number
           fade_timer = createTimer(now.plusMillis(350), [ |
                if (percent = 0) {
                    percent = percent + 80
                    if (percent < 0) percent = 0
                    LivingRoomDim1.sendCommand(percent)
                    fade_timer.reschedule(now.plusMillis(350))
                } else {
                    fade_timer = null
                }
            ])
        }
   }
end
if (percent == 0) {

!!!

1 Like

Hi Vincent,

Ah! so rather before with the rule that dims them down, this which dims them up needs the = 0

rather than the greater than 0

OK, its working now but instead of dimming them slowly up, its basically just turns them on. Which is odd given the rule to dim them down, using the same logic works just fine. The only difference is that percent = percent + 100, to brighten them to 100.

Current rule:

rule "When Kodi Player changed to STOP"
when
        Item myKodi_stop changed to ON
then
 //Slowly Brighten the Lights at the end of the Movie
    if (LivingRoomSw1.state == OFF && FibaroEye1Lux < 20) {
        if (fade_timer === null) {
           percent = LivingRoomDim1.state as Number
           fade_timer = createTimer(now.plusMillis(350), [ |
                if (percent == 0) {
                    percent = percent + 100
                    if (percent < 0) percent = 0
                    LivingRoomDim1.sendCommand(percent)
                    fade_timer.reschedule(now.plusMillis(450))
                } else {
                    fade_timer = null
                }
            ])
        }
   }
end

percent = percent - 5
If (percent >80)

Not sure i understand the logic here :confused:

Sorry
percent = percent + 5

Hi Vincent thanks.

Will this mean the dimmer will add 5% to each increment up to 100? I made that change, upon stop it switches the lights on and just goes to Dim 5%.

I want it go up to another nominated figure, like 80% (Hence why i had 100 or 80 there originally)

rule "When Kodi Player changed to STOP"
when
        Item myKodi_stop changed to ON
then
 //Slowly Brighten the Lights at the end of the Movie
    if (LivingRoomSw1.state == OFF && FibaroEye1Lux < 20) {
        if (fade_timer === null) {
            percent = LivingRoomDim1.state as Number
            if (percent == 0) {  // if the lights are off
                fade_timer = createTimer(now.plusMillis(350), [ |
                    percent = percent + 5 // increase slowly
                    if (percent <= 80) { // up to 80%
                        LivingRoomDim1.sendCommand(percent)
                        fade_timer.reschedule(now.plusMillis(450))
                    } else {
                        fade_timer = null
                    }
                ])
            }
        }
    }
end

It doesnt like that! If after i corrected esle, to else :smiley:


06:50:41.017 [WARN ] [del.core.internal.ModelRepositoryImpl] - Configuration model 'Scene_Watch_Vero.rules' has errors, therefore ignoring it: [78,21]: extraneous input '}' expecting ']'

Sorry, corrected above

1 Like

Cool, it accepts it but the dim is still 5%, ie just comes on, doesnt brighten :frowning: I’d have thought the logic would be reverse of my working dim down rule. Clearly not !