Lock YouTube

Inspired by my own LockU2 utility and Useless Box, I came up with a simple and stupid, yet effective, openHAB rule to prevent my kids from watching YouTube when they are not allowed to do so. So first requirement was ability to turn this lock on or off – just added a new switch item for this, and added it to a sitemap.

The rule makes use of the LGTV binding as well as HarmonyHub binding. Without any of these, I don’t think it would be possible to pull off.

Here goes:

rule "Lock YouTube"
when
    Item LGTV_Application changed to "youtube.leanback.v4" or
    Item LGTV_Application changed to "youtube.leanback.kids.v4"
then
    if (Lock_YouTube.state == ON)
    {
        //HarmonyLGTV_ButtonPress.sendCommand("Exit")
        LGTV_Application.sendCommand("com.webos.app.livetv")
    }
end

rule "Enable Lock YouTube"
when
    Item Lock_YouTube changed to ON
then
    if (HarmonyHub_CurrentActivity.state == "Watch TV" &&
        (LGTV_Application.state == "youtube.leanback.v4" || LGTV_Application.state == "youtube.leanback.kids.v4"))
    {
        //HarmonyLGTV_ButtonPress.sendCommand("Exit")
        LGTV_Application.sendCommand("com.webos.app.livetv")
    }
end

This YouTube blocker won’t actually block the YouTube app on the television, but will instead immediately quit the app once it’s launched. If YouType (or YouTube Kids) is already running when activating the lock, it will also quit the app. Update: Changed to use LGTV binding for quitting YouTube – old method commented out.

I almost couldn’t wait for the premiere which was last Saturday morning. I also have a rule in place for generating notifications when the lock has been triggered. After explicitly instructing my son that YouTube was not allowed that morning, only five minutes later I received the first notification that an attempt was made. After that four more identical notifications. Then a final notification that YouTube Kids had also been attempted. Success.