Openhab 3 and MagicHome bulbs V9


I am rather brand new to the forums and unsure really what to offer in the beginning steps of this troubleshooting.

I have used the MagicHome binding in order to discover/connect my MagicHome bulbs which I note are version 9 of their firmware.

My LED strips work without fault and are painless, the bulbs… The on/off works but after fiddling with the drivers and fading combinations I’ve come to find will not change the colour at all.

I would really love a hand getting this to work. I’ve ended up using Rules and SmartThings API to interface with them, it’s terrible! But it works.

Many, many thanks :blush:

I will openly admit that I am not a scripter, however, I have devised a way to get MagicHome v.9 bulbs working with colour and using their API.

— Steps to reproduce —


  1. Download/Install (NetCapture / Android).
  2. Install CA Certificate.
  3. Run this capture program and grab your token from the MagicHome app packet.


  1. Download/Extract:
    GitHub - namacha/python-magichue: Control Magic Hue(Magichome) in Python.

  2. Install this into Python3 / Pip3

  3. Download/Install:
    colorir · PyPI

  4. Copy this script - I can’t remember what imports I installed as part of my testing, please check for yourself while preparing.

import time
import magichue
import colorsys
import sys
import re

from magichue import RemoteAPI
from magichue import RemoteLight
from colorir import HSV, sRGB

h,s,v = sys.argv[2].split(',')

h_str = str(h)
h_out = re.sub(r'\..*',"",h_str)
h_int = int(h_out)

s_str =str(s)
s_out = re.sub(r'\..*',"",s_str)
s_int =int(s_out)

v_str = str(v)
v_out = re.sub(r'\..*',"",v_str)
v_int = int(v_out)

h = int(h_int)
s = int(s_int)
v = int(v_int)

rgb = HSV(h, s, v, max_sva=100).rgb()
rgb_sRGB = str(rgb)
rgb_sRGB_1 = rgb_sRGB.replace('sRGB', '')

rgb_bracket1 = str(rgb_sRGB_1)
rgb_bracket_1 = rgb_bracket1.replace('(', '')

rgb_bracket2 = str(rgb_bracket_1)
rgb_bracket_2 = rgb_bracket2.replace(')', '')

rgb_zero = str(rgb_bracket_2)
rgb_zero_1 = rgb_zero.replace('.0', '')

rgb_output = str(rgb_zero_1)

TOKEN = ''
api = magichue.RemoteAPI.login_with_token(TOKEN)
light = RemoteLight(api=api, macaddr=sys.argv[1])

r,g,b = rgb_output.split(',')

r_str = str(r)
r_out = re.sub(r'\..*',"",r_str)
r_int = int(r_out)

g_str = str(g)
g_out = re.sub(r'\..*',"",g_str)
g_int = int(g_out)

b_str = str(b)
b_out = re.sub(r'\..*',"",b_str)
b_int = int(b_out)

#b_int = int(b)

light.r = r_int
light.g = g_int
light.b = b_int
  1. Create a rule/script that executes the script:
var thread = Java.type('java.lang.Thread')
var Exec = Java.type("org.openhab.core.model.script.actions.Exec");


And this is how I have ended up getting the bulbs to work and connect via Google Home! ~ I really hope this helps someone, I’m certainly no scripter and this forced me to gulge my eye’s out in frustration… However, I have an end product and I hope you are able to use it.