Quick and Dirty, Light toggling

No need for the smartphone anymore

I am so happy since I started using the Harmony remote for the control of the Kodi installation in the living room. It works great and I do not need my smartphone for the control any more. But for switching off the light when we start watching a movie I still needed the smartphone, so I decided to fix this problem as well:)!

Toggling the state using the Harmony remote

This is the Python script I wrote, not nice but it works.
I first gather the state of the lamps using the Domoticz JSON API. After that I toggle switching off the lamps, or if everything is off I switch the 3 lamps on (using a scene with ID 6).

# -*- coding: utf-8 -*-

import urllib2
import json

# Gather lamp state.
response1 = urllib2.urlopen("http://localhost:8080/json.htm?type=devices&rid=68")
data1 = json.load(response1)
state1 = data1['result'][0]['Data']

response2 = urllib2.urlopen("http://localhost:8080/json.htm?type=devices&rid=175")
data2 = json.load(response2)
state2 = data2['result'][0]['Data']

response3 = urllib2.urlopen("http://localhost:8080/json.htm?type=devices&rid=20")
data3 = json.load(response3)
state3 = data3['result'][0]['Data']

# Toggle the state of the lamps.
if state2 != u'Off':
        response = urllib2.urlopen("http://localhost:8080/json.htm?type=command&param=switchlight&idx=175&switchcmd=Off")
elif state3 != u'Off':
        response = urllib2.urlopen("http://localhost:8080/json.htm?type=command&param=switchlight&idx=20&switchcmd=Off")
elif state1 != u'Off':
        response = urllib2.urlopen("http://localhost:8080/json.htm?type=command&param=switchlight&idx=68&switchcmd=Off")
        response = urllib2.urlopen("http://localhost:8080/json.htm?type=command&param=switchscene&idx=6&switchcmd=On")

I then mapped the Key o to this in keyboard.xml of my Kodi setup with <o>RunScript("/home/kodi/licht_wohnzimmer.py")</o>

After that using MHGUI I mapped the Red button to the key o.


That's it, quick and dirty.

Happy Hacking!!

License: CC BY-SA 4.0 Discuss on Mastodon