Git Product home page Git Product logo

python-insteonplm's Introduction

insteonplm

Build Status GitHub release PyPI

This is a Python package to interface with an Insteon Modem. It has been tested to work with most USB or RS-232 serial based devices such as the 2413U, 2412S, 2448A7 and Hub models 2242 and 2245. Other models have not been tested but the underlying protocol has not changed much over time so it would not be surprising if it worked with a number of other models. If you find success with something, please let us know.

This insteonplm package was created primarily to support an INSTEON platform for the Home Assistant automation platform but it is structured to be general-purpose and should be usable for other applications as well.

Requirements

  • Python 3.5.3 or higher, 3.6 or 3.7
  • Posix or Windows based system
  • Some form of Insteon PLM or Hub
  • At least one Insteon device

Installation

You can, of course, just install the most recent release of this package using pip. This will download the more recent version from PyPI and install it to your host.

pip install insteonplm

If you want to grab the the development code, you can also clone this git repository and install from local sources:

cd python-insteonplm
pip install .

And, as you probably expect, you can live the developer's life by working with the live repo and edit to your heart's content:

cd python-insteonplm
pip install -e .

Device Permissions

Any user account that you want to be able to access the PLM will need permissions to access the USB or Serial device in /dev. In Linux, you'll probably want to do something like this:

sudo usermod -a -G dialout <username>

In FreeBSD, it'll be something like:

sudo pw usermod <username> -G dialer

You may find that you have to log out and log back in as that user for the change to take effect on existing sessions.

First Start

When the module starts it reads the IM's All-Link Database to find linked devices. In order for this module to communicate with a device, it must be linked to the IM. For help with linking please see the section on the Command Line Interface below.

After the module loads the All-Link database it queries each device to identify what type of device it is. This can take quite a while (5-15 sec per device). Once it identifies the devices it saves them in the WORKDIR so that future startups are faster.

Currently there is an issue with the command line Tools not finding battery operated devices since they don't respond to device information requests. This is being addressed in future releases. This is not an issue if used with Home Assistant through the use of device overrides.

Tools

The package installs a message monitor and a command line interface.

Message Monitoring

You can monitor messages flowing across your INSTEON network with the monitor command line tool. To invoke the monitor use the command:

insteonplm_monitor --device /dev/ttyUSB0 --workdir /home/username

Command line options for the monitor are:

-h, --help         show this help message and exit
--device DEVICE    Path to PLM device
--verbose, -v      Set logging level to verbose
--workdir WORKDIR  Working directory for reading and saving device
                   information.

Command Line Interface

The command line tool creates an interactive session to allow certain functions to be performed on the INSTEON devices. To invoke the command line tool use the command:

`insteonplm_interactive --device /dev/ttyUSB0 --workdir /home/username`

Command line options for the interactive tool are:

-h, --help        show this help message and exit
--device DEVICE   Path to PLM device
-v, --verbose     Set logging level to verbose
--workdir WORKDIR  Working directory for reading and saving device
                  information.

Inside the command line tool use help to obtain a list of available commands. The current list of available commands is:

-  add_all_link        Add an All-Link record to the IM and a device.
-  add_device_override Add a device override to the IM.
-  add_x10_device      Add an X10 device to the IM
-  connect             Connect to the IM
-  del_all_link        Delete an all link record from the IM and a device
-  exit                Exit the tool
-  help                List available commands
-  list_devices        Print a list of the available devices
-  load_aldb           Read and load a device All-Link database
-  on_off_test         Test a device with simple on/off commands
-  print_aldb          Print the All-Link database for a device
-  running_tasks       List tasks running in the background
-  set_device          Set the IM device path
-  set_log_level       Set the log message display level
-  set_workdir         Set the WORKDIR to load and save device info
-  write_aldb          Write a record to the device All-Link database
                           !!!! BE CAREFUL WITH THIS COMMAND !!!!!

For help with a specific command type help command_name.

Known Issues

How You Can Help

Development

  • First and foremost, you can help by forking this project and coding. Features, bug fixes, documentation, and sample code will all add tremendously to the quality of this project.
  • If you have a feature you'd love to see added to the project but you don't think that you're able to do the work, I'm someone is probably happy to perform the directed development in the form of a bug or feature bounty.

Testing, Feature Requests and Issue Identification

  • If you're anxious for a feature but it's not actually worth money to you, please open an issue here on Github describing the problem or limitation. If you never ask, it'll never happen

Documentation

Please see our Wiki section for documentation. This documentation is limited. If you would like to drive this effort please send a resume and a list of references to... Honestly, we will take anyone.

PLEASE help. An issue has been opened so just post your interest there.

Credits

Interesting Links

python-insteonplm's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar jborlik avatar lanrongwen avatar martinhjelmare avatar mstovenour avatar nugget avatar pvizeli avatar sarog avatar scop avatar teharris1 avatar wonderslug avatar wz2b avatar yombo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-insteonplm's Issues

Trouble getting things working

I am having a lot of fun telling Alexa to turn on and off my lights. Thanks for putting this library together. The only issue is that things stop working randomly. Things work great and then I will turn off a light and I see it the toggle in Home Assistant turn off, then back on (the physical light turns off). Once that happens then I know it is downhill. I can not turn the light back on because the interface toggle thinks it is currently on.
I did some troubleshooting by shutting down Home Assistant and running insteonplm_monitor --device /dev/ttyUSB0. I modified the tools.py file to simply turn on / or turn off the three lights I have connected. Sometimes it would work, but most of the time it would only make it through one or two lights. It seems like everything works reliably until I add a 3rd module.

Below is the console output from insteonplm_monitor.

A few things I have tried:

Factory Reset my 2413U as well as the 3 Insteon Dimmer modules.
Ensured that the modules are in the same room.
Re-Setup and tested my 2 Insteon Access Points.
I also briefly tested this out on my Raspberry Pi B+ thinking maybe the Model A is too slow. But I had the same issue.

Setup:

