Code Monkey home page Code Monkey logo

udi-poly-kasa's Introduction

Build Status

kasa-polyglot

This is the TP Link Kasa Poly for the Universal Devices ISY994i Polyglot interface with Polyglot V2 (c) JimBoCA aka Jim Searle MIT license.

This node server is intended to support all devices supported by the pyHS100 Python Library

This nodeserver relies on a mostly undocumented and officially supported local API which of course TP-Link could break at any time.

Installation

This nodeserver will only work on a machine running on your local network, it will not work with Polyglot Cloud until TP-Link releases a public API for their cloud interface.

  1. Backup Your ISY in case of problems!
    • Really, do the backup, please
  2. Go to the Polyglot Store in the UI and install.
  3. Add NodeServer in Polyglot Web
  4. Open the admin console (close and re-open if you had it open) and you should see a new node 'Kasa Controller'
  5. The auto-discover should automatically run and find your devices and add them. Verify by checking the nodeserver log
    • While this is running you can view the nodeserver log in the Polyglot UI to see what it's doing

Usage

This node server makes every attempt to handle devices which are not responding for any reason, like they are unplugged or powered off. When a device is Discovered it is remembered, so if it doesn't respond on the next discovery it will still be an active device and when powered up it will be seen as connected.

The node server does not require that you reserve IP addresses for the devices, the device address is remembered based on it's MAC address, so if the IP address changes, it will be properly handled. (This has not been extensively tested, needs more verification)

Kasa Devices

Known working

The known list of supported devices models are:

  • HS100 (US)
  • HS110 (US)
  • HS300 (US)
  • KL110 (US)
  • KL120 (US)
    • Currently limited to on/off and brightness. Can not set temperature yet.
  • KL130 (US)
    • Currently limited to on/off and brightness. Can not set colors or temperature yet.

If you have another device not listed and it is working properly please let me know.

Unknown devices

All other simple plug and bulb devices should work, the nodeserver attempts to figure out the capabilities of the device instead of hardcoding based on the model. But if you have an issue please add to UDI Poly Kasa Issues Feel free to Fork this repo and add support as you like and send me a pull request.

Kasa Controller

This is the main node created by this nodeserver and manages the devices.

Node Drivers

The settings for this node are

Node Server Connected

  • Status of nodeserver process, this should be monitored by a program if you want to know the status

TODO: Devices

  • The number of devices currently managed

TODO: Debug Mode

  • The debug printing mode

TODO: Short Poll

  • This is how often it will Poll the Devices to get status

TODO: Long Poll

  • Updates other device status like emeter.

Node Commands

The commands for this node

Query

  • Poll's all devices and sets all status in the ISY

Discover

  • Run's the auto-discover to find your devices

Install Profile

  • This uploads the current profile into the ISY.
  • Typically this is not necessary, but sometimes the ISY needs the profile uploaded twice.

Kasa Devices

The supported Kasa devices can have different status and commands, but these are the common ones.

Node Drivers

The settings for this node are

Status (ST)

  • Status of device, on, off, or brightness.

Connected (GV0)

  • True if device is communicating

Node Commands

The commands for these nodes

Query

  • Poll's all devices and sets all status in the ISY

On, Off

  • Turn device on or off

Issues

If you have an issue where the nodes are not showing up properly, open the Polyglot UI and go to Kasa -> Details -> Log, and click 'Download Log Package' and send that to [email protected] as an email attachment, or send it in a PM Universal Devices Forum

Upgrading

Open the Polyglot web page, go to nodeserver store and click "Update" for "Kasa".

Then restart the Kasa nodeserver by selecting it in the Polyglot dashboard and select Control -> Restart, then watch the log to make sure everything goes well.

