Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Keypadlinc Support #8

Closed
bfranske opened this issue Dec 11, 2017 · 23 comments
Closed

Add Keypadlinc Support #8

bfranske opened this issue Dec 11, 2017 · 23 comments

Comments

@bfranske
Copy link

I have a 6 button Keypadlinc (other configurations of buttons available too) which has On, Off, A, B, C, D buttons on it in addition to having a dimmer module inside as well. Once this is available I can do some testing. Thanks!

@masterdka
Copy link

I can also do some testing once ready!

@TD22057
Copy link
Owner

TD22057 commented Dec 13, 2017

OK - I should have something to test tonight or tomorrow. Basically it will have control of the dimmer (just like the existing dimmer) and it will report other button presses via MQTT messages. Since those buttons have nothing to actuate, they will just be outputs (like the current mini remotes). When Issue #9 is finished, the buttons will be available to command as simulated presses (basically turn the scene on and off).

TD22057 added a commit that referenced this issue Dec 13, 2017
@TD22057
Copy link
Owner

TD22057 commented Dec 13, 2017

OK - keypadlinc support is up on the dev branch for you to try out. Add the device address to config, download the db, and start pushing buttons. You may also want to run the pair command if you haven't linked all the buttons to the modem yet. I also added leak sensor and battery powered sensor (door, windows) support in as well. And the command line tool should now give you responses to how the commands worked if you use that to do the pairing and db downloading.

@larizzo
Copy link

larizzo commented Dec 13, 2017

I'll test this tonight, the binary_sensor is a great start to this! I was wondering if you think you will be able to command the button to light up or this is something that can't be done from the PLM?

It's the only thing I'm still using openhab for. Home-Assitant to openhab API to turn on the "Home" button light when my Home scene is activated.

@TD22057
Copy link
Owner

TD22057 commented Dec 13, 2017

Thanks. For some reason I thought there was one light attached to the main on/off switch (group 1) but I guess that's wrong. I see the light command now in the developer docs. I'll take a look at see - it will definitely require some iteration though as it's not 100% clear what to do with that. I think the problem is that while you can remotely command the light to go and off, you can't remotely command it to activate the scene write now. To do that, Issue #9 will need to get implemented. But it sounds like your comment is that you want control of just the light as an option. I'll make a cut at that in the next couple of days.

@bfranske
Copy link
Author

I have done some basic testing of the keypadlinc code. I am able to receive events/status in MQTT from the keypadlinc device just fine for all buttons. I'm also able to send on/off commands to the main on/off buttons (group 1) on my 6 button device. The ability to 'press' the buttons i.e. issue #9 will be useful as all the buttons are mapped to scenes. So, for example setting the state to on currently doesn't actually do anything on my device except flip the indicator light because I'm not actually controlling anything with the dimmer inside my keypadlinc, it's just serving as a trigger buttons for scenes.

@larizzo
Copy link

larizzo commented Dec 14, 2017

Yea the light would be enough as I can just trigger the scene or action inside home assistant based on the button press. I'm not even sure how scenes work with the PLM as I've always used the hub to create insteon scenes.

If we could create insteon scenes and trigger them with the button and from home-assistant that would be good too but seems like it would be a lot more complicated.

@bfranske Sounds like you want to do the same thing as me, create a scene inside home-assistant and have the button trigger it? Which would now be possible but if the scene is trigger from Home-Assistant it wouldn't turn on the light.

@larizzo
Copy link

larizzo commented Dec 14, 2017

Also the keypad binary_sensor is working for me.

@bfranske
Copy link
Author

@larizzo I don't actually use Home-Assistant, I'm just looking to interact with Insteon over MQTT. In the past I have used MisterHouse for my Insteon interface and it supports building Insteon scenes in it's config file which it then pushes out to the Insteon devices. I really only use these 'scenes' to build 3-way and 4-way switch capability which will work on the physical switches even if the automation system is down entirely. This is a pretty handy feature to have.

