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).

#!/usr/bin/python
# -*- 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)
response1.close()
state1 = data1['result'][0]['Data']

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

response3 = urllib2.urlopen("http://localhost:8080/json.htm?type=devices&rid=20")
data3 = json.load(response3)
response3.close()
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")
        response.close()
elif state3 != u'Off':
        response = urllib2.urlopen("http://localhost:8080/json.htm?type=command&param=switchlight&idx=20&switchcmd=Off")
        response.close()
elif state1 != u'Off':
        response = urllib2.urlopen("http://localhost:8080/json.htm?type=command&param=switchlight&idx=68&switchcmd=Off")
        response.close()
else:
        response = urllib2.urlopen("http://localhost:8080/json.htm?type=command&param=switchscene&idx=6&switchcmd=On")
        response.close()

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.

mhgui.jpg

That's it, quick and dirty.

Happy Hacking!!

License: CC BY-SA 4.0 Discuss on Mastodon