Release Notes

  • 2.5.0: 04/28/2021
  • 2.4.7: 12/10/2020
    • Check python version on startup
  • 2.4.6: 11/17/2020
  • 2.4.5: 11/16/2020
    • Many fixes for KL430 LED light strips
    • Fixes for Power on all devices
  • 2.4.4: 10/30/2020
    • Fixed bulb on off status
  • 2.4.3: 10/29/2020
    • SmartPlugStrip working better now
  • 2.4.2: 10/19/2020
    • SmartPlugStrip now working again
  • 2.4.1: 10/01/2020
    • Added Support for Smart Light Strip
  • 2.4.0: 08/15/2020
    • Issue 6 Convert to new python-kasa library
      • Currently must install manually: pip3 install --user python-kasa --pre --no-warn-script-location
      • And for Polyisy: sudo -u polyglot pip3 install --user python-kasa --pre --no-warn-script-location
    • Now requires Python 3.7 which is available on Polisy by default, but it means your RPi must be on Buster!
  • 2.3.3: 02/18/2020
    • Fixed #5
  • 2.3.2: 02/01/2020
    • Make sure bulb is on before adjusting other values. Temporary workaround to be fixed better later.
  • 2.3.1: 01/27/2020
    • Fix race condition between discover adding smart strip and shortPoll accessing it
    • Dim and Brighten should be working, although tested minimally
  • 2.3.0: 01/05/2020
    • Full Color control working on KL130
    • Small speed improvement when setting brightness and color temp at the same time.
  • 2.2.6: 01/02/2019
    • Controller long/short Poll runs in threads so main program is more responsive
  • 2.2.5: 12/31/2019
    • Moved main short/long poll into threads so main thread is more responsive
  • 2.2.4: 12/30/2019
    • KL110 and KL120 can be added to scenes, but still more functions to implement
  • 2.2.3: 12/27/2019
    • Add support for KL120 (Dimmable Color Temperature with Energy)
    • Switch to locally checked out pyHS100 with discovery fix for Polisy
  • 2.2.2 11/06/2019
    • Fix to reconnect to device that wasn't responding when nodeserver started
  • 2.2.1 10/15/2019
    • Fix crash when discover takes a long time to complete and devices are not yet initialized for shortPoll
  • 2.2.0 10/13/2019
    • Lot's of rework to allow supporting any Kasa device based on the capabilities instead of hardcoding the model names.
    • Set Brightness also working.
  • 2.1.1 10/01/2019
    • Remove from cloud
  • 2.1.0 09/21/2019
    • Merge changes from @eagleco to support plugs, thank you!
    • Fixed to work for those with emeter (HS110) and those without (HS100)
    • Adding support for SmartBulbs, only limited support currently.
  • 2.0.3 04/21/2019
    • Fixed controller naming, sorry if you are using this you will need to:
      • Go to Polyglot Web page
      • Update the Nodeserver in the Store
      • Delete the Nodeserver
      • Add it again
  • 2.0.2 03/29/2019
    • Fixed shortPoll to properly update
  • 2.0.1 03/28/2019
    • Update ST on shortPoll, added heartbeat
  • 2.0.0 03/27/2019
    • Initial version

udi-poly-kasa's People

Contributors

eagleco avatar einstein42 avatar exking avatar jimboca avatar

Stargazers

 avatar  avatar

Watchers

 avatar

udi-poly-kasa's Issues

Multi-Setters not working on light strips

The get_light_state/set_light_state from python-kasa are not working which is used when setting multiple drivers in one command so the change happens at once. Those functions are not working on a light strip. Will wait to see if that can be fixed, but if not will have to change to setting each driver individually.

KL125

How do I add KL125 to the nodeserver and ISY ?

Thanks

Some devices are not added to ISY because of illegal characters in Kasa device name

A device with a character that the ISY does not support prevents them from showing up in the ISY.

