Kodi Community Forum

Full Version: How to determine whether Kodi is in master mode from the command line
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I currently have Kodi configured with several restricted sources that are only unlocked under master mode. This is to prevent my young kids from watching unsuitable films.

This generally works well, but I have to remember to switch master mode off after watching something from one of the restricted sources. Ideally this would happen automatically in the event that I forget. (A few weeks ago I forgot to exit master mode before I went to bed and when I came down in the morning my six year old son was watching Deadpool Confused)

Unfortunately this functionality isn't built in. I've been trying to roll my own solution, and I settled on rebooting the machine at 4am every morning, because when Kodi starts up it's always in "normal" mode (i.e. not in master mode.). This works, but I had to mess around with some CEC settings to stop the pi turning on my TV every morning when it rebooted, and now I've got weird intermittent CEC problems - e.g. my receiver sometimes turns off when switching to the pi.

I have found that I can exit master mode on the command line with this:

Code:
kodi-send --host=xxx.xxx.xxx.xxx --port=9777 --action="Mastermode"

If Kodi is in master mode, it drops back to normal mode. However, if Kodi isn't in master mode this command brings up the keypad on the screen requesting a pin to enter master mode. This is undesirable because it'll confuse the kids when they turn the telly on.

What I need is a way to determine whether Kodi is in master mode from the command line, then I can write a script to run the command above if (and only if) necessary. Does anyone know of a way to do this? Or an alternative way to accomplish my goal?
This any good to you ?

PHP Code:
curl ---data-binary '{"jsonrpc":"2.0","method":"XBMC.GetInfoLabels","params":{"labels": ["System.ProfileName"] },"id":1}' -'content-type: application/json;' http://127.0.0.1:9001/jsonrpc 

Response from my system

PHP Code:
{"id":1,"jsonrpc":"2.0","result":{"System.ProfileName":"Master user"}} 
You could probably use callbacks as an alternative. Set an idle timeout (or link to screensaver) at which point kodi switches profile automatically.
I use it to jump back to the homepage on screensaver activation (to avoid problems with mysql).
(2016-10-03, 18:34)black_eagle Wrote: [ -> ]This any good to you ?

PHP Code:
curl ---data-binary '{"jsonrpc":"2.0","method":"XBMC.GetInfoLabels","params":{"labels": ["System.ProfileName"] },"id":1}' -'content-type: application/json;' http://127.0.0.1:9001/jsonrpc 

Response from my system

PHP Code:
{"id":1,"jsonrpc":"2.0","result":{"System.ProfileName":"Master user"}} 

Thanks for the idea! Unfortunately this seems to always return "Master user", regardless of whether I'm actually in master mode or not.

I suspect that this is because I only have a single profile. So I don't want to detect what profile I'm in - I want to detect whether or not the master lock is active. I've done some digging based on the query you suggested but I don't think there's a way to do this with the JSON API Sad

I might be forced to reconfigure the box to use two profiles, then I can get this auto-switching to work easily. I'm sure I tried multiple profiles before though and I didn't like it for some reason - I think the master lock method was just much simpler.
I can't see this bool on the wiki so it may have been deprecated, but System.HasLocks certainly used to return whether master mode was enabled.

Code:
{"jsonrpc": "2.0", "method": "XBMC.GetInfoBooleans", "params": { "booleans": ["System.HasLocks"] }, "id": 1}
(2016-10-04, 19:17)BobCratchett Wrote: [ -> ]I can't see this bool on the wiki so it may have been deprecated, but System.HasLocks certainly used to return whether master mode was enabled.

Code:
{"jsonrpc": "2.0", "method": "XBMC.GetInfoBooleans", "params": { "booleans": ["System.HasLocks"] }, "id": 1}

This seemed promising, but it always returns true on my system:

Code:
{"id":1,"jsonrpc":"2.0","result":{"System.HasLocks":true}}

I think it's checking whether locks exist, rather than whether or not they are activated.

However, I was curious about what other deprecated properties there are, so I went and looked at the source code and found System.IsMaster, which works! It returns true when in master mode, and false when the sources are locked.

So now I have my script:

Code:
#!/bin/sh

RESULT=`curl -s --data-binary '{"jsonrpc": "2.0", "method": "XBMC.GetInfoBooleans", "params": { "booleans": ["System.IsMaster"] }, "id": 1}' -H 'content-type: application/json;' http://127.0.0.1/jsonrpc | grep -c "true"`

if [[ "$RESULT" -eq 1 ]]
then
    kodi-send --host=127.0.0.1 --port=9777 --action="Mastermode"
fi

I might look into modifying this to run every 30 minutes while also checking whether the system has been idle for 20 minutes or more using System.IdleTime(time).
What is kodi-send. Where I can download it?
(2017-05-06, 08:31)FreakMurderer Wrote: [ -> ]What is kodi-send. Where I can download it?

It's part of Kodi. On my LibreELEC install it's here:

Code:
/usr/bin/kodi-send
In case anyone's interested, this is the script I finally settled on:

Code:
#!/bin/sh

# Print timestamp
date

# Check whether we are in master mode (1 = in master mode, 0 = not in master mode)
MASTER_MODE=`curl -s --data-binary '{"jsonrpc": "2.0", "method": "XBMC.GetInfoBooleans", "params": { "booleans": ["System.IsMaster"] }, "id": 1}' -H 'content-type: application/json;' http://127.0.0.1/jsonrpc | grep -c "true"`

# Check whether the system is idle (1 = idle, 0 = not idle)
IDLE=`curl -s --data-binary '{"jsonrpc": "2.0", "method": "XBMC.GetInfoBooleans", "params": { "booleans": ["System.IdleTime(3600)"] }, "id": 1}' -H 'content-type: application/json;' http://127.0.0.1/jsonrpc | grep -c "true"`

echo "Master mode = $MASTER_MODE"
echo "System idle = $IDLE"

if [[ "$MASTER_MODE" -eq 1 && "$IDLE" -eq 1 ]]
then
    kodi-send --host=127.0.0.1 --port=9777 --action="Mastermode"
fi

I run this every 30 minutes in a cron job.