Insteon Component

So I have been deliberating if to post this up here for a while for a number of reasons

  1. Not sure how many people have committed to Insteon as I have
  2. It may be controversial in which case a MOD can remove this post

After deciding to move to Home Assistant from OpenHab I was extremely disappointed to find out that the Insteon component required me to get an API code from Insteon. It has been weeks and nothing to date. OpenHab on the other hand has 100% out of the box support, no API code required.

So what I did was setup my Insteon devices on OpenHab and utilize the REST API to control it. The good thing is the component is no different from any dimmer component in HA. Dimming works perfectly.

If someone knows how I can attach the component let me know.

Below is how its setup in the configuration file.

light:
  platform: insteondimmeroh
  name: "Garage"
  resource: http://127.0.0.1:8080/rest/items/Dim5
  brightness: "255"

brightness is the ON brightness out for 255. So for 50% on brightness use 128 as the value.

3 Likes

What all would I need to tweak to get this to work with on/off switches? Or would I have to tweak anything at all?

No tweaks. Just setup the HA component and make sure you reference the OpenHab switch in the component.

Ok I think I am getting close on this. I am getting this error in Home Assistant after adding the component and the configuration.

16-07-17 17:56:57 homeassistant.loader: Unable to find component light.insteondimmeroh
16-07-17 17:56:57 homeassistant.bootstrap: Unable to find platform light.insteondimmeroh

I’m running linux and the location the component needs to be in is

/home/automate/.homeassistant/custom_components/light/

where automate is your username

oops misspelled the directory name. I am now getting this error when trying to use it for a switch.

6-07-17 18:10:27 homeassistant.components.light: Error while setting up platform insteondimmeroh
Traceback (most recent call last):
File “/usr/local/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 98, in _setup_platform
discovery_info)
File “/root/.homeassistant/custom_components/light/insteondimmeroh.py”, line 39, in setup_platform
config.get(‘brightness’, DEFAULT_BRIGHTNESS))])
File “/usr/local/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 155, in add_entities
if self.component.add_entity(entity, self):
File “/usr/local/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 125, in add_entity
entity.update_ha_state()
File “/usr/local/lib/python3.4/site-packages/homeassistant/helpers/entity.py”, line 165, in update_ha_state
state = STATE_UNKNOWN if self.state is None else str(self.state)
File “/usr/local/lib/python3.4/site-packages/homeassistant/helpers/entity.py”, line 237, in state
return STATE_ON if self.is_on else STATE_OFF
File “/root/.homeassistant/custom_components/light/insteondimmeroh.py”, line 72, in is_on
if int(float(request.text)) > 0:
ValueError: could not convert string to float: ‘ON’

Are you using a dimmer or a switch?

I have two dimmer modules that I am using as well as two switches

lets try with one dimmer only to make sure its working. What is the model number?

Also open up openhab in your browser and make sure its working in openhab

eg.

http://192.168.0.175:8080/openhab.app?sitemap=myhome

ok so I can not get either of the dimmers to show on the front end.
model number of the dimmers are 2457d2 lamp linc dimmer dual band.

Post your openhab items file