The code should filter any invalid characters from the device name (like [ ] ( ) < > \ / * ! & ? ; " ') before adding the Node to the ISY.

Of course, you can rename the nodes in the ISY as you like after they show up. But they have to show up first.

In example, if you name a device using the Kasa app to HDTV/Audio it will not show up in the ISY.

HS200 HW Ver 5.0 not supported.

Hey JimBo,

Just installed a new HS200 and it is not discovered by the KASA Nodeserver. Let me know what I can do to assist.

KP115 not Showing

I am trying to get a KP115 to show in the ISY Admin console but all I see is the "Kasa Controller" which is the only node showing in Polisy. I believe I followed the instructions correctly but it's been over an hour and the KP115 still doesn't show.

Steve

KL400L5 Not supported.

Hello JimBo,

Just received 2 KL400L5 strip lights. KASA Node server does not discover them. Let me know what I can do to assist.

LB120 only works with on/off

I was able to add the LB120 to Echo only after setting a hint. I've tried many 1.2.*.0 values, and all act the same. It allows for on and off, but it won't accept a brightness percentage. I tried setting the brightness in the Amazon app and through voice. Setting this manually in the ISY console works. Maybe a different hint is needed?

fresh install ubuntu 18.0.4

Hi,
I've tried installing several times and after successfully getting past the python3.7/pip issues I am still unable to get the node server started. The install.sh completes with no issues, but when I attempt to start the node server and consistently get, "polyinterface:write: No module named 'kasa'".

Your help is appreciated,

Heroildo

2021-04-03 13:04:24,801 MainThread polyinterface INFO polylogger:set_basic_config: set_basic_config: enable=True level=30
2021-04-03 13:04:25,249 MainThread polyinterface INFO polyinterface:init_interface: Received Config from STDIN.
2021-04-03 13:04:25,249 MainThread polyinterface INFO init:: UDI Polyglot v2 Interface 2.1.0 Starting...
2021-04-03 13:04:25,287 MainThread py.warnings WARNING warnings:_showwarnmsg: /usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
2021-04-03 13:04:25,287 MainThread py.warnings WARNING warnings:_showwarnmsg: /usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
2021-04-03 13:04:25,317 MainThread polyinterface ERROR polyinterface:write: Traceback (most recent call last):
2021-04-03 13:04:25,317 MainThread polyinterface ERROR polyinterface:write: File "./kasa-poly.py", line 11, in
2021-04-03 13:04:25,317 MainThread polyinterface ERROR polyinterface:write: from nodes import Controller
2021-04-03 13:04:25,317 MainThread polyinterface ERROR polyinterface:write: File "/root/.polyglot/nodeservers/Kasa/nodes/init.py", line 7, in
2021-04-03 13:04:25,317 MainThread polyinterface ERROR polyinterface:write: from .SmartDeviceNode import SmartDeviceNode
2021-04-03 13:04:25,317 MainThread polyinterface ERROR polyinterface:write: File "/root/.polyglot/nodeservers/Kasa/nodes/SmartDeviceNode.py", line 8, in
2021-04-03 13:04:25,317 MainThread polyinterface ERROR polyinterface:write: from kasa import SmartDeviceException
2021-04-03 13:04:25,317 MainThread polyinterface ERROR polyinterface:write: ModuleNotFoundError
2021-04-03 13:04:25,317 MainThread polyinterface ERROR polyinterface:write: :
2021-04-03 13:04:25,317 MainThread polyinterface ERROR polyinterface:write: No module named 'kasa'

Power Strip Plugs status reverts

I am having an issue where when I manually
turn off any of the plugs from the admin console the status reverts back
to 'on' even though the plug is still physically off. Example, I click
'off' for a plug in the admin console, the status shows 'off',

AttributeError: 'SmartBulb' object has no attribute 'set_state'

2020-02-17 17:35:48,403 [Controller] [ERROR] _parseInput: failed 68ff7b0554c0.runCmd(SET_CTBR) 'SmartBulb' object has no attribute 'set_state'
Traceback (most recent call last):
  File "/var/polyglot/.local/lib/python3.7/site-packages/polyinterface/polyinterface.py", line 846, in _parseInput
    self.nodes[input[key]['address']].runCmd(input[key])
  File "/var/polyglot/.local/lib/python3.7/site-packages/polyinterface/polyinterface.py", line 749, in runCmd
    fun(self, command)
  File "/var/polyglot/nodeservers/Kasa/nodes/SmartBulbNode.py", line 175, in cmd_set_color_temp_brightness
    self.dev.set_state()
AttributeError: 'SmartBulb' object has no attribute 'set_state'
2020-02-17 19:43:00,812 [shortPoll ] [ERROR] SmartBulb_DTNE:Test KL120:set_state: set_all_drivers failed: Communication error
Traceback (most recent call last):
  File "pyHS100/pyHS100/smartdevice.py", line 117, in _query_helper
    request=request,
  File "pyHS100/pyHS100/protocol.py", line 47, in query
    sock = socket.create_connection((host, port), timeout)
  File "/usr/local/lib/python3.7/socket.py", line 728, in create_connection
    raise err
  File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
socket.timeout: timed out

Traceback (most recent call last):
  File "/var/polyglot/nodeservers/Kasa/nodes/SmartDeviceNode.py", line 135, in set_state
    self.set_all_drivers()
  File "/var/polyglot/nodeservers/Kasa/nodes/SmartBulbNode.py", line 63, in set_all_drivers
    self.setDriver('CLITEMP',self.dev.color_temp)
  File "pyHS100/pyHS100/smartbulb.py", line 182, in color_temp
    if not self.is_on:
  File "pyHS100/pyHS100/smartbulb.py", line 296, in is_on
    return bool(self.state == self.BULB_STATE_ON)
  File "pyHS100/pyHS100/smartbulb.py", line 249, in state
    light_state = self.get_light_state()
  File "pyHS100/pyHS100/smartbulb.py", line 107, in get_light_state
    "get_light_state")
  File "pyHS100/pyHS100/smartdevice.py", line 120, in _query_helper
    raise SmartDeviceException('Communication error') from ex
