Hi @divinebovine here is my script in its completeness - it is still running off the old xbmc binding am planning to move it over now we have pause and stop identifiable. Not sure if the includes are needed wither any more:
import org.eclipse.smarthome.core.library.types.DecimalType
import org.eclipse.smarthome.core.library.types.HSBType
import org.eclipse.smarthome.core.library.types.PercentType
import org.joda.time.DateTime
var DateTime time_play_started
rule "Lights off when Play Starts"
when
Item kodi_player_state changed
then
logInfo("RULES", "Kodi State in lowercase is: " + kodi_player_state.state.toString())
logInfo("RULES", "kodi player type is: " + kodi_player_type.state.toString())
var String Kodistate = kodi_player_state.state.toString()
if(Sunset_Event.state == ON && kodi_no_smart_lights.state == OFF) {
logInfo("RULES", "its after sunset")
logInfo("RULES", "kodi state: " + Kodistate.toLowerCase)
if (Kodistate.toLowerCase == "stop") {
logInfo("RULES", "we have stopped")
//reset the proxy switch as we have stopped not paused
kodi_is_playing.sendCommand(OFF)
//look into historicstate for all the light values when the first play started
var Number Lounge1_DimmerState = Lounge_3_Dimmer.historicState(time_play_started).state
var Number Lounge2_DimmerState = Lounge_6_Dimmer.historicState(time_play_started).state
var Number Kitchen1_DimmerState = Kitchen1_Dimmer.historicState(time_play_started).state
var Number Kitchen2_DimmerState = Kitchen2_Dimmer.historicState(time_play_started).state
var HSBType LIFX_LoungeState = Lifx_Lounge.historicState(time_play_started).state
logInfo("RULES", "historic state done")
//turn on all the lights back to the value they were when play started
if(Lounge1_DimmerState > 0) {
Lounge_3_Dimmer.sendCommand(Lounge1_DimmerState)
}
if(Lounge2_DimmerState > 0) {
Lounge_6_Dimmer.sendCommand(Lounge2_DimmerState)
}
if(Kitchen1_DimmerState > 0) {
Kitchen1_Dimmer.sendCommand(Kitchen1_DimmerState)
}
if(Kitchen2_DimmerState > 0) {
Kitchen2_Dimmer.sendCommand(Kitchen2_DimmerState)
}
//LIFX bulbs
Lifx_Lounge.sendCommand(LIFX_LoungeState)
logInfo("RULES", "kodi is stopped so lights should be on as they were")
logInfo("RULES", "kodi is playing:" + kodi_is_playing.state.toString())
}
//sleep loop until player type is updated (without this there are null errors)
while(kodi_player_type.state.toString == "") {
Thread::sleep(500)
}
//check for TV, Movies, or other such as youtube, TenPlay ABC Iview etc)
var String KodiPlayerState = kodi_player_type.state.toString()
if(KodiPlayerState.toLowerCase == "episode" || KodiPlayerState.toLowerCase == "movie" || KodiPlayerState.toLowerCase == "unknown") {
logInfo("RULES", "Kodi State: " + Kodistate)
logInfo("RULES", "Kodi is playing: " + kodi_is_playing.state.toString())
switch (Kodistate.toLowerCase) {
case "play" : {
//check if this is the first time play pressed with a proxy switch
if (kodi_is_playing.state == OFF) {
//record the time to use in historicState
time_play_started = now
//set the proxy switch as this is the first time
kodi_is_playing.sendCommand(ON)
logInfo("RULES", "kodi is playing set to on so this is the first time")
}
//turn off all the desired lights
//Lounge_Lamp_Dimmer.sendCommand(OFF)
Lounge_3_Dimmer.sendCommand(OFF)
Lounge_6_Dimmer.sendCommand(OFF)
Kitchen1_Dimmer.sendCommand(OFF)
Kitchen2_Dimmer.sendCommand(OFF)
//dim LIFX based on scene
var hue = new DecimalType(242.9993133544921875)
var sat = new PercentType(100)
var bri = new PercentType(23)
var HSBType kodiplay = new HSBType(hue,sat,bri)
Lifx_Lounge.sendCommand(kodiplay)
logInfo("RULES", "all lights off")
}
case "pause" : {
//look into historicstate for all the light values when the first play started
//var Number LoungeLamp_DimmerState = Lounge_Lamp_Dimmer.historicState(time_play_started).state
var Number Lounge1_DimmerState = Lounge_3_Dimmer.historicState(time_play_started).state
var Number Lounge2_DimmerState = Lounge_6_Dimmer.historicState(time_play_started).state
var Number Kitchen1_DimmerState = Kitchen1_Dimmer.historicState(time_play_started).state
var Number Kitchen2_DimmerState = Kitchen2_Dimmer.historicState(time_play_started).state
//turn on specific lights to a low light only if they were already on when play started
var hue = new DecimalType(242.9993133544921875)
var sat = new PercentType(100)
var bri = new PercentType(100)
var HSBType kodipause = new HSBType(hue,sat,bri)
Lifx_Lounge.sendCommand(kodipause)
logInfo("RULES", "kodi is paused so lights should be on dim")
//kodi_notification.postUpdate("lights should be dim")
}
}
}
}
end