Im doing my best to work on a Scene rule which basically turns my AV equipment on and dims my lights, if they are on to 0%.
Essentially if the Dimmer is greater than 0, whatever the value, dim by 5% until the dimmer = 0
Ive got about this far
rule "Watch a Netflix movie, Dim the Lights and Turn All AV Equipment on"
when
Item Scene_Watch_Netflix changed to ON
then
//Switch on TV
if (TVStatus.state == OFF) {
sendCommand(TV, ON)
//Switch On AVR
}
else if (Yamaha_Power.state == OFF) {
sendCommand(Yamaha_Power, ON)
//Change AVR Scene to Movie
}
else if ((Zone_1_Scene.state != "Scene 2" || Zone_1_Scene.state != "Scene 3")) {
sendCommand(Zone_1_Scene, 'Scene 1')
//Slowly Dim the Lights if they are above 50%
}
else if (LivingRoomSw1.state == ON && LivingRoomDim1.state < 50) {
sendCommand(LivingRoomDim1, 50)
Thread::sleep(3000)
sendCommand(LivingRoomDim1, 40)
Thread::sleep(3000)
sendCommand(LivingRoomDim1, 30)
Thread::sleep(3000)
sendCommand(LivingRoomDim1, 20)
Thread::sleep(3000)
sendCommand(LivingRoomDim1, 10)
Thread::sleep(3000)
sendCommand(LivingRoomDim1, 0)
//Change Input to Netflix
}
else if (TVStatus.state == ON) {
TV.sendCommand(TVNetflix)
}
end
I believe I see one issue that stares at me. If I am understanding what you are trying to do, I believe your “else if” need to be if.
The reason is this written as language. What you want to say is:
if the tv is off turn it on.
If the receiver is off, turn it on
Etc…
Using else if would do this. I believe you are saying:
If the tv is off turn it on.
Done!
There would be no reason to pass to the else if when the first condition is true. I am hoping this makes sense, and I am giving you the behavior you desire.
Not knowing exactly what yours scenes do, the syntax looks correct, but I can’t comment if you will have the desired output. You may examine the sleeps though they are rather large.
Cool, I suspected that may be the case. I havent tested it as yet, but will tonight. Ill have a read of the sleep article. I couldnt think of a way to slowly dim the lights and have a delay. I might use the Timer method
I saw some posts with better use of the Timers like you’ve suggested so I will try this:
var int percent = 0
var Timer fade_timer = null
rule "Watch a Netflix movie, Dim the Lights and Turn All AV Equipment on"
when
Item Scene_Watch_Netflix changed to ON
then
//Switch on TV
if (TVStatus.state == OFF) {
sendCommand('TV, TVOnOff')
logInfo("TV switched on as a result of Netflix scene")
//Switch On AVR
}
if (Yamaha_Power.state == OFF) {
sendCommand(Yamaha_Power, ON)
logInfo("AVR switched on as a result of Netflix scene")
//Change AVR Scene to Movie
}
if ((Zone_1_Scene.state != "Scene 2" || Zone_1_Scene.state != "Scene 3")) {
sendCommand(Zone_1_Scene, 'Scene 1')
logInfo("AVR Scene set to Netflix as a result of Netflix scene being pressed")
//Slowly Dim the Lights if they are above 50%
}
if (LivingRoomSw1.state == ON) {
if (fade_timer !== null) {
percent = LivingRoomDim1.state
fade_timer = createTimer(now.plusMillis(500)) [ |
LivingRoomDim1.sendCommand(percent)
if (percent > 0) {
percent = percent - 5
fade_timer.reschedule(now.plusMillis(500))
}
]
}
}
//Change Input to Netflix
if (TVStatus.state == ON) {
TV.sendCommand(TVNetflix)
logInfo("Input on TV changed to Netflix")
}
end
Tried to test the rule but the log shows this. @vzorglub any thoughts rule guru?
14:17:36.852 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Watch a Netflix movie, Dim the Lights and Turn All AV Equipment on': An error occurred during the script execution: index=1, size=1
var Number percent = 0
var Timer fade_timer = null
rule "Watch a Netflix movie, Dim the Lights and Turn All AV Equipment on"
when
Item Scene_Watch_Netflix changed to ON
then
var String scene = "Netflix scene"
//Switch on TV
if (TVStatus.state == OFF) {
TV.sendCommand("TVOnOff")
logInfo(scene, "TV switched on")
}
//Switch On AVR
if (Yamaha_Power.state == OFF) {
Yamaha_Power.sendCommand(ON)
logInfo(scene, "AVR switched on")
}
//Change AVR Scene to Movie
if ((Zone_1_Scene.state != "Scene 2" || Zone_1_Scene.state != "Scene 3")) {
Zone_1_Scene.sendCommand("Scene 1")
logInfo(scene, "AVR Scene set to Netflix")
}
//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(500), [ |
if (percent > 0) {
percent = percent - 5
LivingRoomDim1.sendCommand(percent)
fade_timer.reschedule(now.plusMillis(500))
} else {
fade_timer = null
}
])
}
}
//Change Input to Netflix
if (TVStatus.state == ON) {
TV.sendCommand("TVNetflix")
logInfo(scene, "Input on TV changed to Netflix")
}
end
18:46:18.020 [WARN ] [arthome.model.script.actions.BusEvent] - Cannot convert '-1' to a command type which item 'LivingRoomDim1' accepts: [PercentType, OnOffType, IncreaseDecreaseType, RefreshType].
The diming works, but doesnt switch off when it gets to 0.
I can only assume the TVStatus is not being updated to ON fast enough during execution, which means its not changing the Input to Netflix. Even after I tweaked the Network Binding to be very fast!
It appears the TVStatus isnt updating fast enough, after it comes online. Soon as you switch it on, its pingable but the TVStatus shows OFF for ages…