Right now I have lights dimming when KODI plays video - but I’d really only like it to do this when playing movies vs tv shows. Is there anyway to do this? I don’t know if the video being played can be correlated to a library type (mine are divided into movies and tv shows under KODI’s library) but it could be quite handy. Let me know if there’s more info needed.
I think there would be a way to use Kodi’s API to find out. I can’t test it at the minute but I reckon this call could help:
http://kodi.wiki/view/JSON-RPC_API/v6#Notifications.Item.Type
There are loads to chose from so I’d say the right call is in there somewhere.
There is another way to do this with just HASS, but it may be convoluted! I wrote a small javascript+php app that changes the photo currently displayed on a tablet under my TV to the fanart assigned to the currently playing media when Kodi starts playing. (and put the family photo slideshow back when media playback stops.
In doing this, I noticed that the (annoyingly) the default aspect ratio of the image is different based on what you are playing. Movies display “Banners”, TV Shows display “Thumbs”. You can see this by looking at the art displayed in the media player component in the Home Assistant web interface. Since I wanted the images to be uniform, this was a problem for me. Looks like a possible solution for you!
You can test the size of the image Home Assistant displays to determine the media type. This is only going to work if all of your media has artwork assigned in Kodi’s library.
Let me know if you need further details, I can provide some code, although mine doesn’t do exactly what you want, I’m sure you could modify it to do so.
Thanks for the input everyone!
@Bit-River - I guess make the call from a script/automation when media player shows playing etc? Just trying to flesh out the idea a bit…
@Zen - thanks for that, that’s a good idea too! How would I call the javascript - I’d be curious as to that as well.
Any other ideas/thoughts?
Thanks!
So I had this long drawn out message written with a bunch of convoluted code and multiple command line sensors I was going to suggest to you… then I remembered the media_player component has a ‘media_content_type’ property (per: https://home-assistant.io/components/media_player/ ).
Give that a shot, see if it works in your automation. You can test it out without writing any code by playing different media types and watching the state of that property in the states page of the developer tools on the main HASS interface.
@zen - I noticed that too - but wasn’t sure if it would pass along the media type like music vs video or more like movie vs tv - I’ll give that a shot and see how it goes - thanks for the feedback!
Looks like it should report episode vs video for tv::movie, respectively. I’m at work right now, so I can’t investigate too deeply. It’s possible it will report video for both. If so, I’m sure there is another way to go about this.
@Zen - I agree - it does mention tvshow or video - so it might be a good option - will test as soon as I get home from work as well. Thanks for the help - if you beat me to it - let me know what your setup shows while playing, otherwise, I’ll report back as soon as I get a chance to test. Thanks!!
@Zen - so it only shows video when I’m playing tv or movie from Kodi - which is kind of what I expected. I’ll be curious if yours shows the same.
Can confirm - mine shows “video” for either format. Looks like we need another solution.
@Zen - agreed. I like Bit-River’s idea of an API call - I’m guessing some kind of script with a curl or something along those lines? like when media player goes from stopped/playing - it would call said automation script to run curl api call and then do ‘stuff’ based on return.
Thoughts?
Try the JSON RPC call in this link http://stackoverflow.com/questions/22654466/how-to-get-currently-playing-item-in-xbmc it should get you the result you need.
You can make the request with a command line sensor and either a shell script call to curl or something hacked together in python.
An example setup would be to have your automation that fires when media is playing check the above command line sensor, and if it’s a movie playing, dim the lights. If it is anything else, skip it.
@Zen - thanks for the link! I think we’re on the right track here. I follow what you’re saying but I’m not 100% sure how to ‘call’ the API call - like I get the JSON/API - but your part here -
You can make the request with a command line sensor and either a shell script call to curl or something hacked together in python.
How does I do that with HASS? I guess what I’m saying is how would a sensor work in this case? Or how can HASS call curl? Sorry - this is a realm I’ve not dove to deep on yet… I follow what the sensor would do for the automation etc - but wouldn’t they have to be in sync etc? I’ve not seen a way to control how often a sensor runs a command when doing something like this.
@Zen - Thanks for the pointer
@Vexter - This curl command will get you the details:
curl -D - -H ‘Content-Type: application/json’ -d ‘{“jsonrpc”: “2.0”, “method”: “Player.GetItem”, “params”: { “playerid”: 1}, “id”: “VideoGetItem”}’ http://[Your-Kodi’s-IP-Here]:8080/jsonrpc
The call will result in a value for “type” that’s either “episode” or “movie”.
Kodi API calls bake my noodle a bit to be honest, but I’ll be back with a sensor soon enough.
Ok, @vexter0944, I think I have this solved for you.
Create a file on your home assistant box called something like “mediachecker.sh”
$ nano mediachecker.sh
and paste the contents below into it:
#! /bin/bash
curl -s -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "playerid": 1}, "id": "VideoGetItem"}' http://<<<IP ADDRESS OF KODI>>>/jsonrpc | grep -o movie
make the file executable:
$ chmod +x mediachecker.sh
To test, you can use watch to mimic HASS running the sensor:
$ watch mediachecker.sh
This will run your script in a terminal every 2 seconds until you stop it. (you can press ctrl+c to stop). Start a movie in Kodi, and make sure it changes from ‘Fail’ to ‘Movie’. Try playing something else, make sure it does what you want!
Next, create a binary command line sensor to check your media:
- platform: command_line
scan_interval: 10
name: movieplaying
command: "/path/to/mediachecker.sh"
payload_on: "Movie"
payload_off: ""
Then use this sensor for your media lights automation. When you start playing a movie in Kodi, within 10 seconds, this sensor will flip from ‘off’ to ‘on’. You can adjust the timing, name, and path to your needs.
I just tested the shell script on my system here, and can confirm it works. I have not tested the automation, as that will be more specific to your installation.
Let me know if you need any additional pushes in the right direction. Not sure how comfortable you are in linux or with automations, so feel free to reach out if you need more help!
Will test and setup very soon - thanks @Zen!!! That’s a lot of effort for me - but I sure do appreciate it!!
@Zen - I created the mediachecker,sh and sudo chmod +x on it., I do a watch and it says its watching every 2 seconds - bvut I never see a fail or anything. Just a time/date stamp on the right. Thoughts?
ok looks like http://kodi/jsonrpc isn’t responding - investigating…
had to add :8080 to port on ip address…still not getting anything under watch, but the curl does return episode while kids watching tv…so getting closer…
Sorry, been away from the pc.
You can run the command as is straight as a sensor in HASS (just using the curl command as your “command:”), but this reduces your ability to troubleshoot. (You can change the mediachecker.sh script without needing to restart HASS).
Check that the IP for Kodi is correct, and make sure you have the remote control api turned on (in your Kodi interface, go to System/Settings/Network/Services, activate Allow control of Kodi via HTTP). You can check the port from there, as well. If you are running the http interface on a port other than 80, you will need to add it to the curl command. (Like Bit-River did with :8080).
Let me know if that helps
yup 8080 was the issue.
working on getting the sensor to load - it doesn’t like it under /home/hass/.homeassistant for some reason - will move it somewhere else I guess.
continuing to troubleshoot.