Raspberry Pi Model A
Clean Install of Hassbian (Linux hassbian 4.9.24+ #993 Wed Apr 26 17:56:54 BST 2017 armv6l GNU/Linux)
Insteon 2413U
Python 3.4.2
Master branch of python-insteonplm

Console output

I modified this some so that it would turn the module on, wait two seconds, then request the status of the module.
The main question I have is do you have any ideas why I am not consistently receiving the response to the status request while it is polling each device? This seems to be the first issue I see (hopefully close to the root cause). I restarted the Pi and re-ran this several times. Sometimes in the section where it is polling all devices in ALDB, I would receive the status for all 3, but most of the time I would only receive the status for the first one or the second. I suspect there is some buffer that is filling up. Any suggestions?

pi@hassbian:~ $ insteonplm_monitor --device /dev/ttyUSB0
INFO:insteonplm.tools:Connecting to Insteon PLM at /dev/ttyUSB0
INFO:insteonplm.connection:Connecting to PLM on /dev/ttyUSB0
INFO:insteonplm.protocol:New callback <function console.<locals>.async_insteonplm_light_callback at 0xb62b0150> with {} (0 items already in list)
INFO:insteonplm.protocol:Connection established to PLM
INFO:insteonplm.protocol:Requesting PLM Info
INFO:insteonplm.protocol:Requesting First ALL-Link Record
INFO:insteonplm.protocol:PLM Info from 13.AC.33: category:03 subcat:15 firmware:92
INFO:insteonplm.protocol:ALL-Link Record for 3E.94.10: flags:e2 group:01 data:01/0e/43
INFO:insteonplm.protocol:New INSTEON Device 3E.94.10: LampLinc Dual Band 2-pin (01:0e)
WARNING:insteonplm.tools:New Device: {'model': '2457D2', 'cat': 1, 'subcat': 14, 'product_key': None, 'address_hex': '3e9410', 'address': '3E.94.10', 'firmware': 67, 'capabilities': ['light', 'dimmable'], 'description': 'LampLinc Dual Band 2-pin'}
INFO:insteonplm.protocol:Requesting Next ALL-Link Record
INFO:insteonplm.protocol:ALL-Link Record for 3E.98.2D: flags:e2 group:01 data:01/0e/43
INFO:insteonplm.protocol:New INSTEON Device 3E.98.2D: LampLinc Dual Band 2-pin (01:0e)
WARNING:insteonplm.tools:New Device: {'model': '2457D2', 'cat': 1, 'subcat': 14, 'product_key': None, 'address_hex': '3e982d', 'address': '3E.98.2D', 'firmware': 67, 'capabilities': ['light', 'dimmable'], 'description': 'LampLinc Dual Band 2-pin'}
INFO:insteonplm.protocol:Requesting Next ALL-Link Record
INFO:insteonplm.protocol:ALL-Link Record for 01.89.44: flags:e2 group:01 data:01/07/37
INFO:insteonplm.protocol:New INSTEON Device 01.89.44: LampLinc Dimmer V2 2-pin (01:07)
WARNING:insteonplm.tools:New Device: {'model': '2856D2', 'cat': 1, 'subcat': 7, 'product_key': None, 'address_hex': '018944', 'address': '01.89.44', 'firmware': 55, 'capabilities': ['light', 'dimmable'], 'description': 'LampLinc Dimmer V2 2-pin'}
INFO:insteonplm.protocol:Requesting Next ALL-Link Record
INFO:insteonplm.protocol:ALL-Link database dump is complete
INFO:insteonplm.protocol:Polling all devices in ALDB
INFO:insteonplm.protocol:Requesting status for 01.89.44
INFO:insteonplm.protocol:Requesting status for 3E.94.10
INFO:insteonplm.protocol:Requesting status for 3E.98.2D
INFO:insteonplm.protocol:INSTEON device status 01.89.44 is at level 0x0
INFO:insteonplm.protocol:Device 018944.onlevel changed: None->0"
INFO:insteonplm.protocol:INSTEON device status 3E.94.10 is at level 0x0
INFO:insteonplm.protocol:Device 3e9410.onlevel changed: None->0"
INFO:insteonplm.tools:Jonathan, Are you ready to rumble?
INFO:insteonplm.tools:Relay Status
INFO:insteonplm.protocol:Requesting status for 3E.94.10
INFO:insteonplm.tools:Jonathan, Are you ready to rumble?
INFO:insteonplm.tools:Relay Status
INFO:insteonplm.protocol:Requesting status for 01.89.44
INFO:insteonplm.tools:Jonathan, Are you ready to rumble?
INFO:insteonplm.tools:Relay Status
INFO:insteonplm.protocol:Requesting status for 3E.98.2D

InsteonPLM Monitor crashes on launch.

Brand new installation (pip3 install insteonplm on python 3.5.3 on macOS Sierra using the Python.org macOS installer) and I get this when launches:

INFO:insteonplm.tools:Are you ready to rumble?
INFO:insteonplm.tools:Relay Status
ERROR:asyncio:Task exception was never retrieved
future: <Task finished coro=<console() done, defined at /Users/example/Developer/InsteonPLM/lib/python3.5/site-packages/insteonplm/tools.py:11> exception=KeyError()>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "/Users/example/Developer/InsteonPLM/lib/python3.5/site-packages/insteonplm/tools.py", line 134, in console
plm.status_request(addr)
File "/Users/example/Developer/InsteonPLM/lib/python3.5/site-packages/insteonplm/protocol.py", line 765, in status_request
device = self.devices[address.hex]
File "/Users/example/Developer/InsteonPLM/lib/python3.5/site-packages/insteonplm/protocol.py", line 40, in getitem
raise KeyError
KeyError
^CTraceback (most recent call last):
File "./bin/insteonplm_monitor", line 11, in
load_entry_point('insteonplm==0.7.4', 'console_scripts', 'insteonplm_monitor')()
File "/Users/example/Developer/InsteonPLM/lib/python3.5/site-packages/insteonplm/tools.py", line 145, in monitor
loop.run_forever()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/base_events.py", line 421, in run_forever
self._run_once()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/base_events.py", line 1388, in _run_once
event_list = self._selector.select(timeout)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/selectors.py", line 577, in select
kev_list = self._kqueue.control(None, max_ev, timeout)
KeyboardInterrupt

There are 2 unknown devices in the system - a FanLinc and a 2334 KeypadLinc (in case that matters).

Thanks in advance. Happy to provide any additional information you need.

Add support for IP PLM for old Hub

Hi,

Thank you for this component. I would like to know if it would be possible to add IP PLM support for the old Hub (2242). From what I understand (and checking the openhab component), it's the same protocol but over network instead of USB/RS232.

The reason is that the Insteon Local component in Home Assistant work by spamming the Hub to refresh it's state which is really not ideal. Also, the developer seems to have abandoned the project.

Thanks!

I/O Linc

I have added I/O Linc 2450 to my refactored code. If someone can validate it and let me know if it works please. Thanks.

I/O Linc relay (switch side) not appearing.

I have an I/O Linc used for a garage door opener. The sensor side appears, and I thought that in previous versions, if I clicked on the circle in the interface, it would toggle the relay (although I maybe mistaken about that). The relay side does not appear anywhere I can find in HASS, so while I can see the state sensor, I cannot control the relay.

Not sure what is wrong.

Problems running refactored code.

A few problems:

During setup:

2018-02-06 13:15:26 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform insteon_plm
Traceback (most recent call last):
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 189, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
return fut.result()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/futures.py", line 245, in result
raise self._exception
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/tasks.py", line 180, in _step
result = coro.send(None)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/coroutines.py", line 210, in coro
res = func(*args, **kw)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/lib/python3.6/site-packages/homeassistant/components/switch/insteon_plm.py", line 26, in async_setup_platform
_LOGGER.info('Registered %s with switch platform.', device.id)
AttributeError: 'dict' object has no attribute 'id'

While running:

2018-02-06 13:18:18 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/tasks.py", line 180, in _step
result = coro.send(None)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/python-insteonplm/insteonplm/devices/devicebase.py", line 164, in _wait_for_direct_ACK
callback(msg)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/python-insteonplm/insteonplm/states/sensor.py", line 196, in _status_message_received
self._status_message_received)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/python-insteonplm/insteonplm/messagecallback.py", line 59, in remove
cb = self._dict[msg]
KeyError: <insteonplm.messages.standardReceive.StandardReceive object at 0x1086f71d0>

Documentation

If you don't mind me pestering you occasionally for additional info and clarification I can work on getting documentation setup. The biggest thing I would need to get started is a working code example.

Add Support for 6-Button Keypad Dimmer (2334-292)

Was wondering if you are looking at or are willing to add support for 6-Button Keypad Dimmer (2334-292). Let me know what I could do to help. I'm more then happy to provide logs/debugging information.

I linked one button from my Keypad with my USB PLM and when I press it I see this in the homeassistant.log:

