New Insteon version for beta testing - (Do not use since this is now in 0.111 and higher)

I have finally completed significant improvements to the Insteon component. It is based on a new underlying library called pyinsteon. There are a number of improvements and bug fixes. Unfortunately, this release can not be done incrementally so it is a significant change and I want to make sure it is well tested with real users as much as possible.

In order to test the release without disrupting the current release, I have created a custom component. It is available on git hub:

Please use this thread to provide feedback. I have been running it in my own house for quite a while and have done a lot of testing. I feel like it is very close to complete so I am introducing it now for feedback.

Some of the improvements in this release include:

  • Auto-discovery also identifies battery-operated devices just by triggering the device rather than using device overrides
  • The All-Link database is used to determine cascading state changes (ie. device 1 triggers device 2)
  • Operating flags and extended properties are loaded and used to identify device behaviors in the following devices:
    • Thermostat
    • IOLinc
    • KeypadLinc
  • Events are published and can be listened for like a double tap on/off
  • Hub users can use it interchangeably with the Hub app. The state will update in HA.
  • Full support for the Thermostat

There is also a significantly improved command-line tool that allows for setting operating flags and extended properties to configure devices to behave as desired.

It also fixes a number of bugs including the issue with the frontend breaking if the connection is lost.

2 Likes

Excited to give this a test. Thanks for the update. I moved away from the insteon component a year or so ago in favor of insteon-mqtt for their support of cascading state changes, but it hasn’t been very reliable on my insteon network. I’ll let you know how your update works.

Ran into an install problem. After startup, hass logs show the pyinsteon module not found:

Error loading custom_components.insteon2. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 391, in _load_file
    module = importlib.import_module(path)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/insteon2/__init__.py", line 5, in <module>
    from pyinsteon import async_close, async_connect, devices
ModuleNotFoundError: No module named 'pyinsteon'

However I did install pyinsteon, but perhaps not in a way hass can use it? Any suggestions?

Successfully built pyyaml idna-ssl

Installing collected packages: pyserial, pyserial-asyncio, chardet, multidict, idna, yarl, async-timeout, typing-extensions, idna-ssl, attrs, aiohttp, pypubsub, aiofile, async-generator, pyyaml, pyinsteon

Running setup.py install for pyinsteon ... done

Successfully installed aiofile-1.5.2 aiohttp-3.6.2 async-generator-1.10 async-timeout-3.0.1 attrs-19.3.0 chardet-3.0.4 idna-2.9 idna-ssl-1.1.0 multidict-4.7.5 pyinsteon-0.1.0rc4 pypubsub-4.0.3 pyserial-3.4 pyserial-asyncio-0.4 pyyaml-5.3.1 typing-extensions-3.7.4.2 yarl-1.4.2

I wonder if it’s because i’m dockerized – not sure how i install pyinsteon within the docker image

How are you running HA? The pyinsteon module needs to be in the same virtual environment as HA.

I am running through hassio with ha in a docker image. I got to the command line in the container, but the installer couldn’t compile. Generally I don’t touch these images so they closely represent production. Any advice if it’s possible to test in my environment?

I will try tonight to create a docker image but I don’t know enough about hass.io to say how that will work.

No problem, I understand. I’ll putz a bit more tonight too

Can we just include the pyinsteon files with your files in Insteon2? I don’t know enough about HASS.IO to know how to run the pip command currently. (not running docker)

Unfortnately it is not as easy as adding pyinsteon to the custom component because the component requires a few other modules be installed as well. They would all have to be included but it would also require that they all point to local versions rather than the standard site-packages location.

What I did was create a Dockerfile and put it into the repository. If you know how to start docker and use a Dockerfile to run HA this will work the same.

The alternative is to run the following (Updated for the correct statement):

docker exec -it --user=root homeassistant pip3 install --upgrade https://github.com/teharris1/pyinsteon/archive/release1.zip

Either one will install pyinsteon in the docker container.

