Jump to content

MagicHome Node Server


fahrer16

Recommended Posts

 

6 hours ago, hart2hart said:

Where can I get a description of the shortPoll and longPoll values and their impact on this node?  I left them at the default values of 5 and 60 but haven't done a lot with the LED strips.

Looks like the long poll does a query of all the nodes. There is no short poll in the code so it does nothing.

Link to comment
Share on other sites

  • 4 months later...

Just installed this Poly onto Polisy (since I just got some Magic Home bulbs - https://www.amazon.com/gp/product/B07VLBCGP2/ref=ppx_yo_dt_b_asin_title_o00_s00 )

Seems to mostly work...  If I issue a 'Fast-on' I get this error in the log:

2019-11-09 10:23:10,620 [Controller] [INFO ] Received Fast On Command for d8f15ba85be1
2019-11-09 10:23:10,621 [Controller] [INFO ] Received command to turn on d8f15ba85be1.
2019-11-09 10:23:10,622 [Controller] [ERROR] --- Logging error ---
2019-11-09 10:23:10,624 [Controller] [ERROR] Traceback (most recent call last):
2019-11-09 10:23:10,625 [Controller] [ERROR] File "/usr/local/lib/python3.7/logging/__init__.py", line 1025, in emit
    msg = self.format(record)
2019-11-09 10:23:10,626 [Controller] [ERROR] File "/usr/local/lib/python3.7/logging/__init__.py", line 869, in format
    return fmt.format(record)
2019-11-09 10:23:10,626 [Controller] [ERROR] File "/usr/local/lib/python3.7/logging/__init__.py", line 608, in format
    record.message = record.getMessage()
2019-11-09 10:23:10,627 [Controller] [ERROR] File "/usr/local/lib/python3.7/logging/__init__.py", line 369, in getMessage
    msg = msg % self.args
2019-11-09 10:23:10,628 [Controller] [ERROR] TypeError: not enough arguments for format string
2019-11-09 10:23:10,629 [Controller] [ERROR] Call stack:
2019-11-09 10:23:10,631 [Controller] [ERROR] File "/usr/local/lib/python3.7/threading.py", line 890, in _bootstrap
    self._bootstrap_inner()
2019-11-09 10:23:10,633 [Controller] [ERROR] File "/usr/local/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
2019-11-09 10:23:10,633 [Controller] [ERROR] File "/usr/local/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
2019-11-09 10:23:10,634 [Controller] [ERROR] File "/var/polyglot/.local/lib/python3.7/site-packages/polyinterface/polyinterface.py", line 765, in _parseInput
    self.nodes[input[key]['address']].runCmd(input[key])
2019-11-09 10:23:10,635 [Controller] [ERROR] File "/var/polyglot/.local/lib/python3.7/site-packages/polyinterface/polyinterface.py", line 668, in runCmd
    fun(self, command)
2019-11-09 10:23:10,636 [Controller] [ERROR] File "./magichome.py", line 232, in fastOn
    return self.setOn(_cmd)
2019-11-09 10:23:10,637 [Controller] [ERROR] File "./magichome.py", line 214, in setOn
    LOGGER.debug('Setting %s to red=%s, green=%s, blue=%s', str(_red), str(_green), str(_blue))
2019-11-09 10:23:10,638 [Controller] [ERROR] Message: 'Setting %s to red=%s, green=%s, blue=%s'
Arguments: ('255.0', '147.0', '41.0')

Fast Off seems to work:

2019-11-09 10:23:50,009 [Controller] [INFO ] Received Fast Off Command for d8f15ba85be1
2019-11-09 10:23:50,010 [Controller] [INFO ] Received command to turn off d8f15ba85be1.
2019-11-09 10:23:51,096 [Thread-10 ] [INFO ] Updating Driver d8f15ba85be1 - GV5: 0, uom: 25
2019-11-09 10:23:51,098 [Thread-10 ] [INFO ] Updating Driver d8f15ba85be1 - ST: 0, uom: 51

 

The biggest issue is when the Poly says the bulb is at 100% - the bulb is *FAR* less bright than 100% with the app. It's only about 25% as bright.I can set the bulb to '100%' - but the bulb itself only goes to about 20 or 30% brightness (as compared to 100% setting with the 'Magic Home' app). I suspect the Poly is sending 100 for 100% - and the bulb may be expecting 255 (or something like it). Alternatively - I'm trying to set 'Warm White' here. The bulb has separate LEDs for WW and CW. These do not appear to be used by the Poly. However - that may not be the total issue. 100% Red via the Poly is less than half as bright as 100% Red from the app.

Link to comment
Share on other sites

  • 1 month later...

Install Nodes on Polisy, now the LED controller is there, but it doesn't discover LEDs  ( that I do see on the Magic Home App and can control from there)

Log below

2019-12-31 09:47:49,875 [Controller] [INFO ] Discovering MagicHome LED Controllers... 2019-12-31 09:47:54,976 [Controller] [INFO ] 0 bulbs found. Checking status and adding to ISY 2019-12-31 09:47:54,978 [Controller] [INFO ] NOTE: LED Controllers can be specified for addition even if not detected via discovery. Add a custom configuration parameter to Polyglot for each LED controller with a key starting with "LED". The value should be in the following format, note the use of double quotes: {"ip":"192.168.0.84", "mac":"F0FEAF241937"} "mac" is the MAC address without colons. 2019-12-31 09:47:54,978 [Controller] [INFO ] NOTE: A delay can be specified to wait a bit for the LED controller to process commands before querying them to update the controller's state in the ISY. Defaults to 1.0 sec. 2019-12-31 09:48:21,457 [Interface ] [DEBUG] Received stop from Polyglot... Shutting Down. 2019-12-31 09:48:21,458 [Interface ] [INFO ] Disconnecting from MQTT... localhost:1883 2019-12-31 09:48:21,461 [Interface ] [INFO ] MQTT Graceful disconnection. 2019-12-31 09:48:25,944 [MainThread] [INFO ] Received Config from STDIN. 2019-12-31 09:48:25,946 [MainThread] [INFO ] UDI Polyglot v2 Interface 2.0.34 Starting... 2019-12-31 09:48:25,991 [MainThread] [DEBUG] gws: {'default': {2: ('192.168.1.1', 'igb0')}, 2: [('192.168.1.1', 'igb0', True)]} 2019-12-31 09:48:25,991 [MainThread] [DEBUG] gw: default=('192.168.1.1', 'igb0') 2019-12-31 09:48:25,992 [MainThread] [DEBUG] ifad: igb0=[{'addr': '192.168.1.208', 'netmask': '255.255.255.0', 'broadcast': '192.168.1.255'}] 2019-12-31 09:48:25,993 [MainThread] [INFO ] Connect: Network Interface: {'addr': '192.168.1.208', 'netmask': '255.255.255.0', 'broadcast': '192.168.1.255'} 2019-12-31 09:48:25,995 [Interface ] [INFO ] Connecting to MQTT... localhost:1883 2019-12-31 09:48:26,048 [Interface ] [INFO ] MQTT Connected with result code 0 (Success) 2019-12-31 09:48:26,050 [Interface ] [INFO ] MQTT Subscribing to topic: udi/polyglot/ns/3 - MID: 1 Result: 0 2019-12-31 09:48:26,050 [Interface ] [INFO ] MQTT Subscribing to topic: udi/polyglot/connections/polyglot - MID: 2 Result: 0 2019-12-31 09:48:26,051 [Interface ] [INFO ] Sent Connected message to Polyglot 2019-12-31 09:48:26,168 [NodeServer] [INFO ] Starting MagicHome LED Polyglot v2 NodeServer version 2.0.4 2019-12-31 09:48:26,169 [NodeServer] [INFO ] Discovering MagicHome LED Controllers... 2019-12-31 09:48:31,211 [NodeServer] [WARNING] ./magichome.py:94: ResourceWarning: unclosed <socket.socket fd=7, family=AddressFamily.AF_INET, type=SocketKind.SOCK_DGRAM, proto=0, laddr=('0.0.0.0', 48899)> 2019-12-31 09:48:31,212 [NodeServer] [INFO ] 0 bulbs found. Checking status and adding to ISY 2019-12-31 09:48:31,214 [NodeServer] [INFO ] NOTE: LED Controllers can be specified for addition even if not detected via discovery. Add a custom configuration parameter to Polyglot for each LED controller with a key starting with "LED". The value should be in the following format, note the use of double quotes: {"ip":"192.168.0.84", "mac":"F0FEAF241937"} "mac" is the MAC address without colons. 2019-12-31 09:48:31,214 [NodeServer] [INFO ] NOTE: A delay can be specified to wait a bit for the LED controller to process commands before querying them to update the controller's state in the ISY. Defaults to 1.0 sec. 2019-12-31 09:49:55,719 [Interface ] [DEBUG] Received stop from Polyglot... Shutting Down. 2019-12-31 09:49:55,720 [Interface ] [INFO ] Disconnecting from MQTT... localhost:1883 2019-12-31 09:49:55,723 [Interface ] [INFO ] MQTT Graceful disconnection. 2019-12-31 09:50:00,021 [MainThread] [INFO ] Received Config from STDIN. 2019-12-31 09:50:00,022 [MainThread] [INFO ] UDI Polyglot v2 Interface 2.0.34 Starting... 2019-12-31 09:50:00,066 [MainThread] [DEBUG] gws: {'default': {2: ('192.168.1.1', 'igb0')}, 2: [('192.168.1.1', 'igb0', True)]} 2019-12-31 09:50:00,066 [MainThread] [DEBUG] gw: default=('192.168.1.1', 'igb0') 2019-12-31 09:50:00,067 [MainThread] [DEBUG] ifad: igb0=[{'addr': '192.168.1.208', 'netmask': '255.255.255.0', 'broadcast': '192.168.1.255'}] 2019-12-31 09:50:00,068 [MainThread] [INFO ] Connect: Network Interface: {'addr': '192.168.1.208', 'netmask': '255.255.255.0', 'broadcast': '192.168.1.255'} 2019-12-31 09:50:00,070 [Interface ] [INFO ] Connecting to MQTT... localhost:1883 2019-12-31 09:50:00,122 [Interface ] [INFO ] MQTT Connected with result code 0 (Success) 2019-12-31 09:50:00,124 [Interface ] [INFO ] MQTT Subscribing to topic: udi/polyglot/ns/3 - MID: 1 Result: 0 2019-12-31 09:50:00,124 [Interface ] [INFO ] MQTT Subscribing to topic: udi/polyglot/connections/polyglot - MID: 2 Result: 0 2019-12-31 09:50:00,125 [Interface ] [INFO ] Sent Connected message to Polyglot 2019-12-31 09:50:00,235 [NodeServer] [INFO ] Starting MagicHome LED Polyglot v2 NodeServer version 2.0.4 2019-12-31 09:50:00,236 [NodeServer] [INFO ] Discovering MagicHome LED Controllers... 2019-12-31 09:50:05,383 [NodeServer] [WARNING] ./magichome.py:94: ResourceWarning: unclosed <socket.socket fd=7, family=AddressFamily.AF_INET, type=SocketKind.SOCK_DGRAM, proto=0, laddr=('0.0.0.0', 48899)> 2019-12-31 09:50:05,385 [NodeServer] [INFO ] 0 bulbs found. Checking status and adding to ISY 2019-12-31 09:50:05,386 [NodeServer] [INFO ] NOTE: LED Controllers can be specified for addition even if not detected via discovery. Add a custom configuration parameter to Polyglot for each LED controller with a key starting with "LED". The value should be in the following format, note the use of double quotes: {"ip":"192.168.0.84", "mac":"F0FEAF241937"} "mac" is the MAC address without colons. 2019-12-31 09:50:05,387 [NodeServer] [INFO ] NOTE: A delay can be specified to wait a bit for the LED controller to process commands before querying them to update the controller's state in the ISY. Defaults to 1.0 sec.

Link to comment
Share on other sites

@Adolfo , the MagicHome protocol isn't very robust and auto detection can be hit or miss.

Included in the message you pasted in from Polyglot is a recommendation to manually add LED controllers to the node server via the polyglot interface by creating a key starting with "LED" and a value containing JSON of the ip address and mac address of the controller ({"ip":"192.168.0.84", "mac":"F0FEAF241937"} "mac" is the MAC address without colons). 

Also, the polisy should be on the same subnet as the LED controller.

Link to comment
Share on other sites

  • 2 weeks later...

Moved MagicHome to Polisy and things are not working so well.

I can only control devices successfully with programs and scenes but each of them must be run twice to set correct attributes when the device is off to begin with.

Off, Fast Off, Fast On, Query are working, On, Brighten and Dim do not, error: name 'brightness' is not defined.

Can't set a color value, reverts back in less than a second.

I did a manual install and it looked successful, only one warning: 

  WARNING: The script dotenv is installed in '/root/.local/bin' which is not on PATH.

  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Link to comment
Share on other sites

Glad this was created. Really enjoy being able to integrate with existing Insteon scenes.

Just added the one string of lights I had previous just sitting on the shelf unused.

No problem setting them up in the Polisy but I too am not getting them to come on at the brightness level commanded by the scene from an off state. 

Would love to find a way to set both the brightness and color when setting a scene. It looks like I can only choose one command.

Not a programmer so still trying to figure out how I might use a program to control extra settings when a scene is activated.

 

Link to comment
Share on other sites

@rossarmstrong In the scene, use the Change RGB or RGBW command to set the values. I use the MagicHome app to set the color then look at the values in ISY and set RGBW in the scene based on that.

You may need to execute the scene twice if you are on Polisy until the issue is I'm having is resolved.

Link to comment
Share on other sites

1 minute ago, rossarmstrong said:

Thanks!

Wasn't expecting the RGB values to change the brightness level. That now let's me associate the desired color and brightness level to a scene.

Are you using a program to have the scene activate twice?

I use a program or tell Alex to do it a second time. 

Link to comment
Share on other sites

OK. I am looking for a way to activate twice when the scene is activated with a keypad button.

This might also solve certain scenes where the device status "lies" until a Query is run. Not sure I want to build a program for every scene to force a query after every activation. But that is off topic.

 

Link to comment
Share on other sites

@markv58, I'm on a Polisy and I'm not seeing that issue.  I installed from the store without doing anything from the shell.  I created a scene, put two lights in it and it works the first time, every time, whether called directly or from a program.

  1. Do you see any errors in the log associated with that issue?
  2. Were you running earlier on a Pi or other box that didn't have the issue? 
  3. Have you tried uninstalling the node server and re-installing?

It had been a little while since I looked at this node server but I recently got some new lights and noticed some items I need to clean up.  The biggest issue I'm having is that the new lights I got are RGBWW but the underlying python package isn't reporting they have that capability so they don't get as bright as they should.  I think this is the same issue that @MWareman noted a little while ago.  It looks like that package hasn't been updated in quite some time so I'm hoping there's a newer fork available that has already reverse-engineered the protocol used by newer bulbs.

Link to comment
Share on other sites

@fahrer16 I was running on a Pi with no problems. I can't be sure that I didn't modify the code cause it has been a while, should have looked.

No errors and I believe the node was freshly installed when I restored to Polisy.

What happens is when the device is off, the first command issued does nothing visible or turns on at the previous value. The AC shows the device as on after the first command.

I can poke around in the code and see what I can figure out but it isn't a problem that needs immediate attention. Right in the middle of a major update to PiCamMonitor and I'm hearing warning sirens now, storms coming.

Link to comment
Share on other sites

@fahrer16 Starting from scratch on a RPi Poly.

Installing from the NodeServer Store, Polyglot log:

1/11/2020, 10:02:37 AM [polyglot] error: NSChild: MagicHome cloneRepo: Error: runInstallProcess: undefined

1/11/2020, 10:02:37 AM [polyglot] error: Error: runInstallProcess: undefined

    at runInstallProcess (/snapshot/polyglot-v2/lib/modules/children.js:45:11)

    at process._tickCallback (internal/process/next_tick.js:68:7)

1/11/2020, 10:02:37 AM [polyglot] error: NSResponse: Success: false - cloneRepo: Error: runInstallProcess: undefined

 

After adding Node, MagicHome log:

2020-01-11 10:04:58,463 [MainThread] [INFO ] Received Config from STDIN. 2020-01-11 10:04:58,464 [MainThread] [INFO ] UDI Polyglot v2 Interface 2.0.34 Starting...

2020-01-11 10:04:58,466 [MainThread] [ERROR] Traceback (most recent call last):

2020-01-11 10:04:58,467 [MainThread] [ERROR] File "./magichome.py", line 9, in <module>

2020-01-11 10:04:58,468 [MainThread] [ERROR] from flux_led import BulbScanner, WifiLedBulb

2020-01-11 10:04:58,468 [MainThread] [ERROR] ImportError

2020-01-11 10:04:58,468 [MainThread] [ERROR] :

2020-01-11 10:04:58,468 [MainThread] [ERROR] No module named 'flux_led'

Link to comment
Share on other sites

@markv58 what version of polyglot are you on?  I'm on 2.2.6, I've also updated from the terminal a few times using "sudo dpkg update" and "sudo dpkg upgrade".  I did have quite a bit of trouble with some other node servers early on with the Polisy with missing packages and the like but it's been pretty good recently.  

The node wouldn't work at all if you were really missing the flux_led package so that wouldn't explain the failing first attempt at changing the bulb.  One thought that just came to mind is whether your Polisy is on WiFi or wired ethernet.  The node server essentially sends out a packet blindly to the bulb's IP address and if it's on WiFi I could see that the first packet might get lost.  

I was just refreshing my memory on how the node server works and there's an option that might help you out.  In the configuration for the node server in polyglot you could create a key called "query_before_cmd" with a value of "True" (all without quotes).  That will query the state of the bulb before issuing the command to turn on; that might help with any communications issues to the bulb because it'll establish that connection before sending the command out.

Link to comment
Share on other sites

@fahrer16 Polisy is on 2.2.8, the Pi is on 2.2.9. On Polisy I did a manual install because I had the same problem and just figured something went wrong when I did the restore to move everything over from the Pi.

Polisy is wired so that's not it and I've tried with query True and False.

I'm also getting an error on Polisy when hitting Brighten and Dim:

2020-01-11 11:07:46,205 [Controller] [INFO ] Received BRT command on dc4f22c0c413

2020-01-11 11:07:46,206 [Controller] [ERROR] Error executing BRT command on dc4f22c0c413: name 'brightness' is not defined

2020-01-11 11:07:54,687 [Controller] [INFO ] Received BRT command on dc4f22c0c413

Link to comment
Share on other sites

@fahrer16

Did the manual install on Pi, nodeserver is running and am having the same issues.

If I turn the bulb on the Brightness reports 20% but no photons, hitting Set White 50 then photons. I can set R & G to any value but can only set B to 1- 255. Setting B to 0 turns off the bulb but leaves the value at the last state.

Link to comment
Share on other sites

44 minutes ago, sorka said:

Does anyone know how to set a static IP on the controller?

I use ip/Mac binding on my router. I don't think it is possible to set a static ip on these cheap little devices.

Link to comment
Share on other sites

I've been spending a little time looking into the node server with some bulbs I recently picked up on Amazon.  The bulbs I picked up are capable of warm white and cool white but they weren't getting added to the ISY with those capabilities. 

There's no public API for these bulbs and the python project used for this node server was developed a few years ago by someone who reverse-engineered the protocol from the magic home app using packet capture.  Unfortunately I have iOS so packet capture directly from the app isn't really an option for me.  I looked at the raw response from the bulbs using python on the Polisy and it has some differences from the original protocol.

The biggest issue I'm seeing is that the byte used to tell that the bulb is on or off is reversed from the original protocol.  A hex value of 0x23 used to mean that the bulb was off but it now appears to mean that the bulb was on.  It doesn't look like anybody has done any work to add these bulbs to the python project so I'll probably need to find some time to do a little bit more reverse engineering, at least to make the bulbs I have work.  It'll be tough because I can't capture the traffic from the app to the bulb to see what the commands should be... I should probably switch to Android at some point.

Here's the translation of what most of the bulbs' outputs look like based on the reverse-engineering that was done by the original project author:

        #pos  0  1  2  3  4  5  6  7  8  9 10 11 12 13
        #    81 25 23 61 21 06 38 05 06 f9 01 00 0f 9d
        #     |  |  |  |  |  |  |  |  |  |  |  |  |  |
        #     |  |  |  |  |  |  |  |  |  |  |  |  |  checksum
        #     |  |  |  |  |  |  |  |  |  |  |  |  color mode (f0 colors were set, 0f whites, 00 all were set)
        #     |  |  |  |  |  |  |  |  |  |  |  cold-white
        #     |  |  |  |  |  |  |  |  |  |  <don't know yet>
        #     |  |  |  |  |  |  |  |  |  warmwhite
        #     |  |  |  |  |  |  |  |  blue
        #     |  |  |  |  |  |  |  green
        #     |  |  |  |  |  |  red
        #     |  |  |  |  |  speed: 0f = highest f0 is lowest
        #     |  |  |  |  <don't know yet>
        #     |  |  |  preset pattern
        #     |  |  off(23)/on(24)
        #     |  type
        #     msg head

 

@markv58 If you'd like to see if the protocol from your bulb has the same issue, you could go to the terminal on your Polisy and enter the following after typing "python3":

from flux_led import WifiLedBulb
import binascii
bulb = WifiLedBulb('bulb_ip') #Insert the bulb's IP address here in place of bulb_ip
print(binascii.hexlify(bulb.query_state(2)))

If you could post the output while the bulb is on and off that would be great.  It would also be helpful to know whether your bulb has warm white and cold white capability.
 

You could also try some commands like bulb.turnOn() bulb.turnOff() bulb.setRgbw(255,255,255,255) to see if they work as expected.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Forum Statistics

    • Total Topics
      36.5k
    • Total Posts
      367.6k
×
×
  • Create New...