no - no output at all when I run the script on it’s own. just blank…
take that back…while watching movie - it said movie
watching tv or nothing playing results in no output.
no - no output at all when I run the script on it’s own. just blank…
take that back…while watching movie - it said movie
watching tv or nothing playing results in no output.
If you remove the -s from the curl command and also the pipe to grep, it will display the full output of curl. This is less useful as a sensor, but should let you know what it’s actually doing.
yup - returns same as running curl command by hand - so looking good…can’t figure out why HASS is so pi$$ed off.
17-01-18 20:05:40 homeassistant.components.sensor.command_line: Command failed: /usr/bin/mediachecker.sh
ok - so retarted HASS and its no longer complaining. and movie showed yeah!
but had movie playing in kodi when I did that…will see what playing tv looks like…maybe error is only when not movie? will report…
yup - when movie NOT playing HASS log gets torqued quickly. plus sensor has not changed at this time from movieplaying to anything else.
It’s almost like we need to add in “unknown” when KODI is not playing and “episode” when tv is playing and key off that in the automation/scripting under HASS.
thoughts?
I just set up the sensor on my machine to test. You aren’t crazy, I noticed the same behavior. Teach me to offer untested code.
First thing I noticed is a mismatched case issue. The sensor is looking for “Movie” but it will never find that. “movie” is the correct ‘on’ state.
I tried skipping the script entirely, and just using the curl command as the sensor, and that failed as well. Not sure if it’s the null string that it’s stumbling on, or something else. Testing further.
roger - glad to hear I’m not losing it - LOL!
I’ll sit tight to see what you come up with - like I said, we need payload off to be unknown or episode and payload on to be movie I think. Not sure how to handle that in HASS under a sensor.
ok - from a previous example I used for “ping action” thread I started - thanks @PtP
#! /bin/bash
ping -w 5 8.8.8.8 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo “Success”
else
echo “Fail”
fi
we need to echo back the type (movie/episode/unknown) - can a sensor handle an ‘or’ statment for payload?
Ok, give this a shot -
#! /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 | if [[ $(grep -o movie) ]]; then echo "ON"; else echo "OFF"; fi
This will output the default ON and OFF based on if a movie is playing or not. That should make HASS happy.
ok - made that change in the script and
then changed sensor to ON and OFF for each payload.
restarted HASS didn;t come back…don’t know why - rebooting…brb
MUCH happier now!
Working for you, then?
Yes sir! Re-working automation as we speak! @Zen - a HUGE thanks! I’m a Windows admin by trade so I struggle a bit with the linux part of HASS - but you were great! Thanks for hanging right in there with me!
Just so everyone has the solution -
bash script:
#! /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 | if [[ $(grep -o movie) ]]; then echo "ON"; else echo "OFF"; fi
Sensor:
- platform: command_line
scan_interval: 10
name: Movie_Time
command: “/usr/bin/mediachecker.sh”
payload_on: “ON”
payload_off: “OFF”
Automation:
- alias: “KODI Movie Stopped”
trigger:
- platform: state
entity_id: sensor.movie_time
from: ‘ON’
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
service: scene.turn_on
entity_id: scene.Kodi_Stopped
- alias: "KODI Movie Playing"
trigger:
- platform: state
entity_id: sensor.movie_time
to: 'ON'
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
service: scene.turn_on
entity_id: scene.Kodi_Playing
Scene:
scene:
- name: Kodi_Playing
entities:
light.linear_lb60z1_dimmable_led_light_bulb_level_3_0:
state: on
brightness: 25
switch.ge_unknown_type5052_id3031_switch_2_0: off
- name: Kodi_Stopped
entities:
light.linear_lb60z1_dimmable_led_light_bulb_level_3_0:
state: on
brightness: 255
switch.ge_unknown_type5052_id3031_switch_2_0: on
HTH!
@Zen - you know - I was doing some reading today…wonder if we could have used this instead of the sensor?
Such that when Kodi is playing, making the same curl call - but would it come back with something? Just thinking outloud - everything is working (THANKS!) - but was just kind of curious.
@vexter0944 - This was just added in the most recent update last week (0.36), so I haven’t had a chance to dig in much yet. From what I can tell, it looks like we could make the request with this function, but I don’t think we would get the output back out.
I’m sure there are probably quite a few ways to get that information out of Kodi. In the end, use what works best for you. I come from a linux background and tend to prefer console-based scripted languages (bash, perl, python). That is how I think, so that is how I build things. You mentioned being a Windows Admin, so maybe you have similar feelings about C#, ASP, Powershell, or whatever you crazy Windows kids are up to these days .
HAHA @Zen! Us crazy Windows kids these days - LOL! Still laughing Appreciate the feedback - happy with the solution, just the new component got me wondering/curious if it was a fit for simplicity’s sake - otherwise, doing fine - take care!!!
There’s a tidier looking curl string that someone’s put up in feature requests:
I gave it a vote, sounds like a great idea.