News:

HOT TIP! In the command editor, you can ctrl-click and drag an item to create a copy of it.

Main Menu

milight (limitlessled) control python module error

Started by mrDavisma, March 04, 2015, 12:15:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

mrDavisma

Hi
I recently got some Mi Lights and straight away looked for better ways to control them, first through eventghost as I used it but then I found voxcommando! So with no python experience I set off and found the module https://github.com/ojarva/python-ledcontroller with this I can simple use comands like led.on(1)
My Problem
This module works fine in eventghost but not in Vox. The script allows me to call simple code to control the lights like
import ledcontroller
led = ledcontroller.LedController("ip.ad.re.ss")
led.on(1) # the command

This works in eventghost fine however when i try using it in voxcommando I get an error

python ready
Line: 168 >>
TypeError: expected str, got bytes

being a noob to python I could not fix this (nor can I now!) so I bypassed python in vox and passed payloads to eventghost to run the python. After a few days of learning python I came up with this bit of code

import eg
import ledcontroller
led = ledcontroller.LedController("192.168.0.115")
red, royal_blue, green, yellow, white = "red", "royal_blue", "green", "yellow", "white"
a, b, c, d, e, f, g, h, i, j = "10",  "20", "30", "40", "50", "60", "70", "80", "90", "100"
main_light, side_light, back_light, living_room_lights, dinning_room_light = 1, 4, 2, 0, 3
on = "on"
off = "off"
v = "set_brightness"
w = "set_color"
y = eg.event.payload[1]
x = eg.event.payload[2]
z = "led."
group = [main_light, side_light, back_light, living_room_lights, dinning_room_light]
power = [on, off]
colour = [red, royal_blue, green, yellow, white]
dim = [a, b, c, d, e, f, g, h, i, j,]
if x in group:
    x = x

if y in power:
    mycommand = z + y +"(" + (x) + ")"
    exec mycommand
if y in colour:
    mycommand = z + w + "("  + '"' + y + '"' + ", " + x + ")"
    print mycommand
    exec mycommand
if y in dim:
    mycommand = z + v + "("  +  y +  ", " + x + ")"
    exec mycommand
print x
print y



I am very happy with this  :) python is fun lol. This code works great, upon receiving payloads in eventghost from voxcommando.
I want to continue my learning by expanding on this code to set values etc so I can use vox commando to remember lights status ( if on or off etc ) as Mi lights have no talk back feature like the philips hue do  :( but to make this easier for me now to right the code and later to share it with people it would be better if I could get the ledcontroller module to work in voxcommander so I dont have to go back and forth between Vox and Eg

So Finally
So after my long winded post ( Sorry ) Can someone have a look at the module and try and work out why it works in eventghost but not voxcommando and if there is a away to fix it please

Thanks

Mark

jitterjames

For starters you are not going to be able to "import eg" since you are not running the python in eventGhost.

In order to import your ledCtroller you would need to put the correct files into the python libraries folder in VoxCommando which is found in

\VOXCOMMANDOFOLDER\plugins\py\lib

But if you are unfamiliar with both VoxCommando and with Python I don't think you'll get very far.

You will be better off either sending command to EventGhost and getting EventGhost to control your lights, or you can use this solution for MiLights that has already been worked out.

http://voxcommando.com/forum/index.php?topic=1743.0

nime5ter

VC uses IronPython, not "pure" Python per se, so sometimes there are some differences or incompatibilities depending on which Python modules you're trying to use. In the past we've had issues with the socket module and one of the url_lib modules. Your ledcontroller module is using the socket module.

That may or may not be the issue here. As James mentions, we don't actually need to use Python to control wifi lights in VC because you can send messages directly using VC's TCP plugin. It does the exact same thing as your Python script. So, for now at least, you may want to just try switching to the commands he links to above.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

I probably didn't read the original post carefully enough.  Sorry about that!  :bonk

mrDavisma

Hi guys
           Thank you for your quick replies!
James I already had the ledcontroller in the lib folder. I worked that bit out lol. I understand I would not be able to import eg within voxcommando, the code I posted is the one made for eventghost to use to process the events sent from voxcommando. I just wanted to try and use python within voxcommando to keep everything " In the same basket"
I wanted to use python because it seems easier to build and use more complex phases like " turn the main light on change the colour to red and dim to twenty" etc also I will look to incorporate  setting varibles in the same code for remembering individual light states and last active light etc

Hi nime5ter
                 cheers for the info. I did look line 168 in the code and tried traced it back it back to the import socket but didn't know where to go from there but at least I know why it may not be working.
I will take another look at the link James posted but it seems to need many commands for everything where as using the code I have with just 3 commands I can control all the lights individually with just 3 command phases

all else fails i will just continue to pass the payloads to eg from vox

Thanks

Mark

mrDavisma

Quote from: jitterjames on March 04, 2015, 01:28:55 PM
I probably didn't read the original post carefully enough.  Sorry about that!  :bonk

No worries mate lol Thank you for the great program! I will be picking up a licence as soon as I make it useful to my wife and get permission lol

jitterjames

Quote from: mrDavisma on March 04, 2015, 01:53:44 PM
I will take another look at the link James posted but it seems to need many commands for everything where as using the code I have with just 3 commands I can control all the lights individually with just 3 command phases
Yes you should take another look.  It is incredibly simple.  For example, to turn all lights on requires only a single action, no python or anything else (you just need to enable the TCP plugin).
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<command id="283" name="All Groups ON" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>TCP.UDP.SendMixed</cmdType>
    <params>
      <param>\x42\x00\x55</param>
      <param>8899</param>
      <param>192.168.1.163</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase optional="true">Jarvis</phrase>
  <phrase>turn lights on</phrase>
</command>


However there is also support to do much more than just turn lights on and off.

If you really want to use python though, the next release of VC (coming soon) will have an updated version of the IronPython dlls which may resolve certain issues such as the one you have encountered.

mrDavisma

That sounds good, Off to work now so will have a play when I get home then. thanks for the help

Mark

nime5ter

Today's VC release (version 2.1.4.2) has an updated IronPython plugin, if you'd like to see if that helps resolve your issues with the ledcontroller module.

My understanding is that they've addressed several socket-related bugs.

http://voxcommando.com/home/downloads/

http://voxcommando.com/mediawiki/index.php?title=ChangeLog#Version_2.1.4.2



TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)