pyHS100.smartdevice.SmartDeviceException: Communication error

Set RGB Color issue

Received PM from gzahar, see log files in PM

If the lights are on and I try to 'Set RGB Color' (either directly through AC or in a program), I have to send the command twice to get it to take effect. The first time the command is sent, the lights blink 'off' indicating the controller is seeing something, but the color stays the same. Then I send the command again, and it changes to the correct color. If I send an off command and then a 'Set RGB Color' command it also works.

Not a big problem to get around, but I've attached the log package if it helps. At 20:58:08 I sent the first command and the lights blink but don't change color. At 20:58:14, I resend the command and the lights change color.

When using the 'Set Color' option, it takes effect right away.

Thanks

HS103 v5 get "unpack requires a buffer of 4 bytes" error when trying to "discover"

HS103 v5 get "unpack requires a buffer of 4 bytes" error when trying to "discover"

2022-01-05 17:39:45,766 NodeServer polyinterface      WARNING  Controller:discover: Adding previously known device that didn't respond to discover: {'type': 'SmartPlug', 'name': 'PA Node Test', 'host': '192.168.1.68', 'mac': '00:5f:67:d4:c9:f2', 'model': 'HS103(US)', 'address': '005f67d4c9f2', 'emeter': False, 'id': 'SmartPlug_NN'}
2022-01-05 17:39:45,766 NodeServer polyinterface      INFO     Controller:add_node: adding SmartPlug 'PA Node Test' 005f67d4c9f2
2022-01-05 17:39:45,766 NodeServer polyinterface      DEBUG    SmartDeviceNode:__init__: PA Node Test: dev=None
2022-01-05 17:39:45,766 NodeServer polyinterface      DEBUG    SmartDeviceNode:__init__: PA Node Test: cfg={'type': 'SmartPlug', 'name': 'PA Node Test', 'host': '192.168.1.68', 'mac': '00:5f:67:d4:c9:f2', 'model': 'HS103(US)', 'address': '005f67d4c9f2', 'emeter': False, 'id': 'SmartPlug_NN'}
2022-01-05 17:39:45,766 NodeServer polyinterface      DEBUG    SmartDeviceNode:__init__: PA Node Test: controller=<nodes.Controller.Controller object at 0xf700962c> address=005f67d4c9f2 name=PA Node Test host=192.168.1.68
2022-01-05 17:39:45,766 NodeServer polyinterface      INFO     polyinterface:addNode: Adding node PA Node Test(005f67d4c9f2)
2022-01-05 17:39:45,766 NodeServer polyinterface      INFO     Controller:discover: done
2022-01-05 17:39:45,769 Controller polyinterface      DEBUG    SmartDeviceNode:connect: PA Node Test: connected=None
2022-01-05 17:39:45,769 Controller kasa.smartdevice   DEBUG    smartdevice:__init__: Initializing 192.168.1.68 of type <class 'kasa.smartplug.SmartPlug'>
2022-01-05 17:39:45,770 Controller polyinterface      DEBUG    SmartDeviceNode:update: PA Node Test: self.dev:<DeviceType.Plug at 192.168.1.68 - update() needed>
2022-01-05 17:39:45,770 Controller polyinterface      DEBUG    SmartDeviceNode:update: PA Node Test: asyncio.run
2022-01-05 17:39:45,770 Controller asyncio            DEBUG    selector_events:__init__: Using selector: EpollSelector
2022-01-05 17:39:45,798 Controller kasa.protocol      DEBUG    protocol:query: > (143) {"system": {"get_sysinfo": null}, "emeter": {"get_realtime": null, "get_monthstat": {"year": 2022}, "get_daystat": {"month": 1, "year": 2022}}}
2022-01-05 17:40:45,852 Controller kasa.protocol      DEBUG    protocol:query: Unable to query the device, retrying: unpack requires a buffer of 4 bytes
2022-01-05 17:40:45,859 Controller kasa.protocol      DEBUG    protocol:query: > (143) {"system": {"get_sysinfo": null}, "emeter": {"get_realtime": null, "get_monthstat": {"year": 2022}, "get_daystat": {"month": 1, "year": 2022}}}