17-02-28 20:15:46 INFO (MainThread) [insteonplm.protocol] Processing message: b'02503d8ff8000003cf1300'
17-02-28 20:15:46 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback <bound method PLM._parse_insteon_standard of <insteonplm.protocol.PLM object at 0x2b73b84449b0>>
Traceback (most recent call last):
  File "uvloop/cbhandles.pyx", line 49, in uvloop.loop.Handle._run (uvloop/loop.c:48380)
  File "/usr/local/lib/python3.5/site-packages/insteonplm/protocol.py", line 492, in _parse_insteon_standard
    device = self.devices[msg.address.hex]
  File "/usr/local/lib/python3.5/site-packages/insteonplm/protocol.py", line 40, in __getitem__
    raise KeyError
KeyError

I am not famirial with python env.Ubuntu 16

marius@HPP:/CPP/python-insteonplm$ pip install .
Processing /home/marius/CPP/python-insteonplm
Collecting pyserial==3.2.0 (from insteonplm==0.9.1)
Using cached https://files.pythonhosted.org/packages/2c/c2/2a391a69730c05a646f27e71e965cf8a0e9ccd72c0f0b870b74d47f3c32b/pyserial-3.2-py2.py3-none-any.whl
Collecting pyserial-asyncio (from insteonplm==0.9.1)
Using cached https://files.pythonhosted.org/packages/d5/5e/518ace81b212db9a6458bf86ae9626c850bdc06ab133edd11f9b2a29ec47/pyserial_asyncio-0.4-py3-none-any.whl
Collecting async_timeout (from insteonplm==0.9.1)
Using cached https://files.pythonhosted.org/packages/1d/b9/213521db2918b5b7f7df333a33ea3d38ba70ba705d9db6c29f0343c213ea/async_timeout-2.0.1-py3-none-any.whl
Building wheels for collected packages: insteonplm
Running setup.py bdist_wheel for insteonplm ... done
Stored in directory: /home/marius/.cache/pip/wheels/6d/be/e2/64b09e0f501d6f92ca9f304326f0360f8e504febaf1e0233fc
Successfully built insteonplm
Installing collected packages: pyserial, pyserial-asyncio, async-timeout, insteonplm
Found existing installation: pyserial 3.0.1
Cannot uninstall 'pyserial'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
marius@HPP:
/CPP/python-insteonplm$

Test Cases

I was thinking, if we are going to go through the hassle of a refactor we can probably add a test framework. Any suggestions on a good one for python?

Enable/disable detached load

Enable the command line tool (and potentially the HA GUI) to enable/disable detached load in a device such as the KPL

Controlling a switch with Insteon link is not reflected in the HASS UI.

@teharris1 You wrote (in #44):

The other issue you are seeing, if I understand you correctly, is that state changes do not cascade along linked devices. In other words, if switchA controls switchB and switchB controls switchC, changes to switchA do not effect switchC. The PLM is like any other device. So the PLM can change the KPL the changes to the KPL don't cascade to the devices controlled by the KPL. This is by design in the Insteon model.

That is not the issue I am describing.

The most basic form of this is that if I turn on an Insteon device using an Insteon link, the HASS UI does not update.

For example:

Two SwitchLincs that have Insteon links between them. If I change the state on the SwitchLinc from the SwitchLinc, the HASS UI updates the state correctly. If I change the state by pushing the button on the other switch, the HASS UI does not update the state correctly.

Without this working, it means that the system will never know the state of a FanLinc's fan if it is controlled via a switch and/or a button/set of buttons on a KPL.

I think the code would need to understand the device links, so that when the PLM received a message from device X the system would know that device X was linked to devices Y, Z and A and set their states accordingly.

How to beta test prior to the Home Assistant Pull Request

Hi David. Imagine my luck: I just got my Insteon PLM a few days ago, began researching Python control for it, and BOOM -- up comes your repo!

My inspiration is twofold:

  1. Get rid of my stupid ISY99 controller, which demands that I upgrade Java on my laptop every time I want to do something with it, and
  2. Learn Python more, especially async i/o.

I'm currently waiting for the delivery of another RemoteLinc (2342-222) with which to experiment -- I can't remove any of my current controllers from service (i.e., linked to existing PLM) or I endure the wrath of the other user of our Insteon control system, iykwim. So at the moment I'm unable to generate any events to be received by the PLM, but that will change in a couple of days.

It looks like the next steps for this library might be something like making a (public) send_message() in protocol.py that understands the various Insteon message types? Curious about your thoughts on this.

Ultimately, my needs aren't very fancy: I have a system that uses Insteon almost exclusively for lighting, and all the lights are controlled via (sunset-offset, mostly) timers, with a few wired and wireless controllers around for all-units-off commands (bedside) and to control some small groups (which doesn't require any PLM interaction, really).