Switch bedroomFan “bedroom fan” {insteonplm=“3B.DB.E2:F00.00.02#switch”}
Switch outdoorlights “outdoor lights” {insteonplm=“3B.EA.50:F00.00.02#switch”}
Dimmer kitchenunder1 "kitchen under1 {insteonplm=“2F.25.FD:F00.00.05#dimmer”}
Dimmer kitchenunder2 “kitchen under2” {insteonplm=“2F.2A.84:F00.00.05#dimmer”}

OK I just switched these from Dimmers to Sliders on the sitemap and they show up now but are getting Cannot retrieve item kitchenunder2 for widget org.openhab.model.sitemap.Slider

Try this items file

Group All
Group gDD 		(All)

/******** Lights ********/

// LampLinc
Dimmer kitchenunder1 "kitchen under1"   (gDD) { insteonplm = "2F.25.FD:F00.00.19#dimmer" }

and this sitemap

sitemap demo label="Home"
{
	Frame label="Floors" {
		Group item=gDD label="Downstairs" icon="firstfloor"
	}
}

Make sure you are not using an other sitemap or items file. Let me know if it works…

OK sweet that worked.

Cool! Now try setting up the HA component I posted and provide some feedback.

Ok that is now working. Thanks. Is there a way to get the on/off switches working too?

I had written another component for that that I have included below. You mileage may vary with that one. You need to make sure you setup your items file correctly! You had the wrong identifier for the dimmer in your items file. Make sure you have the correct number for the switch.

Dimmer kitchenunder1 "kitchen under1 {insteonplm=“2F.25.FD:F00.00.05#dimmer”}

should have been

Dimmer kitchenunder1 “kitchen under1” (gDD) { insteonplm = “2F.25.FD:F00.00.19#dimmer” }

See switch code below.

"""
Support for OpenHab Insteon switch.

"""
import logging

import requests

from homeassistant.components.switch import SwitchDevice

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = "Openhab Insteon REST Switch"
DEFAULT_BODY_ON = "ON"
DEFAULT_BODY_OFF = "OFF"


# pylint: disable=unused-argument,
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
    """Setup the REST switch."""
    resource = config.get('resource')

    if resource is None:
        _LOGGER.error("Missing required variable: resource")
        return False

    try:
        requests.get(resource, timeout=10)
    except requests.exceptions.MissingSchema:
        _LOGGER.error("Missing resource or schema in configuration. "
                      "Add http:// or https:// to your URL")
        return False
    except requests.exceptions.ConnectionError:
        _LOGGER.error("No route to resource/endpoint: %s", resource)
        return False

    add_devices_callback([RestSwitch(
        hass,
        config.get('name', DEFAULT_NAME),
        config.get('resource'),
        config.get('body_on', DEFAULT_BODY_ON),
        config.get('body_off', DEFAULT_BODY_OFF))])


# pylint: disable=too-many-arguments
class RestSwitch(SwitchDevice):
    """Representation of a switch that can be toggled using REST."""

    def __init__(self, hass, name, resource, body_on, body_off):
        """Initialize the REST switch."""
        self._state = None
        self._hass = hass
        self._name = name
        self._resource = resource
        self._body_on = body_on
        self._body_off = body_off

    @property
    def name(self):
        """The name of the switch."""
        return self._name

    @property
    def is_on(self):
        """Return true if device is on."""
        return self._state

    def turn_on(self, **kwargs):
        """Turn the device on."""
        request = requests.post(self._resource,
                                data=self._body_on,
                                timeout=10)
        if (request.status_code == 200) or (request.status_code == 201):
            self._state = True
            _LOGGER.info("HTTP Status Code: %s", request.status_code)
        else:
            _LOGGER.error("Can't turn on %s. Is resource/endpoint offline?",
                          self._resource)

    def turn_off(self, **kwargs):
        """Turn the device off."""
        request = requests.post(self._resource,
                                data=self._body_off,
                                timeout=10)
        if (request.status_code == 200) or (request.status_code == 201):
            self._state = False
        else:
            _LOGGER.error("Can't turn off %s. Is resource/endpoint offline?",
                          self._resource)

    def update(self):
        """Get the latest data from REST API and update the state."""
        request = requests.get(self._resource+"/state", timeout=10)
        
        _LOGGER.info("request.text: %s", request.text)
        _LOGGER.info("self._body_on: %s", self._body_on)	

        if request.text == self._body_on:
            self._state = True
        elif request.text == self._body_off:
            self._state = False
        else:
            self._state = None
1 Like

Yeah I noticed the wrong identifier this morning. I changed it and it got rid of the errors but the sitemap never would show them right. I think grouping them was the way to go. I will work on these and see what I can get working the dimmers are both functioning now.

Awesome! All of the insteon componets are now showing and working in Home Assistant. Thanks man that helped a lot.