I'm fairly sure (based on my limited Python abilities) the issue the is "protocol:query: Unable to query the device, retrying: unpack requires a buffer of 4 bytes" ... I'm assuming that it's just a case of "code change" by TPLink ...

My Polyglot has python-kasa 0.4.0 installed ... The device does respond to the test script:

# kasa --host 192.168.1.68 --plug sysinfo
== System info ==
{'active_mode': 'none',
 'alias': 'PA Node Test',
 'dev_name': 'Smart Wi-Fi Plug Mini',
 'deviceId': '8006E4CFFFEE6ABA49B2B2F2C90C8A791E5A7712',
 'err_code': 0,
 'feature': 'TIM',
 'hwId': 'B25CBC5351DD892EA69AB42199F59E41',
 'hw_ver': '5.0',
 'icon_hash': '',
 'latitude_i': 407337,
 'led_off': 0,
 'longitude_i': -736779,
 'mac': '00:5F:67:D4:C9:F2',
 'mic_type': 'IOT.SMARTPLUGSWITCH',
 'model': 'HS103(US)',
 'next_action': {'type': -1},
 'oemId': '211C91F3C6FA93568D818524FE170CEC',
 'on_time': 0,
 'relay_state': 0,
 'rssi': -33,
 'status': 'new',
 'sw_ver': '1.0.3 Build 201015 Rel.142523',
 'updating': 0}
# kasa --host 192.168.1.68 --plug on     
Turning on PA Node Test
# kasa --host 192.168.1.68 --plug off
Turning off PA Node Test

Let me know if you need more (or if you want me to send you a device and/or have Amazon send you one)

Thanks

@Shley

KP125M support

Hi, I was wondering if you plan to support the KP125M. It's a Matter device, but I am not using it with Matter; just as a legacy Kasa device.

I have a few HS300s and they work fine.

If you need a device to test with, I can send you one. You can also log on to my system.

Best Jim

Support switches and dimmers

A bunch of HS200 Switches that work as expected. Status updates in ISY - Cannot be set as controller in program/scene
HS220 Dimmer switches that work but only for On/Off - no status updates in ISY and can't be a controller in a scene/program

(I don't have any, so will take a while...)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.