I got all of your code running on a CHIP (https://getchip.com/pages/chip), although I may end up with a Raspi because I think I have wired Ethernet where I need it.

Looking forward to seeing where this goes, and how I might be able to help!

IPDB not Identifying Device Types

In my testing I have found the IPDB isn't correctly identifying my devices. From what I can see it's basing it off the All_Link_Record lookup, but it always returns a generic 010000 code. Looks like we could possibly change it to do a lookup to get a list of devices, then send that list through a loop or something to do a Product Data Request on each one (which is supposed to return the device class) and then add them to self.devices array... Still learning my way around the code, so I'm not 100% sure if that would work.

Refactoring design decisions

The original code base is very good but has some challenges to implement more complex devices such as Thermostats or FanLinc devices. The goal of the refactoring effort is to remove these limitations and create a community driven architecture that is maintainable and extensible. Here are some jumping off questions to consider:

  1. Is this a generic Insteon management tool or an extension for Home Assistant? The current design objective states it is generic but there are a number of HA specific ideas built in.
  2. What is the role of the PLM class? Currently all messages and commands are managed and processed by PLM. How should we separate concerns and define other classes that make the handling of messages and commands easier?
  3. Do we employ Duck typing to messages or are they separate classes by message type? there are pros and cons here with meaningful design implications. Duck typing feels more Pythonesque and would simplify the creation of messages. However a single class for all message types may create a beast of a class that requires a lot of context specific logic.
  4. How do we accept commands from control modules like Home Assistant? Should these commands come into a command module similar to the way PLM does it today? An alternative is to have a control module call a device specific class such as DimmableLightingControl that processes the Light ON command. Pros and cons of each especially when considering device state management.
  5. How do we handle complex devices such as the FanLinc where the standard message controls the light dimmer but the fan control requires access to an extended message to control group 2. Do we create a separate device class, use duck typing or force the control module (aka Home Assistant) to map to the Insteon methods where all this module does is make the commands available without any consideration for the upstream use case?
    These are just a few topics. Feel free to add more and contribute.

At a total loss for the basic setup of a device

I am stuck trying to set up a device. I have the following in my configuration.yaml:
homeassistant:
customize:
light.330aXXX:
friendly_name: Garage Spot Light

insteon_plm:
port: /dev/ttyUSB0

But I cannot see the device in Home Assistant. what am I doing wrong? I do see an error in the log for "set_write_buffer_limits raise NotImplementedError" but that is all.

Add battery level support for Hidden Door Sensor (2845-222)

(Relocated from Issue #1) from @rstanley75

Did a little investigation into the OpenHAB binding and I discovered something.

From src/main/resources/device_features.xml:

<feature name="HiddenDoorSensorData">
	<message-dispatcher>SimpleDispatcher</message-dispatcher>
	<message-handler cmd="0x03" group="1">NoOpMsgHandler</message-handler>
	<message-handler cmd="0x11" group="1">NoOpMsgHandler</message-handler>
	<message-handler cmd="0x13" group="1">NoOpMsgHandler</message-handler>
	<message-handler cmd="0x2e">HiddenDoorSensorDataReplyHandler</message-handler>
	<command-handler command="OnOffType">NoOpCommandHandler</command-handler>
	<poll-handler>NoPollHandler</poll-handler>
</feature>

Then, from src/main/java/org/openhab/binding/insteonplm/internal/device/MessageHandler.java:

    public static class HiddenDoorSensorDataReplyHandler extends MessageHandler {
        HiddenDoorSensorDataReplyHandler(DeviceFeature p) {
            super(p);
        }

        @Override
        public void handleMessage(int group, byte cmd1, Msg msg, DeviceFeature f, String fromPort) {
            InsteonDevice dev = f.getDevice();
            if (!msg.isExtended()) {
                logger.trace("{} device {} ignoring non-extended msg {}", nm(), dev.getAddress(), msg);
                return;
            }
            try {
                int cmd2 = msg.getByte("command2") & 0xff;
                switch (cmd2) {
                    case 0x00: // this is a product data response message
                        int batteryLevel = msg.getByte("userData4") & 0xff;
                        int batteryWatermark = msg.getByte("userData7") & 0xff;
                        logger.debug("{}: {} got light level: {}, battery level: {}", nm(), dev.getAddress(),
                                batteryWatermark, batteryLevel);
                        m_feature.publish(new DecimalType(batteryWatermark), StateChangeType.CHANGED, "field",
                                "battery_watermark_level");
                        m_feature.publish(new DecimalType(batteryLevel), StateChangeType.CHANGED, "field",
                                "battery_level");
                        break;
                    default:
                        logger.warn("unknown cmd2 = {} in info reply message {}", cmd2, msg);
                        break;
                }
            } catch (FieldException e) {
                logger.error("error parsing {}: ", msg, e);
            }
        }
    }

It looks like it's sending cmd 2e and then getting the battery level from the User Data 4 byte of the extended-length response.

On page 9 from the dev docs:
hiddendoorpage9

I had originally interpreted that little bit on page 9 as returning the level at which the low battery level alert is tripped, but since I get convincingly accurate battery level info from OpenHAB perhaps Data 4 is the actual battery level and Data 7 is actually the level where the alert gets tripped?

Edit: Finally read the docs on Markdown formatting.

Add support for X10 powerline devices.

Yup, I said it. X10.

My house was built in 1937 so not everything is exactly what you would call up-to-code. As such, there are light switches that are still stuck in no-neutral-wire hell (and likely will be for quite some time). I have a few lingering X10 devices in my house. While it would be wonderful to purge my life of these awful things, for the time being I seem to be stuck with them. As much as I despise these devices it would be really nice if I had a way to control them.

Potential difficulties as I see them:

  • A whole different set of weird communication parameters. For example, two messages must be transmitted to send one command.
  • Few X10 devices support two-way communication, meaning we can't rely on the these devices to tell us whether or not they've changed state or respond to any requests as to their state.
  • We can't get a list of X10 devices from the PLM so the device addresses will need to be added manually in the config file.

Auto Discovery

The ALL-Link response record 0x57 does not consistently return the cat, subcat or firmware information. According to the developers guide this is device dependent. I have seven different device types and only one (motion sensor) returns the cat, subcat and firmware versions.

A command was added in 2007 code 0x50 cmd1 0x03 cmd2 0x00 which will return the product data, however this only works on 1 of my seven devices. The command that produces the most consistent result is code 0x50 cmd1 0x10 cmd2 0x00. This works on five of my seven devices. The ones it does not work on are both battery operated so it is possible it works on them as well but that they do not respond to requests until they wake. I have not been able to test this sufficiently yet.

KeyError - When sensor (Door is open/closed)

Hi
Any idea why i get this error when door sensor is triggered - open or close.
Running latest HomeAssistant on Raspbian with Insteon PLM.

2017-08-22 22:40:07 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback PLM._parse_insteon_standard(address: 2D.B...\xcf\x11\x01'))
Traceback (most recent call last):
File "/usr/lib/python3.4/asyncio/events.py", line 120, in _run
self._callback(*self._args)
File "/srv/homeassistant/lib/python3.4/site-packages/insteonplm/protocol.py", line 508, in _parse_insteon_standard
device = self.devices[msg.address.hex]
File "/srv/homeassistant/lib/python3.4/site-packages/insteonplm/protocol.py", line 40, in getitem
raise KeyError
KeyError

2017-08-22 22:40:08 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback PLM._parse_insteon_standard(address: 2D.B...e3kE\x11\x01'))
Traceback (most recent call last):
File "/usr/lib/python3.4/asyncio/events.py", line 120, in _run
self._callback(*self._args)
File "/srv/homeassistant/lib/python3.4/site-packages/insteonplm/protocol.py", line 508, in _parse_insteon_standard
device = self.devices[msg.address.hex]
File "/srv/homeassistant/lib/python3.4/site-packages/insteonplm/protocol.py", line 40, in getitem
raise KeyError
KeyError

What would it take...

I like the work that has been done so far, but I see many of my devices not showing up. I'd like to help even if I have limited time and my Python is a bit rusty... I have thermostats, open close sensors, dimmers, on/off switches that I can test against...

Typo in the code....

I got this error:

2018-01-30 19:32:48 INFO (MainThread) [homeassistant.components.light.insteon_plm] Received update calback from PLM for 264bce
2018-01-30 19:32:49 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback PLM._handle_standard_or_extended_message_received(<insteonplm.m...t 0x105d73898>)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 127, in _run
self._callback(*self._args)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/lib/python3.6/site-packages/insteonplm/plm.py", line 274, in _handle_standard_or_extended_message_received
device.receive_message(msg)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/lib/python3.6/site-packages/insteonplm/devices/dimmableLightingControl.py", line 194, in receive_message
super().receive_message(msg)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/lib/python3.6/site-packages/insteonplm/devices/dimmableLightingControl.py", line 72, in receive_message
super().receive_message(msg)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/lib/python3.6/site-packages/insteonplm/devices/devicebase.py", line 94, in receive_message
callback(msg)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/lib/python3.6/site-packages/insteonplm/devices/dimmableLightingControl.py", line 244, in _light_off_command_received
device2.ligth_status_request()
AttributeError: 'DimmableLightingControl_2475F' object has no attribute 'ligth_status_request'
2018-01-30 19:32:49 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback PLM._handle_standard_or_extended_message_received(<insteonplm.m...t 0x105d73978>)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 127, in _run
self._callback(*self._args)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/lib/python3.6/site-packages/insteonplm/plm.py", line 274, in _handle_standard_or_extended_message_received
device.receive_message(msg)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/lib/python3.6/site-packages/insteonplm/devices/dimmableLightingControl.py", line 194, in receive_message
super().receive_message(msg)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/lib/python3.6/site-packages/insteonplm/devices/dimmableLightingControl.py", line 72, in receive_message
super().receive_message(msg)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/lib/python3.6/site-packages/insteonplm/devices/devicebase.py", line 94, in receive_message
callback(msg)
File "/Users/majortomlocal/Developer/InsteonPLM-teharris/lib/python3.6/site-packages/insteonplm/devices/dimmableLightingControl.py", line 244, in _light_off_command_received
device2.ligth_status_request()
AttributeError: 'DimmableLightingControl_2475F' object has no attribute 'ligth_status_request'
2018-01-30 19:32:50 INFO (MainThread) [homeassistant.components.light.insteon_plm] Received update calback from PLM for 216a65

I would guess the two bolded parts are the problem. :-D

Multiple monitor command line problems

I'm using Ubuntu 14.04, python3.4, and clone of the repo on 2017/09/09 and hit several problems. Brand new PLM USB modem and I hit it with a factory reset just to be sure it's clean. I have 1 lamp module plugged in and linked (both directions) to the modem.

Problem 1: Run the insteonplm_monitor with -h and it throws an exception.

./bin/insteonplm_monitor --help
usage: insteonplm_monitor [-h] [--device DEVICE] [--verbose]

Connect to receiver and show events as they occur. Pulls the following
arguments from the command line (not method arguments): :param device: Unix
device where the PLM is attached :param verbose: Show debug logging.

optional arguments:
  -h, --help       show this help message and exit
  --device DEVICE  Device
  --verbose, -v
Task exception was never retrieved
future: <Task finished coro=<console() done, defined at /opt/homeassistant/lib/python3.4/site-packages/insteonplm/tools.py:11> exception=SystemExit(0,)>
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/base_events.py", line 276, in run_forever
    self._run_once()
  File "/usr/lib/python3.4/asyncio/base_events.py", line 1172, in _run_once
    handle._run()
  File "/usr/lib/python3.4/asyncio/events.py", line 120, in _run
    self._callback(*self._args)
  File "/usr/lib/python3.4/asyncio/tasks.py", line 238, in _step
    result = next(coro)
  File "/opt/homeassistant/lib/python3.4/site-packages/insteonplm/tools.py", line 26, in console
    args = parser.parse_args()
  File "/usr/lib/python3.4/argparse.py", line 1737, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib/python3.4/argparse.py", line 1769, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib/python3.4/argparse.py", line 1975, in _parse_known_args
    start_index = consume_optional(start_index)
  File "/usr/lib/python3.4/argparse.py", line 1915, in consume_optional
    take_action(action, args, option_string)
  File "/usr/lib/python3.4/argparse.py", line 1843, in take_action
    action(self, namespace, argument_values, option_string)
  File "/usr/lib/python3.4/argparse.py", line 1026, in __call__
    parser.exit()
  File "/usr/lib/python3.4/argparse.py", line 2382, in exit
    _sys.exit(status)
SystemExit: 0

Problem 2: Ran with no arguments and it opens /dev/ttyUSB0. It would help if that default was in the help docs (or just make the device a required input) since my device isn't plugged in to /dev/ttyUSB0. I have an alarmdecoder (ad2usb) module plugged in on USB0. Yet it looks like it's reporting insteon devices and sounds like it's talking to the modem. Note that I don't have an insteon thermostat so I'm not sure why it's reporting one. Then it throws an exception with a message that isn't enough for me to figure out what's going on.

INFO:insteonplm.tools:Connecting to Insteon PLM at /dev/ttyUSB0
INFO:insteonplm.protocol:New INSTEON Device 3C.4F.C5: Thermostat (05:0b)
INFO:insteonplm.protocol:New INSTEON Device 43.AF.9B: ToggleLinc Relay (02:1a)
INFO:insteonplm.connection:Connecting to PLM on /dev/ttyUSB0
INFO:insteonplm.protocol:New callback <function console.<locals>.async_insteonplm_light_callback at 0x7eff049d3ae8> with {} (2 items already in list)
INFO:insteonplm.protocol:retroactive callback device 43.AF.9B matching {}
WARNING:insteonplm.tools:New Device: {'address_hex': '43af9b', 'capabilities': ['switch'], 'model': '2466SW', 'subcat': 26, 'product_key': None, 'description': 'ToggleLinc Relay', 'cat': 2, 'address': '43.AF.9B', 'firmware': 0}
INFO:insteonplm.protocol:retroactive callback device 3C.4F.C5 matching {}
WARNING:insteonplm.tools:New Device: {'address_hex': '3c4fc5', 'capabilities': ['climate'], 'model': '2441TH', 'subcat': 11, 'product_key': None, 'description': 'Thermostat', 'cat': 5, 'address': '3C.4F.C5', 'firmware': 0}
INFO:insteonplm.protocol:Connection established to PLM
INFO:insteonplm.protocol:Requesting PLM Info
INFO:insteonplm.protocol:Requesting First ALL-Link Record
INFO:insteonplm.tools:Are you ready to rumble?
INFO:insteonplm.tools:Relay Status
ERROR:asyncio:Task exception was never retrieved
future: <Task finished coro=<console() done, defined at /opt/homeassistant/lib/python3.4/site-packages/insteonplm/tools.py:11> exception=KeyError()>
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 238, in _step
    result = next(coro)
  File "/opt/homeassistant/lib/python3.4/site-packages/insteonplm/tools.py", line 134, in console
    plm.status_request(addr)
  File "/opt/homeassistant/lib/python3.4/site-packages/insteonplm/protocol.py", line 839, in status_request
    device = self.devices[address.hex]
  File "/opt/homeassistant/lib/python3.4/site-packages/insteonplm/protocol.py", line 40, in __getitem__
    raise KeyError
KeyError

Problem 3: Ran with the correct USB device and I got multiple exceptions, none of which I can figure out anything about.

 ./bin/insteonplm_monitor --device /dev/ttyUSB2
INFO:insteonplm.tools:Connecting to Insteon PLM at /dev/ttyUSB2
INFO:insteonplm.protocol:New INSTEON Device 3C.4F.C5: Thermostat (05:0b)
INFO:insteonplm.protocol:New INSTEON Device 43.AF.9B: ToggleLinc Relay (02:1a)
INFO:insteonplm.connection:Connecting to PLM on /dev/ttyUSB2
INFO:insteonplm.protocol:New callback <function console.<locals>.async_insteonplm_light_callback at 0x7fdda31f4ae8> with {} (2 items already in list)
INFO:insteonplm.protocol:retroactive callback device 3C.4F.C5 matching {}
WARNING:insteonplm.tools:New Device: {'cat': 5, 'address': '3C.4F.C5', 'address_hex': '3c4fc5', 'subcat': 11, 'model': '2441TH', 'capabilities': ['climate'], 'product_key': None, 'firmware': 0, 'description': 'Thermostat'}
INFO:insteonplm.protocol:retroactive callback device 43.AF.9B matching {}
WARNING:insteonplm.tools:New Device: {'cat': 2, 'address': '43.AF.9B', 'address_hex': '43af9b', 'subcat': 26, 'model': '2466SW', 'capabilities': ['switch'], 'product_key': None, 'firmware': 0, 'description': 'ToggleLinc Relay'}
INFO:insteonplm.protocol:Connection established to PLM
INFO:insteonplm.protocol:Requesting PLM Info
INFO:insteonplm.protocol:Requesting First ALL-Link Record
INFO:insteonplm.protocol:PLM Info from 44.85.11: category:03 subcat:15 firmware:9e
INFO:insteonplm.protocol:ALL-Link Record for 3A.29.84: flags:e2 group:01 data:01/0e/43
INFO:insteonplm.protocol:Auto Discovering device '3a2984'.
INFO:insteonplm.protocol:New INSTEON Device 3A.29.84: LampLinc Dual Band 2-pin (01:0e)
WARNING:insteonplm.tools:New Device: {'cat': 1, 'address': '3A.29.84', 'address_hex': '3a2984', 'subcat': 14, 'model': '2457D2', 'capabilities': ['light', 'dimmable'], 'product_key': None, 'firmware': 67, 'description': 'LampLinc Dual Band 2-pin'}
INFO:insteonplm.protocol:Requesting Next ALL-Link Record
INFO:insteonplm.protocol:ALL-Link Record for 3A.29.84: flags:a2 group:01 data:01/0e/43
INFO:insteonplm.protocol:Device '3a2984' is already added manually.
INFO:insteonplm.protocol:Requesting Next ALL-Link Record
INFO:insteonplm.protocol:ALL-Link database dump is complete
INFO:insteonplm.protocol:Requesting product data for 3A.29.84
INFO:insteonplm.protocol:Requesting product data for 3C.4F.C5
INFO:insteonplm.protocol:Requesting product data for 43.AF.9B
INFO:insteonplm.protocol:Failed to discover device '3c4fc5'.
INFO:insteonplm.protocol:Failed to discover device '43af9b'.
INFO:insteonplm.protocol:Polling all devices in ALDB
INFO:insteonplm.protocol:Requesting status for 3A.29.84
INFO:insteonplm.protocol:Requesting status for 3C.4F.C5
INFO:insteonplm.protocol:Requesting status for 43.AF.9B
INFO:insteonplm.protocol:INSTEON standard 3A.29.84->44.85.11: cmd1:03 cmd2:00 flags:20
ERROR:asyncio:Exception in callback PLM._parse_insteon_standard(address: 3A.2..., flagsval: 32)
handle: <Handle PLM._parse_insteon_standard(address: 3A.2..., flagsval: 32)>
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/events.py", line 120, in _run
    self._callback(*self._args)
  File "/opt/homeassistant/lib/python3.4/site-packages/insteonplm/protocol.py", line 525, in _parse_insteon_standard
    self._parse_product_data_response(msg.address, msg.userdata)
  File "/opt/homeassistant/lib/python3.4/site-packages/insteonplm/protocol.py", line 640, in _parse_product_data_response
    category = userdata[4]
IndexError: bytearray index out of range
INFO:insteonplm.tools:Are you ready to rumble?
INFO:insteonplm.tools:Relay Status
ERROR:asyncio:Task exception was never retrieved
future: <Task finished coro=<console() done, defined at /opt/homeassistant/lib/python3.4/site-packages/insteonplm/tools.py:11> exception=KeyError()>
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 238, in _step
    result = next(coro)
  File "/opt/homeassistant/lib/python3.4/site-packages/insteonplm/tools.py", line 134, in console
    plm.status_request(addr)
  File "/opt/homeassistant/lib/python3.4/site-packages/insteonplm/protocol.py", line 839, in status_request
    device = self.devices[address.hex]
  File "/opt/homeassistant/lib/python3.4/site-packages/insteonplm/protocol.py", line 40, in __getitem__
    raise KeyError
KeyError

Digging around in the code, it looks like the lamp and thermostat are hard coded in tools.py:140. Why is that?

Add support for 240v Load Controler (2477SA1) and ON/OFF Switch (2477S)

I'm trying to add support for 240v Load Controler 2477SA1 and do a PR but something odd is happening when I test.

I added this line to the ipdb.py:
Product(0x09, 0x0a, 0x000041, '240v Load Controler ', '2477SA1', ['switch']),

I end up with both the 2477SA1 and the 2477S identifying as 240v Load Controler.

Logs for 2477SA1:

17-04-22 09:30:04 INFO (MainThread) [insteonplm.protocol] ALL-Link Record for 2E.8B.AF: flags:a2 group:01 data:00/00/00
17-04-22 09:30:04 INFO (MainThread) [insteonplm.protocol] ALL-Link Record for 2E.8B.AF: flags:e2 group:01 data:09/0a/41
17-04-22 09:30:04 INFO (MainThread) [insteonplm.protocol] New INSTEON Device 2E.8B.AF: 240v Load Controler (09:0a)
17-04-22 09:30:04 INFO (MainThread) [homeassistant.components.insteon_plm] New INSTEON PLM device: 2E.8B.AF (2e8baf) ['switch']
17-04-22 09:30:04 INFO (MainThread) [homeassistant.core] Bus:Handling <Event platform_discovered[L]: platform=insteon_plm, discovered=[{'description': '240v Load Controler', 'subcat': 10, 'model': '2477SA1', 'address_hex': '2e8baf', 'address': '2E.8B.AF', 'firmware': 65, 'capabilities': ['switch'], 'product_key': 65, 'cat': 9}], service=load_platform.switch>
17-04-22 09:30:04 INFO (MainThread) [homeassistant.components.switch.insteon_plm] Registered 2E.8B.AF with switch platform.
17-04-22 09:30:04 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, new_state=<state switch.2e8baf=off; friendly_name=2E.8B.AF, Firmware=0x41, Cagegory=0x9, Model=2477SA1, Subcategory=0xa, Description=240v Load Controler, Product Key=65, INSTEON Address=2E.8B.AF @ 2017-04-22T09:30:04.882958-04:00>, entity_id=switch.2e8baf>
17-04-22 09:30:04 INFO (MainThread) [insteonplm.protocol] Requesting status for 2E.8B.AF
17-04-22 09:30:06 INFO (MainThread) [insteonplm.protocol] INSTEON device status 2E.8B.AF is at level 0xff
17-04-22 09:30:06 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state switch.2e8baf=off; friendly_name=2E.8B.AF, Firmware=0x41, Cagegory=0x9, Model=2477SA1, Subcategory=0xa, Description=240v Load Controler, Product Key=65, INSTEON Address=2E.8B.AF @ 2017-04-22T09:30:04.882958-04:00>, new_state=<state switch.2e8baf=on; friendly_name=2E.8B.AF, Firmware=0x41, Cagegory=0x9, Model=2477SA1, Subcategory=0xa, Description=240v Load Controler, Product Key=65, INSTEON Address=2E.8B.AF @ 2017-04-22T09:30:06.617403-04:00>, entity_id=switch.2e8baf>

Logs for 2477S:

17-04-22 09:30:04 INFO (MainThread) [insteonplm.protocol] ALL-Link Record for 3D.25.74: flags:a2 group:01 data:09/0a/41
17-04-22 09:30:04 INFO (MainThread) [insteonplm.protocol] New INSTEON Device 3D.25.74: 240v Load Controler (09:0a)
17-04-22 09:30:04 INFO (MainThread) [homeassistant.components.insteon_plm] New INSTEON PLM device: 3D.25.74 (3d2574) ['switch']
17-04-22 09:30:04 INFO (MainThread) [homeassistant.core] Bus:Handling <Event platform_discovered[L]: platform=insteon_plm, discovered=[{'description': '240v Load Controler', 'subcat': 10, 'model': '2477SA1', 'address_hex': '3d2574', 'address': '3D.25.74', 'firmware': 65, 'capabilities': ['switch'], 'product_key': 65, 'cat': 9}], service=load_platform.switch>
17-04-22 09:30:04 INFO (MainThread) [homeassistant.components.switch.insteon_plm] Registered 3D.25.74 with switch platform.
17-04-22 09:30:04 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, new_state=<state switch.3d2574=off; friendly_name=3D.25.74, Firmware=0x41, Cagegory=0x9, Model=2477SA1, Subcategory=0xa, Description=240v Load Controler, Product Key=65, INSTEON Address=3D.25.74 @ 2017-04-22T09:30:04.913668-04:00>, entity_id=switch.3d2574>
17-04-22 09:30:04 INFO (MainThread) [insteonplm.protocol] ALL-Link Record for 3D.25.74: flags:e2 group:01 data:02/2a/45
17-04-22 09:30:04 INFO (MainThread) [insteonplm.protocol] Requesting status for 3D.25.74
17-04-22 09:30:06 INFO (MainThread) [insteonplm.protocol] INSTEON device status 3D.25.74 is at level 0x0
17-04-22 09:30:06 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state switch.3d2574=off; friendly_name=3D.25.74, Firmware=0x41, Cagegory=0x9, Model=2477SA1, Subcategory=0xa, Description=240v Load Controler, Product Key=65, INSTEON Address=3D.25.74 @ 2017-04-22T09:30:04.913668-04:00>, new_state=<state switch.3d2574=off; friendly_name=3D.25.74, Firmware=0x45, Cagegory=0x2, Model=2477SA1, Subcategory=0x2a, Description=240v Load Controler, Product Key=65, INSTEON Address=3D.25.74 @ 2017-04-22T09:30:04.913668-04:00>, entity_id=switch.3d2574>

Also I see this entry:
Product(0x02, 0x2a, None, 'SwitchLinc Switch', '2477S', ['light']),
Which I think should match the 2477S but does not match it as it was undetected before I added the config for the 2477SA1.

If you can let me know what I did wrong I'll test and create a PR for you.

Thanks, Shawn

Problems with controlling KeyPadLinc from the HASS UI.

I have been trying to understand exactly what is happening, but from what I can tell there are problems with controlling KeyPadLincs using the HASS UI when they have links to other devices.

I have a newly installed KPL with no links other than to the PLM. From the UI I can control it with no problem. If I turn it on, manually, it updates the UI (only seems to update the switch position, not the light icon but that is the same for all switches).

The SwitchLincs work fine from the UI and update the UI when controlled locally. When controlled by a linked button on a KPL, the UI does not update despite there being a link to the PLM from the button. (This goes to the link management issue #38 I raised earlier.)

If I try to control any of my KPLs that have links to other devices, I can change their state one time, but then the UI restores the original state (meaning that UI changes back to the original state, leaving the device in the new state) and from that point further I cannot control the device from the UI until I change its state locally. Changing its state locally, seems to reset it for a single use from the UI.

Create interactive command line tool

Create an interactive command line tool that allows users to complete some basic tasks:

  • Connect to PLM/Hub
  • List devices
  • Put the IM in All-Link mode as controller or responder
  • Read a device All-Link database
  • Write to a device All-Link database
  • Test basic device commands (On/Off)

Windows support

Just wondering - what is limiting the Window support? I'm currently using a similar project from years ago to control a few lights. (https://sourceforge.net/projects/pylights/)

Seems like they use the same Serial library, though I'd rather move to a maintained project, but the lack of Windows support is stopping that.

Saving the results of auto-discovery.

It would be nice to be able to save the results of auto-discovery, so that Home Assistant would start faster. It could still do auto-discovery but at least would have all the devices previously discovered.

Thermostat Controls.

While I can't start right away, I am looking at adding support for the 2441TH Thermostat. From what I can tell, it looks like it 1) Uses both standard and extended messages 2) uses different Groups to control the heating, cooling, general info, etc. So this could be fun. Open to any help, suggestions, etc along the way...

InsteonPLM fails with pyserial version > 3.2.0

When I upgraded to the most recent Home Assistant 0.49.1 I started to get an error that insteon_plm could not be configured, with this in the home-assistant.log

2017-07-26 22:26:22 ERROR (MainThread) [homeassistant.setup] Error during setup of component insteon_plm
Traceback (most recent call last):
  File "/opt/hass/lib/python3.4/site-packages/homeassistant/setup.py", line 187, in _async_setup_component
    result = yield from component.async_setup(hass, processed_config)
  File "/opt/hass/lib/python3.4/site-packages/homeassistant/components/insteon_plm.py", line 44, in async_setup
    import insteonplm
  File "/home/hass/.homeassistant/deps/insteonplm/__init__.py", line 6, in <module>
    from .connection import Connection      # noqa: F401
  File "/home/hass/.homeassistant/deps/insteonplm/connection.py", line 5, in <module>
    import serial.aio
  File "/home/hass/.homeassistant/deps/serial/aio.py", line 20, in <module>
    import logger
ImportError: No module named 'logger'

I tried downgrading Home Assistant to 0.48.1 which was working previously but I kept getting the same error. In a moment of desperation I tried a fresh install of Home Assistant 0.48.1 in a new container to no avail.

So I started digging and found this in the changelog for pyserial (https://github.com/pyserial/pyserial/blob/master/CHANGES.rst)

Version 3.2.1 2016-10-14

Improvements:

remove serial.aio in favor of separate package, pyserial-asyncio

I don't know what the heck it means, except the error references aio.py. I tried pyserial v3.2.0:

pip3 install --upgrade pyserial==3.2.0 --target ~/.homeassistant/deps
hass -skip-pip

To my amazement insteon_plm started working again! To be sure I tried one iteration more recent:

pip3 install --upgrade pyserial==3.2.1 --target ~/.homeassistant/deps

insteon_plm failed with version 3.2.1.

Forcing the downgrade to pyserial 3.2.0 seems to be a valid workaround for now. This is where I'm lost, as I have no idea where to proceed from here to fix the issue in insteon_plm itself.

Add support for 2448A7 USB Stick

Looking at the spec it appears that the package should be able to work with the single-band (wireless only) USB stick interface.

Bump version - refactored code meaningfully ready

My refactoring efforts are done I believe. I have a lot of documentation to write and there are still some open issues (small I think). But I am proposing that the latest code become version 0.8.0. To test the latest code you need to download insteonplm and home-assistant. From Home Assistant, you really only need to replace the 5 insteon_plm.py files located in

  • components/insteon_plm.py,
  • components/light/insteon_plm.py,
  • components/switch/insteon_plm.py
  • components/binary_sensors/insteon_plm.py
  • components/fan/insteon_plm.py

Get Next All-Link Record returns NAK too early

There is a fundamental issue in Insteon where the indication of the last PLM ALDB record is a NAK message. However, the NAK message can occur simply because the PLM is not ready rather than actually reaching the last record. When this occurs there is no way to tell the difference.

Temporary solution is to allow devices to be added from the saved device file or from the device override option. This will ensure devices are found every time. The downside of this approach is that a device that is not in the ALDB could be added this way and appear to work when it does not. This may cause user confusion. A better approach needs to be found but this option is better than not finding the device at all.

Fast ON/OFF

Does this library support Insteon's FAST ON/OFF functionality of the dimmer switches?
Eg. the event when a user double-clicks/taps the switch up or down.

insteonplm hangs while doing initial discovery

I'm attaching 3 separate attempts to run Home Assistant. All of them end in the same way hanging on initial device polling.

The log settings were as follows:

logger:
  logs:
    aiohttp.server: critical
    insteonplm: debug
    homeassistant: critical

Configuration:

insteon_plm:
  port: /dev/ttyUSB0

Not sure what else to add at this point. Please don't hesitate to ask for more info.

run1.txt
run2.txt
run3.txt

Support PLM 2413s

Indications are that the 2413s is not supported. This thread will focus on debugging and resolving the issue.

Add support for Insteon link management.

One of Insteon's best features is that it can be configured to run with no controller, using device to devices links and groups. This is particularly valuable with KeyPadLinc - configuring bidirectional groups of links makes it so that all the button-LEDs remain in sync when one turns a light on or off via a linked KeyPadLinc without needing a controller's intervention.

There are several problems with manually creating these links:

  1. the number of links needed gets very big quickly (2 KeyPadLincs require 4 links to have a button on each control the other, 3 KeyPadLincs require 6 links, etc.) and remembering all that need to be done is hard.
  2. there is no easy way to ensure that all the links are correctly set other than noticing that one button does not control the device as it should, or that the state gets out of sync.
  3. it can involve a lot of walking (given that these linked devices do not need to be in the same room or even on the same floor, and that they have to be done one at a time, this is an actual issue).
  4. some features cannot be supported directly (KeyPadLinc detached loads and self referential buttons are two examples).

@teharris1 had asked whether this software should just be a driver for Home Assistant or be more general. I think that really be able to use Insteon gear in this environment, one needs to be able to configure these links with (at a minimum) a command line tool. It would be great to have a GUI to do this, but that is not critical.

This post on the Indigo Forum explains the ideas better.

As I mentioned, link management is particularly valuable with detached loads. Newer generation KeyPadLincs (i.e. all built after 2013, as I understand it) can detach control of the local load from button 1 (in 8-button mode) or buttons 1-2 and 7-8 (in 6-button mode). This is really nice for having the same button control the same light on multiple KeyPadLincs in the same space (this shows an example of how it would be used).

Here are the notes from the developer docs that explain it:

http://cache.insteon.com/developer/2334-xxx2486xdev-042013-en.pdf
Detach Load Notes:

  • Detach Load is only supported through software. It cannot be turned on/off from the device.

  • When Detach Load is turned On, the load will then be moved/controlled by Group 9
    o Link to Group 9 using the SET Button.
    o Link to Group 1 by using the ON or OFF Button. o Link to Buttons A-H using the A-H buttons.

  • Control of the LEDs when Detach load is enabled
    o To control the Group 1 LEDs, simply send the Keypad a Group 1 On/Off
    command
    o To control the other LEDs, use the Extended 2E Set LED Bit Mask command to
    set those LEDs

-Getting status of the LEDs when Detach Load is enabled

o To get the Status of the 8 LEDs (Group 1-8), use the Read Data 2E command and
the Data 11 byte contains the LED State information.
o To get the Status of Group 9 (The Load), use the Standard status request
command Cmd1=19 Cmd2=00

Status of lights and switches does not update after manual change

The Insteon devices all work great when controlled from within HA, but when I manually turn a device on or off at the wall switch, the HA status does not update.
Tested with the following:

  • Fresh install of the latest version of Hassbian image on RPi2
  • Insteon 2413U USB PLM
  • Insteon 2477D SwitchLinc Dimmer Switch
  • Insteon 2477S SwitchLinc On/Off Switch

I've made no changes to the yaml configuration file other than the following:

  customize:
    light.4xxxx4:
      friendly_name: Stairs Light
      icon: mdi:stairs
    light.4xxxxe:
      friendly_name: Entry Light
    light.4xxxx9:
      friendly_name: Hallway Light
      hidden: true
    light.4xxxx1:
      friendly_name: Porch Light
    light.3xxxxe:
      friendly_name: Yard Lights
      icon: mdi:spotlight-beam
    switch.3xxxxa:
      friendly_name: Front Fountain
      icon: mdi:water-pump
    switch.3xxxxc:
      friendly_name: Back Fountain
      icon: mdi:water-pump
    light.3xxxx8:
      friendly_name: Garage Sconces
      icon: mdi:garage

insteon_plm:
  port: /dev/ttyUSB0
  device_override:
    - address: 3xxxxa  # Front fountain
      platform: switch  # Make fountain a switch instead of a light

Perform All-Link checks

Enable the following checks of All-Links:

  • Half links
  • Broken links (ie. missing device)
  • Missing links (ie. a device has X groups make sure there are X links to the PLM)

Streamline startup

Do not refresh the modem ALDB every startup. Only do it on first startup (i.e. there is no insteon_plm_device_info.dat file) or on demand.

Help adding smoke bridge support

I picked up an Insteon Smoke Bridge to link wireless smoke detectors into my Home Assistant. The bridge is supported by the OpenHab PLM binding using category 0x10 , subcat 0x0A, product key F00.00.22. The developer docs for the smoke bridge can be found here.

I don't have any problem doing the work to get this integrated myself, but I was hoping for some pointers as to how to proceed. I looked at ipdb.py and see where to add the line, but I don't understand the model capability list and what that maps to (or what allowed values are for that list).

Thanks - Ted

Multiple Capabilities

I have multiple older devices that do not respond to 0x03 0x00 commands so they always come back as 0x01 0x00 devices (i.e. lights). I see that I can override this but with only one capability whereas your platform allows for multiple capabilities. My suggestion is to change homeassistant/components/insteonplm.py starting at line 82 to:
if isinstance(device['platform'], list):
plm.protocol.devices.add_override(
device['address'], 'capabilities', device['platform'])
else:
plm.protocol.devices.add_override(
device['address'], 'capabilities', [device['platform']])

This will enable the following in the config file:
insteon_plm:
port: /dev/insteon
device_override:
- address: aabbcc
platform:
- light
- dimmable

By the way, I am happy to contribute to this project. I have over 30 different insteon devices of all types but I have never programmed in Python (c# guy) and have never contributed to an opensource project. So I am bound to make mistakes and don't want to break your very well done project.

InsteonPLM gets stuck waiting for response.

When it boots up, InsteonPLM scans all the links in the PLM and requests all their initial states, but at some point along the way either some device fails to respond or it doesn't understand the response and it gets stuck waiting forever. Any new command just gets added to the end of the queue. For example:

2017-08-13 02:28:20 DEBUG (MainThread) [insteonplm.protocol] turn_on '1d1f83' 2456D3
2017-08-13 02:28:20 DEBUG (MainThread) [insteonplm.protocol] Still waiting on last_command.
2017-08-13 02:28:20 DEBUG (MainThread) [insteonplm.protocol] Adding command to queue: 02621d1f830011ff

Any incoming data the PLM gets will report that there are a some command sitting in the queue.

2017-08-13 02:28:36 DEBUG (MainThread) [insteonplm.protocol] Received 5 bytes from PLM: b'76ac411101'
2017-08-13 02:28:36 DEBUG (MainThread) [insteonplm.protocol] Found a code 0x62 message which returns 9 bytes
2017-08-13 02:28:36 DEBUG (MainThread) [insteonplm.protocol] Wait for ACK/NAK on sent: b'02621d1f83001300' expecting rsize of 9
2017-08-13 02:28:36 DEBUG (MainThread) [insteonplm.protocol] Send queue contains 20 items

To see what the command was, I added a line to _send_hex() which outputs

2017-08-13 03:09:10 DEBUG (MainThread) [insteonplm.protocol] Still waiting on last_command.
2017-08-13 03:09:10 DEBUG (MainThread) [insteonplm.protocol] Which is :b'\x02j'

0x02j is 026A which is "Thermostat Get Zone Info", but I don't have a thermostat and Home Assistant doesn't list one (so InsteonPLM knows I don't either) so I'm thinking that's either not really the command being sent or that's not really the command to get thermostat zone info.

PLM won't initialize - WARNING:insteonplm.protocol:Sent command b'0269' UNsuccessful! (acknak 0x15)

been trying to get my insteon USB PLM working for a week now and making no progress. The PLM works fine when connected to it's previous system (altsteon for vera). i get an initial error, then some more after time (maybe insteon messages?). here's what i get:
https://pastebin.com/g9A3u4rR

here's the log with logger: turned on:
https://pastebin.com/big9wJw8

i also get the same error running the standalone python-insteonplm installed via pip.

thanks!

Leak sensor reporting 'wet' when it is dry

Leak sensor indicates the device is wet when it is dry Issue is the daily heartbeat is being seen as an 'on' command. Device needs to be rewritten to support groups 0x01 Dry 0x02 Wet and 0x04 Heartbeat.

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.