In the command above replace home-assistant with the name of the docker container (most likely homeassistant). If you don’t know the name of the container you can run this:

docker ps

It will return the names of running containers.

Yeh – my dockerfile was just homeassistant, changed a few builds ago.

I’m getting a compile error when running the pip install within the docker container:

Collecting https://github.com/teharris1/pyinsteon/archive/master.zip
  Using cached https://github.com/teharris1/pyinsteon/archive/master.zip
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied, skipping upgrade: pyserial in /usr/local/lib/python3.7/site-packages (from pyinsteon==0.1.0rc4) (3.1.1)
Requirement already satisfied, skipping upgrade: pypubsub in /usr/local/lib/python3.7/site-packages (from pyinsteon==0.1.0rc4) (4.0.3)
Requirement already satisfied, skipping upgrade: pyyaml in /usr/local/lib/python3.7/site-packages (from pyinsteon==0.1.0rc4) (5.3)
Requirement already satisfied, skipping upgrade: aiohttp in /usr/local/lib/python3.7/site-packages (from pyinsteon==0.1.0rc4) (3.6.1)
Requirement already satisfied, skipping upgrade: async-generator in /usr/local/lib/python3.7/site-packages (from pyinsteon==0.1.0rc4) (1.10)
Collecting aiofile
  Using cached aiofile-1.5.2.tar.gz (83 kB)
Requirement already satisfied, skipping upgrade: pyserial-asyncio in /usr/local/lib/python3.7/site-packages (from pyinsteon==0.1.0rc4) (0.4)
Requirement already satisfied, skipping upgrade: multidict<5.0,>=4.5 in /usr/local/lib/python3.7/site-packages (from aiohttp->pyinsteon==0.1.0rc4) (4.7.5)
Requirement already satisfied, skipping upgrade: attrs>=17.3.0 in /usr/local/lib/python3.7/site-packages (from aiohttp->pyinsteon==0.1.0rc4) (19.3.0)
Requirement already satisfied, skipping upgrade: chardet<4.0,>=2.0 in /usr/local/lib/python3.7/site-packages (from aiohttp->pyinsteon==0.1.0rc4) (3.0.4)
Requirement already satisfied, skipping upgrade: yarl<2.0,>=1.0 in /usr/local/lib/python3.7/site-packages (from aiohttp->pyinsteon==0.1.0rc4) (1.4.2)
Requirement already satisfied, skipping upgrade: async-timeout<4.0,>=3.0 in /usr/local/lib/python3.7/site-packages (from aiohttp->pyinsteon==0.1.0rc4) (3.0.1)
Requirement already satisfied, skipping upgrade: idna>=2.0 in /usr/local/lib/python3.7/site-packages (from yarl<2.0,>=1.0->aiohttp->pyinsteon==0.1.0rc4) (2.9)
Building wheels for collected packages: pyinsteon, aiofile
  Building wheel for pyinsteon (PEP 517) ... done
  Created wheel for pyinsteon: filename=pyinsteon-0.1.0rc4-py3-none-any.whl size=203814 sha256=e66fcb8ae620d9a21bf4f2c5403b1ad208ea8f96947f0785c9b987d198aa4363
  Stored in directory: /tmp/pip-ephem-wheel-cache-vtdyc3gs/wheels/bc/94/eb/8f0d159c79659df97fade59e4c71bfbe98ee011d4f6a0c98e0
  Building wheel for aiofile (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-rphx8347/aiofile/setup.py'"'"'; __file__='"'"'/tmp/pip-install-rphx8347/aiofile/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-wom9pkij
       cwd: /tmp/pip-install-rphx8347/aiofile/
  Complete output (22 lines):
  /usr/local/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /tmp/pip-install-rphx8347/aiofile/aiofile/posix_aio.pyx
    tree = Parsing.p_module(s, pxd, full_module_name)
  /usr/local/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'build_requires'
    warnings.warn(msg)
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.7
  creating build/lib.linux-x86_64-3.7/aiofile
  copying aiofile/version.py -> build/lib.linux-x86_64-3.7/aiofile
  copying aiofile/thread_aio.py -> build/lib.linux-x86_64-3.7/aiofile
  copying aiofile/__init__.py -> build/lib.linux-x86_64-3.7/aiofile
  copying aiofile/utils.py -> build/lib.linux-x86_64-3.7/aiofile
  copying aiofile/aio.py -> build/lib.linux-x86_64-3.7/aiofile
  running build_ext
  building 'aiofile.posix_aio' extension
  creating build/temp.linux-x86_64-3.7
  creating build/temp.linux-x86_64-3.7/aiofile
  gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/local/include/python3.7m -c aiofile/posix_aio.c -o build/temp.linux-x86_64-3.7/aiofile/posix_aio.o
  unable to execute 'gcc': No such file or directory
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for aiofile
  Running setup.py clean for aiofile
Successfully built pyinsteon
Failed to build aiofile
Installing collected packages: aiofile, pyinsteon
    Running setup.py install for aiofile ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-rphx8347/aiofile/setup.py'"'"'; __file__='"'"'/tmp/pip-install-rphx8347/aiofile/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-7t6o1nfh/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7m/aiofile
         cwd: /tmp/pip-install-rphx8347/aiofile/
    Complete output (22 lines):
    /usr/local/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /tmp/pip-install-rphx8347/aiofile/aiofile/posix_aio.pyx
      tree = Parsing.p_module(s, pxd, full_module_name)
    /usr/local/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'build_requires'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.7
    creating build/lib.linux-x86_64-3.7/aiofile
    copying aiofile/version.py -> build/lib.linux-x86_64-3.7/aiofile
    copying aiofile/thread_aio.py -> build/lib.linux-x86_64-3.7/aiofile
    copying aiofile/__init__.py -> build/lib.linux-x86_64-3.7/aiofile
    copying aiofile/utils.py -> build/lib.linux-x86_64-3.7/aiofile
    copying aiofile/aio.py -> build/lib.linux-x86_64-3.7/aiofile
    running build_ext
    building 'aiofile.posix_aio' extension
    creating build/temp.linux-x86_64-3.7
    creating build/temp.linux-x86_64-3.7/aiofile
    gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/local/include/python3.7m -c aiofile/posix_aio.c -o build/temp.linux-x86_64-3.7/aiofile/posix_aio.o
    unable to execute 'gcc': No such file or directory
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-rphx8347/aiofile/setup.py'"'"'; __file__='"'"'/tmp/pip-install-rphx8347/aiofile/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-7t6o1nfh/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7m/aiofile Check the logs for full command output.

Oh, sorry, I pointed to the master branch. Meant to point to the release1 branch. Use this:

python3 -m pip install --upgrade https://github.com/teharris1/pyinsteon/archive/release1.zip

Sorry, but think I’m going to have to wait for this to hit the full release. Not familiar (yet) with docker and with trying to rebuild set up, and life I just don’t have the time right now.

I do look forward to the update, as I want the two way status updates again, miss those.

Thanks for your hard work.

That command worked great for me – thank you sir.

Now on reboots i’m getting two errors and ultimately the component is not loading.

Log Details (ERROR)
Logger: homeassistant.setup
Source: custom_components/insteon2/utils.py:94
First occurred: 10:33:59 AM (1 occurrences)
Last logged: 10:33:59 AM

Error during setup of component insteon2
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 170, in _async_setup_component
    hass, processed_config
  File "/config/custom_components/insteon2/__init__.py", line 147, in async_setup
    add_on_off_event_device(hass, device)
  File "/config/custom_components/insteon2/utils.py", line 94, in add_on_off_event_device
    for event in device.events[group]:
TypeError: 'LowBatteryEvent' object is not iterable
Log Details (ERROR)
Logger: homeassistant.setup
Source: setup.py:263
First occurred: 10:34:00 AM (6 occurrences)
Last logged: 10:34:01 AM

Unable to prepare setup for platform insteon2.climate: Unable to set up component.
Unable to prepare setup for platform insteon2.cover: Unable to set up component.
Unable to prepare setup for platform insteon2.fan: Unable to set up component.
Unable to prepare setup for platform insteon2.light: Unable to set up component.
Unable to prepare setup for platform insteon2.switch: Unable to set up component.

Sorry, I had fixed that issue but the code did not sync to my repository. Can you download the insteon2 files again and just replace the ones in the custom_components directory?

that worked – Auto Discovery is working its way through adding devices now. I’ll start re-mapping the hex addresses to my previous entity names… Looks like i’ll have to delete the other entities (from mqtt) and replace them with this new one so i don’t have to update all my rules.

I’ll send feedback if any troubles arise or certain devices don’t work. I have ~60 or so devices … dimmers, switches, keypads, fanlincs, thermostats… I removed all my battery devices a while back though

Let it sit for a few hours not knowing how quick the auto-discovery process was… went through all my devices and found they all are in except my switches (dimmers, keypads, thermostats, fanlinc’s all loaded fine)

There was a startup error for the switch component:

Log Details (ERROR)
Logger: homeassistant.components.switch
Source: custom_components/insteon2/insteon_entity.py:25
Integration: Switch (documentation, issues)
First occurred: 7:39:39 AM (1 occurrences)
Last logged: 7:39:39 AM

Error while setting up insteon2 platform for switch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/insteon2/switch.py", line 15, in async_setup_platform
    hass, DOMAIN, InsteonSwitchDevice, async_add_entities, discovery_info
  File "/config/custom_components/insteon2/utils.py", line 316, in async_add_insteon_entities
    new_entities.append(entity_type(device, group))
  File "/config/custom_components/insteon2/insteon_entity.py", line 25, in __init__
    self._insteon_device_group = device.groups[group]
KeyError: 2

Do you know what type of switch devices you have? There is only 2 that have a group 2 (or should have a group 2), they are the OnOffOutlet and the KeyPadLinc. Switches are Insteon category 0x02 devices, meaning they are on/off devices only, non-dimmable. I am going to put in a logging statement to help catch what device is having an issue.

In looking at the code, there should be a log entry for it. Do you have debug level logging on for the insteon component?

Background:
Not a programmer but keen to help. I like the direction this is headed.
Running HA 108.1 on a Pi4 4GB, on Raspbian, using hassio (docker).
I have an Insteon net with 14 devices, running well on the insteon (1) integration.
connected via USB USB PLM 2413U. I also have a Hub 2245-222 which works with Amazon Alexa for voice control of some devices and for backup of HA if ever needed.

Results with insteon2 so far:

  • Installation was a bit confusing with part of the story in this thread and part on github, but not too difficult.
  • First run I got an error with a Smoke Bridge 2982-222, which we had before doing some renovations. The new building code here requires wired in Smoke and CO2 detectors in each bedroom so the Bridge (for battery operated detectors) is now kind of surplus. I unpluged it and restarted HA and got the same error. In the end I renamed file “insteon_plm_device_info.dat”
    which ended that error and uncovered another with the following error log:
2020-04-09 15:06:19 INFO (MainThread) [pyinsteon.managers.device_manager] Adding device to INSTEON devices list: 352726
2020-04-09 15:06:19 INFO (MainThread) [custom_components.insteon2.utils] Adding new INSTEON device to Home Assistant with address 352726
2020-04-09 15:06:19 ERROR (MainThread) [custom_components.insteon2.utils] I think the error is here
2020-04-09 15:06:19 INFO (MainThread) [homeassistant.components.light] Setting up light.insteon2
2020-04-09 15:06:19 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new light.insteon2 entity: light.lamplinc_dimmer_35_27_26_2

The " I think the error is here" log fragment suggests a ghost in the machine [grin]

I will stop here. If wanted I can do a better job of reporting.
Wes