Skip to content

Add support for Lutron Keypad LEDs #30452

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

Merged
merged 9 commits into from
Apr 20, 2020
Merged

Conversation

alistairg
Copy link
Contributor

@alistairg alistairg commented Jan 3, 2020

Description:

Add support for controlling Lutron Keypad (RadioRA2 keypads) LEDs, and tracking the state of phantom keypad LEDs.

Add additional event parameter (non breaking change) that provides the 'full' name of a button, including its area name, such that it's the same as the entity IDs created by the integration. This makes it more useful for creating button handler automations and the like.

Related issue (if applicable): fixes #

None

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>

Not Applicable

Example entry for configuration.yaml (if applicable):

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@probot-home-assistant
Copy link

Hey there @JonGilmore, mind taking a look at this pull request as its been labeled with a integration (lutron) you are listed as a codeowner for? Thanks!

@JonGilmore
Copy link
Contributor

@thecynic I'm curious to know your thoughts on this PR with how LEDs were implemented. I haven't gotten a chance to fully review/test it yet

@JonGilmore
Copy link
Contributor

@alistairg finally got a chance to pull this down to test it out. Seems like there might be a little more work required on it. Here are some observations:

  • when I first booted HA, all LED switches were off, even though multiple keypads had LEDs on
  • does it make more sense to make the LEDs sensors rather than switches? When I switch an LED off, the scene itself doesnt turn off, but the LED does. This just seems a bit confusing to me.

@koreth @bdunks @achatham @benjimatt @nickovs would love to hear input from you guys on this PR

@alistairg
Copy link
Contributor Author

Hmm - I’d have expected it to sync with the keypad LEDs at boot, but there’s a broader bug in the Lutron integration I’ve yet to track down that doesn’t properly queue commands. This could be another symptom of that (I notice this issue on my home system when sending multiple “Cover Close” commands)

The use case I have requires switches vs sensors, and that’s been the root of all my testing. Most of the keypads in my home are “virtual” (controlling no local load) and I use the buttons to trigger actions within HASS. That’s why I added the “Full ID” parameter to the event - such that it can be tracked back to the right keypad.

The LED control allows me to mirror an internal state within HASS at the keypad - for example, showing that a set of lights in a room are on, or that automated control for a room is active. For the most part, this functionality could technically be achieved using phantom switches within Lutron, but this is a significant waste of capacity within the Lutron system - notably for folks that are limited to the “Essentials” 100 device limit. I use the switch entity within HASS to directly control the LED at keypad(s) as needed.

Copy link
Member

@pvizeli pvizeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a switch and not light platform?

@JonGilmore
Copy link
Contributor

Why a switch and not light platform?

Thats a good question. Technically, this doesn't control anything except for the led on the keypad itself. Does HA have any other integrations like this? Seems like this is a very unique case...

@neillt
Copy link

neillt commented Feb 24, 2020

Ended up here to request keypad LED control as well... after reading above I would just chime in as a user that if it's a switch it will stand out differently than all the lights in the lutron system... but I think it's splitting hairs.

I just hope this isn't idling around just for the sake of deciding if it should be a light or a switch.

@JonGilmore
Copy link
Contributor

Ended up here to request keypad LED control as well... after reading above I would just chime in as a user that if it's a switch it will stand out differently than all the lights in the lutron system... but I think it's splitting hairs.

I just hope this isn't idling around just for the sake of deciding if it should be a light or a switch.

I'm curious, what is your use case with wanting to control the keypad LEDs? Do you have an opinion one way or another? Did you actually test this PR out? I had issues when testing it that I stated above:

when I first booted HA, all LED switches were off, even though multiple keypads had LEDs on

@alistairg
Copy link
Contributor Author

Would be interested on whether this is going to go forward or die on the "PR" vine, also. I'm running this in my own home, and would love to not be running forked custom components if at all possible ;)

@JonGilmore
Copy link
Contributor

Would be interested on whether this is going to go forward or die on the "PR" vine, also. I'm running this in my own home, and would love to not be running forked custom components if at all possible ;)

@alistairg have you tested the startup issue I described? Can you reproduce it? I think it'd be worth resolving that before merging.

@neillt
Copy link

neillt commented Feb 26, 2020

I'm curious, what is your use case with wanting to control the keypad LEDs? Do you have an opinion one way or another? Did you actually test this PR out?

My use case... in my master bedroom I have a keypad with keys labeled "Locks" and "Heat Pump".

If I have any locks on exterior doors unlocked, I would like to light the LED. Pressing the button on the keypad would trigger an automation to lock every exterior door. Once the locks report they are locked, the LED is turned off.