I'm not entirely sure how scenes inside HomeAssistant work but I think you would be able to do what you want without Insteon scene support. You should be able to build a collection of devices you want to control as a group inside HomeAssistant and then have Home Assistant watch for state changes on the button you want to trigger the scene and then HA sends device off/on commands to the individual devices. That should be doable now because we're getting MQTT status updates from the buttons on the keypadlinc which should be able to be used to trigger whatever you want inside of HA.

What's not yet possible is interfacing with Insteon scenes which are stored in the Insteon hardware itself and do not require anything else to use. Personally, I would only use Insteon scenes to create 3-way and 4-way switch scenarios and I would create anything more advanced (e.g. "movie mode scene" or whatever) within my automation software and then just trigger them from buttons.

@TD22057
Copy link
Owner

TD22057 commented Dec 14, 2017

I'd recommend this link: https://github.com/hollie/misterhouse/wiki/Insteon-Linking-and-Scenes
It's got a really nice write up about how scenes work in Insteon. Basically each button is a scene controller and lights/loads are scene responders and you can link controllers to N responders as you like. When you trigger a scene, it sends out a message with it's address and group and an on/off cmd and anyone with that addr/group combo in it's database will respond. So you can use my tool to configure those scenes by manipulating the databases.

The keypad buttons are basically just broadcasting an on/off message on a specific group number (and they just toggle between on and off). The light is set to match that. However, if you change the light manually via command, I'm not sure if that changes the on/off internal state - say you press a button and it sends "ON". If you then manually turn the light off with a remote command, does the next button press send an "ON" or an "OFF"? I'd need to implement that and then you could try it out and see.

The PLM modem is also a controller with up to 255 virtual scenes. That's basically setting the modem as the controller at group N and whatever devices you want in the scene as responders. Then you can trigger the scenes by having the modem send the command with the right group number.

I think I can add an input topic/payload for the light control. That will allow you to control the light on each button with a message but it won't trigger a scene. That could be useful for showing the state of some other device using the lights. Then when #9 is implemented, you can trigger the scenes that the button would trigger by sending a different message. That will also probably change the light state but we'd need to test that.

@TD22057
Copy link
Owner

TD22057 commented Dec 15, 2017

FYI - I found the commands to trigger button lights and request the light states. I'll work on adding them but you'll have to test them for me. I have a lot going on the next few days but I should have something to try by Sunday or so.

@ptorsten
Copy link

Holding the button do dim the scene, if it allows dimming.

I'm happy to help here as I'm looking into getting something running for my system.

@TD22057
Copy link
Owner

TD22057 commented Dec 18, 2017

@ptorsten Sorry - I don't understand what you mean. The main load button should already handle dimming. Do the other buttons also work as dimmers? If that's the case, I need to see the messages that are getting sent when that happens (i.e. run the program w/ the log level set at 10 (DEBUG) and hold down the scene buttons and post what the messages are). FYI I bought a KeypadLinc - it should be here next week so I can do better testing then.

@larizzo
Copy link

larizzo commented Dec 18, 2017

Yea the other buttons support dimming also, I've never used them but I'll see if I can get you a debug log unless @ptorsten beats me too it.

@ptorsten
Copy link

I'll see what I can do today (but yes, all works as dimmer buttons even for scenes)

@larizzo
Copy link

larizzo commented Dec 18, 2017

Dimming Lights:

