Kodi / light rule

Hi all

I’m trying to setup the rule to switch off my lights once a movie or an episode starts but it’s not working.

My items
String kodi_player_state "Status [%s]" <sofa> (gKodi) {xbmc="<[#livingRoom|Player.State]"} String kodi_player_type "Typ [%s] " <sofa> (gKodi) {xbmc="<[#livingRoom|Player.Type]"}

My rule:
rule "Lights out when kodi starts" when Item kodi_player_state changed to Play then if(kodi_player_type.state == "episode") { sendCommand(Sw_EG_Lampe_Sofa,"OFF") } end

The rule triggers, so checking kodi_player_state is correct. Also, the lamps switches off correctly if I put it outside the if condition. So I’m not checking kodi_player_type correctly.

Also, I’m still struggling with the data types. When writing kodi_player_type to the log, it’s not working as it’s a StringItem. So I figured I have to get the state of the StringItem. Is that correct? What exactly is a StringItem ?


You probably want:


OK, will try that too. But as I wrote, switching off the lamp works correctly. The part that is not working is if(kodi_player_type.state == "episode")

Ah, try this then:

if(kodi_player_type.state.toString == "episode")

Any luck?

Not at first, I thought I was going crazy :smiley:

If I did anything before my if condition, it worked correcty!? And I literally mean “anything” like logging a message.

It turns out, that the rule runs “too fast”. When kodi_player_state changes to Play, it takes a short while for the kodi_player_type to be updated! So if I directly have the if condition, kodi_player_type is still empty and the condition is false. If I did anything before that, the type has enough time to update.

The condition itself works correctly :grinning:

I will insert an additional check to make sure that kodi_player_state is set before I continue with the rule.

Thanks a lot for your help.

Here is how I do it:

rule "Adjust Living lighting when XBMC starts/stops"
    Item XbmcLiving_Player changed
    var String state = XbmcLiving_Player.state.toString()
    logInfo("XBMC State:", state.toString)
    switch (state.lowerCase) {
	 	case "play" :  {
	 		   		sendCommand(Light_GF_Living_Floor, OFF)
	 		   		sendCommand(Light_GF_Living_Iris, OFF)
	 		   		sendCommand(Light_GF_Living_Strip, OFF)
	 	case "pause" : {
	 				sendCommand(Light_GF_Living_Floor, "80,1,20")
	 				sendCommand(Light_GF_Living_Iris, "80,1,20")
	 		   		sendCommand(Light_GF_Living_Floor, ON)
	 		   		sendCommand(Light_GF_Living_Iris, ON)
	 		   		sendCommand(Light_GF_Living_Strip, ON)
	 	case "stop"  : {
	 				sendCommand(Light_GF_Living_Floor, "80,1,20")
	 				sendCommand(Light_GF_Living_Iris, "80,1,20")
	 		   		sendCommand(Light_GF_Living_Floor, ON)
	 		   		sendCommand(Light_GF_Living_Iris, ON)
	 		   		sendCommand(Light_GF_Living_Strip, ON)

Best regards,

Thanks for your example. Good idea with the switch statement, will use that in my rules too now.

in your case, you don’t distinguish between different types? In our case, I don’t want to switch off all lights when we start music :wink: That’s why I want to check the type for “episode” or “movie” first.
Also, once everything works, I will extend it with some Astro binding rules so these light rules only trigger once it’s dark outside.

@pgruetter - Got you regarding types. Personally I use my Onkyo receiver binding for playing audio, and only use KODI for music when the house is in party mode for playing music/visualizations…So haven’t gotten around to wiring player type handling yet, but imagine something like this would work before the switch (untested!):

if (kodi_player_type.state.toString != ("episode" | "movie")) {

‘sleep’ is there for a half a second to address the state timing issue you mentioned above. Interested to see what you come with! :slight_smile:

The following now works for me, so I’m very close to your solution:

while(kodi_player_type.state.toString == “”) {
if(kodi_player_type.state.toString == “episode” || kodi_player_type.state.toString == “movie”)

I’m still learning the rule syntax so I’m always interested in other ways to write my rules.

Also got an Onkyo since yesterday :grin: Although I deactivated the network access because I realized that standby power consumption is VERY high. Got a master slave multiple socket outlet and even on the highest setting, all slaves keep activating / deactivating because the Onkyo uses too much power… bummer :rage:

My Onkyo also stays kind of warm when on standby - have the TX-NR838. According to this, it only uses 5W of power during standby, but I’ve never bothered to measure… There are some options mentioned here you might want to try disabling to see if power consumption during standby can be reduced.

What model do you have, and how many Watts did you measure during standby?

Got a TX-NR609. Already tried disabling all services. The socket outlet can be adjusted between 8W and 80W, although I’m not sure that’s really true. Anyway, I read in another blog post that someone measured around 38Watts, only because of active network setting. I don’t think it’s really 80W on mine, but even 40W is too much to keep it running 24/7.

1 Like

Thanks for sharing! Will have to measure mine soon to see for myself… :sunglasses:

Let me know if you do, interested to see if it’s really that high

Do you guys actually get player.type to update? I have player.state, player.title etc. Updating when I press play, but never type even after a few minutes.

Yes, check my first post how I defined kodi_player_type. This updates about 1s after the state has changed to Play and then contains “episode” or “movie” for example.
Maybe check your logs? I had a syntax error in my items file yesterday and got a nice error message telling me that.

hmm. I see where I went wrong - for some reason it didn’t like hostname being a name. Worked when I changed it to the IP Address

Not sure if this is of any use to anyone but I have a great rule that does all that’s here as well as recording the state the lights were in BEFORE kodi starts playing, has different light optiosn for pause and then resumes lighting once stopped to the state it was in before play started.

Happy to post items and rule if anyone is interested

I know its been a while since you offered to share your rules Andrew, but I’m a fairly new user and I’d like to see what you’ve done. I plan on trying to implement this behavior in the next few days and examples are helpful, especially at this stage for me.

Hi Daniel,

maybe you are interested in my example.

Have Fun.