Second case for the Heat Pump... if the thermostat is on Auto, Heat, or Cool, the LED is on. Pressing the keypad button toggles between Off and Auto. If the thermostat is turned to Off, the LED is turned off.

I haven't tested the PR yet. I should have some time tomorrow to check it out. I have an 80 device RA2 install, with about 10 keypads so I'll see what happens.

@thecynic
Copy link
Contributor

In general, this looks reasonable, but I don't use LEDs via hass so don't know if i can comment on whether or not this is integrated correctly here. switch does seem like the right thing since the controlled entity isn't actually a light but an LED on the keypad, but I'm not sure if hass has another paradigm for such things.

@neillt
Copy link

neillt commented Mar 15, 2020

Realized I never commented back on some things... switch appears to be the convention used on other devices. I have a Skybell wi-fi doorbell cam, and changing the settings for the LED backlight is a switch. Same for my pool interface integration, changing status for things is done via switch, even if it may turn lights on or off.

@neillt
Copy link

neillt commented Mar 19, 2020

Testing on my 0.106.5 system with these changes shows it working great on my dual repeater system.

@JonGilmore
Copy link
Contributor

thanks @neillt - I tested on my dev system running the latest 0.107.4 and things look to be working as I'd expect them to be.

@frenck
Copy link
Member

frenck commented Mar 21, 2020

Why a switch and not light platform?

I agree with pvizeli, an LED emits light and should be a light, not a switch.

@alistairg
Copy link
Contributor Author

I'm not sure I agree - the LED on these things is not a light, but a binary indicator. As HASS groups anything that looks 'binary' to a switch (e.g. input_boolean), this makes sense to be a switch. It doesn't provide useful or measurable light, it's just state tracking.

@neillt
Copy link

neillt commented Mar 21, 2020

Why a switch and not light platform?

I agree with pvizeli, an LED emits light and should be a light, not a switch.

There is already precedent in other integrations (like Skybell) where indicator LEDs that are not used for useful illumination are switches, not lights.

@neillt
Copy link

neillt commented Mar 26, 2020

Just curious when we might see this roll into an actual release? 107 is getting point updates almost every day and this is just hanging there.

@frenck
Copy link
Member

frenck commented Mar 26, 2020

There is already precedent in other integrations

In software development it doesn't work like that. There is no reason to assume past decisions are still the right one.

It doesn't provide useful or measurable light, it's just state tracking.

It isn't just state tracking, since you can change the state.

@neillt About releases; 0.107 is the current stable, the patch releases only contain bug fixes, never new features. So not sure how patch releases are related to your comment.

Feel free to help us lower the workload by pre-reviewing other PR's. That is always greatly appreciated 👍

@alistairg
Copy link
Contributor Author

It isn't just state tracking, since you can change the state.

@frenck I meant that from a Lutron perspective it's just state tracking. You can't directly control the keypad LED from a Lutron button or similar, it just tracks the state of either other Lutron devices or reflects an internal variable (which can now be controlled by HA).

This isn't control of a Lutron "light" from HA, but a Lutron state indicator. That indicator could reflect the on/off state of a further light (which would be represented as a light in HA).

@neillt
Copy link

neillt commented Mar 26, 2020

It gets more complicated than that... what about phantom keypads you program into the lutron system? In that case, there isn't a physical LED at all, just a variable being tracked within the lutron system when a particular scene or condition is met.

For example, if I created a phantom keypad button for a "night" scene, and it's called programmatically say by the astro clock, there may not be a physical button. But there is still an "LED" that can be queried and tracked to determine if that scene is active.

@neillt About releases; 0.107 is the current stable, the patch releases only contain bug fixes, never new features. So not sure how patch releases are related to your comment.

True... I suppose this is a new feature rather than a bug fix. I understand.

@neillt
Copy link

neillt commented Apr 8, 2020

Welp, it looks like this didn't make it into 0.108, even though it's ready and works great.

How do we reach a resolution on what to call the LED control entities. This code has been working for over 45 days now.

@thecynic
Copy link
Contributor

thecynic commented Apr 9, 2020 via email

@bdunks
Copy link

bdunks commented Apr 10, 2020

Similar to @thecynic, I’m not sure if I have a vote. If I do: Merge as switch.

I’ve been following since @JonGilmore tagged me three months ago, and somewhere along the way we got sideways.

The LED is fundamentally not a light in the Lutron ecosystem. It only exists within the scope of another Lutron “DEVICE” (light, scene, shade, etc.). While it’s referenced as an LED in the Lutron technical integration documentation, and can be queries or set independently, its state is also used to show scene and light state in the LutronConnect app - I.e., no light emitted from the LED.