2017-12-18 18:34:53 INFO Protocol: Read 0x50: Std: 3d.8f.f8 Type.ALL_LINK_BROADCAST grp: 03 cmd: 17 00
2017-12-18 18:34:53 INFO Broadcast: Handling all link broadcast for 3d.8f.f8 'entrance'
2017-12-18 18:34:53 ERROR Serial: Serial read error from /dev/ttyUSB0
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/network/Serial.py", line 174, in read_from_link
    self.signal_read.emit(self, data)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/Signal.py", line 50, in emit
    slot(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/Protocol.py", line 255, in _data_read
    self._process_msg(msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/Protocol.py", line 297, in _process_msg
    status = handler.msg_received(self, msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/handler/Broadcast.py", line 64, in msg_received
    return self._process(msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/handler/Broadcast.py", line 102, in _process
    device.handle_broadcast(msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/device/KeypadLinc.py", line 103, in handle_broadcast
    self.signal_pressed.emit(self, msg.group, on)
UnboundLocalError: local variable 'on' referenced before assignment
2017-12-18 18:34:55 INFO Protocol: Read 0x50: Std: 3d.8f.f8 Type.ALL_LINK_BROADCAST grp: 03 cmd: 18 00
2017-12-18 18:34:55 INFO Broadcast: Handling all link broadcast for 3d.8f.f8 'entrance'
2017-12-18 18:34:55 ERROR Serial: Serial read error from /dev/ttyUSB0
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/network/Serial.py", line 174, in read_from_link
    self.signal_read.emit(self, data)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/Signal.py", line 50, in emit
    slot(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/Protocol.py", line 255, in _data_read
    self._process_msg(msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/Protocol.py", line 297, in _process_msg
    status = handler.msg_received(self, msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/handler/Broadcast.py", line 64, in msg_received
    return self._process(msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/handler/Broadcast.py", line 102, in _process
    device.handle_broadcast(msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/device/KeypadLinc.py", line 103, in handle_broadcast
    self.signal_pressed.emit(self, msg.group, on)
UnboundLocalError: local variable 'on' referenced before assignment

Raising Lights:

017-12-18 18:35:03 INFO Protocol: Read 0x50: Std: 3d.8f.f8 Type.ALL_LINK_BROADCAST grp: 03 cmd: 17 01
2017-12-18 18:35:03 INFO Broadcast: Handling all link broadcast for 3d.8f.f8 'entrance'
2017-12-18 18:35:03 ERROR Serial: Serial read error from /dev/ttyUSB0
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/network/Serial.py", line 174, in read_from_link
    self.signal_read.emit(self, data)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/Signal.py", line 50, in emit
    slot(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/Protocol.py", line 255, in _data_read
    self._process_msg(msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/Protocol.py", line 297, in _process_msg
    status = handler.msg_received(self, msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/handler/Broadcast.py", line 64, in msg_received
    return self._process(msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/handler/Broadcast.py", line 102, in _process
    device.handle_broadcast(msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/device/KeypadLinc.py", line 103, in handle_broadcast
    self.signal_pressed.emit(self, msg.group, on)
UnboundLocalError: local variable 'on' referenced before assignment
2017-12-18 18:35:07 INFO Protocol: Read 0x50: Std: 3d.8f.f8 Type.ALL_LINK_BROADCAST grp: 03 cmd: 18 00
2017-12-18 18:35:07 INFO Broadcast: Handling all link broadcast for 3d.8f.f8 'entrance'
2017-12-18 18:35:07 ERROR Serial: Serial read error from /dev/ttyUSB0
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/network/Serial.py", line 174, in read_from_link
    self.signal_read.emit(self, data)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/Signal.py", line 50, in emit
    slot(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/Protocol.py", line 255, in _data_read
    self._process_msg(msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/Protocol.py", line 297, in _process_msg
    status = handler.msg_received(self, msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/handler/Broadcast.py", line 64, in msg_received
    return self._process(msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/handler/Broadcast.py", line 102, in _process
    device.handle_broadcast(msg)
  File "/usr/local/lib/python3.6/site-packages/insteon_mqtt/device/KeypadLinc.py", line 103, in handle_broadcast
    self.signal_pressed.emit(self, msg.group, on)
UnboundLocalError: local variable 'on' referenced before assignment

@TD22057
Copy link
Owner

TD22057 commented Dec 19, 2017

Thanks. In the regular dimmer switch (and the keypadlinc), holding down the button sends two messages: 1) start manual dimming up or down and 2) stop manual dimming. So there is no on or off data or dimmer level data. Just a start/stop. In the regular dimmer, I schedule a refresh when dimming is done to go find out what the actual level is before sending out the status update. And because it's a group broadcast, that refresh hits every device connected to the one doing the dimming to refresh and everything gets updated properly. Interestingly, even the on/off lamp module I have will send out manual up/down messages so it can be used to dim other modules even though it itself can't dim.

It looks like the mini-remote module has the same issue as the Keypadlinc in that it doesn't know what message to emit when a button is held down. My general feeling is that the remote and keypadlinc should send out a "on" message if the dimming is going up and "off" if the dimming is going down but that's a tough one because the switch itself in these cases doesn't really have any state. Except that the keypadlinc buttons do have an LED so maybe query in the at case query the LED state and emit that as on/off. (this is for the keypadlinc buttons not connected to the load).

I'll go ahead the exception and try and get the first cut at LED get/set system in Keypadlinc tonight.

@TD22057
Copy link
Owner

TD22057 commented Dec 19, 2017

I've created issue #15 to discuss getting and setting the LED light status of the KeypadLinc. I have some questions about that so if you're interested, head over there and let me know what you think.

I've pushed an update to the dev branch for the remote and keypadlinc to hopefully fix the dimming mode. I could only test it a little bit since I don't have a device so please give it a try and let me know how it goes.

@TD22057
Copy link
Owner

TD22057 commented Dec 25, 2017

I just pushed some fixes for KeypadLinc support. As part of the fix for #15, the device now maintains the state of each of the 8 buttons (which is also the state of the LED's). So when holding a button down, that info gets refreshed when the button is released and so the system knows whether the device light is still on or not and emits that MQTT message. Like the dimmer, every device in the scene attached to that button is refreshed when the button is released to get state updates.

There are still some open issues that I need to work on before this is totally done:

  • pair() doesn't work. It builds the links from device->modem but not modem->device so the results don't work.
  • what to do about dimmer and non-dimmer models? I only own a dimmer module and wrote it that way (in inherits from Dimmer) but that won't work for non-dimmer modules. Device needs to be more flexible to handle either case (or build 2 devices) and have some way to indicate that in the set up.
  • do 8 button versions work? I think they should - the 6 button number uses the same groups so I think it's ok but I have no way to test this.

@ptorsten
Copy link

Trying with the KeyPad 8 and everything works! Thanks!

@ptorsten
Copy link

Isn't all keypads dimmer only?

@mwdng
Copy link

mwdng commented Dec 26, 2017

Not all keypadlinc’s are dimmers I have one that’s a switch only, 6 button. I use it for fluorescent lights.

@TD22057
Copy link
Owner

TD22057 commented Dec 28, 2017

OK - keypadlinc support has been added to the dev branch. I had to change MQTT config settings so take a look at the new config file. The KeypadLinc is now a dimmer + 8 switches. So you can treat it as a dimmer or a switch (similar to the dimmer now in that it responds to simple on/off commands like a switch). Sending on/off commands to the other buttons just turns the LED on or off since they have no load connected to them. Additionally, I reworked the pairing system so now all the links from the keypad to the modem can be made automatically. For example, to configure a new keypadlinc I just installed, I did this from the command line (mqtt would work as well):

[edit config.yaml and restart]

Link the modem as a controller of the keypad (so we can send other commands):
   insteon-mqtt linking config.yaml modem
   insteon-mqtt linking config.yaml aa.bb.cc
   [keypad double beeps]

Link the keypad as a controller of the modem (so we can get replies to commands):
   insteon-mqtt linking config.yaml aa.bb.cc
   insteon-mqtt linking config.yaml modem
   [keypad double beeps]

Add links for groups 1-8 of the controller to the keypad so get all button messages:
   insteon-mqtt pair config.yaml aa.bb.cc

I still need to update the db-add command to allow different groups for controllers and responds to get full advantage of a keypadlinc but I've added that in issue #20.

As always, feel free to report an issues - this was a fairly big update and I haven't had time to put a real test harness in yet so there might be some things I missed.

@TD22057 TD22057 closed this as completed Dec 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants