if (state.lowerCase == “play”) {
// store the state when play was pressed
time_play_started = now
sendCommand(Lounge_Dimmer, OFF)
}
if (state.lowerCase == “pause”
|| state.lowerCase == “stop”) {
var play_time = xbmc_state_1.lastUpdate
if(Lounge_Dimmer.historicState(play_time) == “ON”) {
sendCommand(Lounge_Dimmer,ON)
}
}
rule “Lights dimm play”
when
Item Status_Kodi changed to Play
then
sendCommand(Lys_stue_venstre_dimm, “20”)
sendCommand(Lys_stue_hoyre_dimm, “20”)
end
rule “Lights dimm pause/stopp”
when
//Item Status_Kodi changed from Play to Pause or
Item Status_Kodi changed from Play to Stop
then
sendCommand(Lys_stue_hoyre_dimm, “100”)
sendCommand(Lys_stue_venstre_dimm, “100”)
end
Thanks for the reply - I had a working script like yours working fine - however the workflow with that script is a but of a problem as if the light is not on when Kodi plays, I want it to not be on when kodi stops (for example in the middle of the day). With this script the light comes on regardlesss of it’s previous state.
That was where I was trying to get persistance to evaluate the state prior to the play event but there is something either not initialised or there is some syntax problem. I will change tolowercase and see if thats causing it
Yes, string Items are persistable, however, it depends on the persistence service, but db4o should do it.
I have one question about your Code:
You defined time_play_started to save the time, when playback started, but you never make use of this variable.
Instead you make use of .lastUpdate, which should be fine.
Now .lastUpdate should deliver Date, historicState expects AbstractInstant. I’m not very familiar with Types, so… is that correct?
Maybe you have to make a TypeCasting like xbmc_state_1.lastUpdate as AbstractInstant or so…