Additionally, as pointed out earlier, LEDs could be associated with DEVICES on the “HOMEOWNER_KEYPAD,” or the reserved Phantom Buttons on the “MAIN_REPEATER,” both of which have no physical representation.

Let’s merge as switch and then take the debate to another pull request if folks have pragmatic use cases to control these as a light.

@nickovs
Copy link
Contributor

nickovs commented Apr 10, 2020

FWIW, I vote for LEDs being switches too.

@chrisaljoudi
Copy link
Contributor

Ditto; switch seems more appropriate to me.

def update(self):
"""Call when forcing a refresh of the device."""
if self._prev_state is None:
self._prev_state = self._lutron_device.state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is self._prev_state used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemingly nowhere..... I've removed it from the block of code I added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name _prev_state was perhaps a misnomer. It's effectively a:
self._first_update..

Please don't submit it like this. You don't want to re-query the Main Repeater every time HASS wants to check the state. We get asynchronous notifications about switch state from the MR, which keeps the current state up to date.

So, what we need is a single update at startup, and that was the purpose of _prev_state. So rename it as you like (first_update bool, inital_State, whatever you like), but we should keep the explicit MR query to only happen at startup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thecynic - Totally fair, but doesn't the underlying Lutron library actually cache the state ("last_state") ?

So, I guess what we really want to do is check last_state from Lutron and, if it's None do a force refresh? We don't want to add caching on top of caching, surely?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alistairg Ah, good point, that will work nicely. If 'last_state' is None, query 'state'. 👍

Copy link
Member

@MartinHjelmare MartinHjelmare Apr 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use add_entities(entities, True) for this case? That will make sure that update is called during entity addition.

Polling is already turned off, and we're already calling add_entities with second parameter True, so I don't think we need to change anything. Please confirm.

Copy link
Contributor

@thecynic thecynic Apr 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure honestly. Previously, I found update was called a lot, but maybe that's different now. It should be easy to test @alistairg if you want to double check that it only gets called once at startup. Would be interested to see if new clients opening the webview or refreshing screen, switching views, etc. doesnt cause a forced update, but my knowledge if that part of hass will force queries is limited.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so I updated the code that should now correctly address all scenarios. update() will trigger a low-level refresh from Lutron if there's no value (which is the case at first add) then will use the underlying cached value in future cases.

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@MartinHjelmare
Copy link
Member

Do we need to update the docs?
https://www.home-assistant.io/integrations/lutron/

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MartinHjelmare
Copy link
Member

Please check if we should update the docs. Ping me when that's done and I'll merge.

@neillt
Copy link

neillt commented Apr 20, 2020

Docs do need updating. I tried to create a PR and my noobness with git was ALL too apparent. I quickly canceled the PR. Here is the markdown I tried to incorporate, to be inserted right after the keypads section:

Keypad LEDs

Each full-width button on a Lutron SeeTouch, Hybrid SeeTouch, and Tabletop SeeTouch Keypad has an LED that can be controlled by Home Assistant. A service call of switch.turn_off or switch.turn_on against the appropriate LED entity will control the keypad LED.

Keep in mind that the Lutron system will also control the LED state independent of Home Assistant, according to the programming of the RadioRA2 system. This also means you can query LED states to determine if a certain scene is active, since the LED will have been illuminated by the RadioRA2 repeaters. This includes the "phantom" LEDs of Main Repeater Keypad buttons; even though there is no physical button or LED, the RadioRA2 system tracks the scenes and will "light" the LED that can be queried.

If a button is not programmed to control any lights or other devices in the RadioRA2 system but is given a name in the programming software, it will be available to fire events in Home Assistant. However, since there is no way to have a scene "active" on a button with no devices associated, the Main Repeater will automatically extinguish the keypad LED a few seconds after the button press. If you wish to have Home Assistant light the keypad LED after a button press, you will need to delay your service call to light the LED for several seconds, so it arrives after the Main Repeater has sent the command to turn it off.

@thecynic
Copy link
Contributor

thecynic commented Apr 20, 2020 via email

@JonGilmore
Copy link
Contributor

JonGilmore commented Apr 20, 2020

@MartinHjelmare here's the documentation PR: home-assistant/home-assistant.io#13096

Also, thanks @neillt :D

@frenck
Copy link
Member

frenck commented Apr 20, 2020

Thanks for creating the Docs PR @JonGilmore 👍

@frenck frenck merged commit d144228 into home-assistant:dev Apr 20, 2020
@lock lock bot locked and limited conversation to collaborators Apr 25, 2020
@alistairg alistairg deleted the lutron-led branch September 7, 2020 03:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.