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 support for HSV encoded color lights #90

Merged
merged 4 commits into from
Oct 26, 2020
Merged

Add support for HSV encoded color lights #90

merged 4 commits into from
Oct 26, 2020

Conversation

postlund
Copy link
Collaborator

@postlund postlund commented Oct 17, 2020

This PR adds support for light bulbs with colors encoded in HSV format. Brightness is supported as well (since it's embedded in the color data).

@rospogrigio This PR is ready for review, but it should not be merged before #92 and a final test by user.

@postlund postlund added the enhancement New feature or request label Oct 17, 2020
@postlund postlund self-assigned this Oct 17, 2020
@SmartM-ui
Copy link

Here I am,
I follow the development with interest.
As soon as possible I try and send the log.
If I can be useful for anything, don't hesitate to ask

@postlund
Copy link
Collaborator Author

Would be great with a tester for this 👍 Do you have bulbs configured via RGB as well?

@ultratoto14
Copy link
Collaborator

Hi i do have multiple lights with different settings:

  • HSV on 4 bytes (0-1000) range
  • RGB_HSV (0-255) range

I have something almost fully working here https://github.com/ultratoto14/localtuya-homeassistant/tree/rgbw_update. Be kind, i'm not a python developer, many things can be done differently
You can have a check to implement and merge what you need in yours.
As a high number of DP is used, i tried to suggest one for each entry in case i can found it during the config

What is not working in mine:

  • I have RGBW GU10 from different manufacturer which have different white range. So mired should be also configurable
  • I need to detect when HA sends white or color commands to adapt, as it is separated. When a scene is saved via the editor it stores all the information, meaning brightness, color_temp, color and everything is sent to the bulb once the scene is triggered. Need to manually update the yaml to ensure only the needed command is sent.

@postlund
Copy link
Collaborator Author

Thanks @ultratoto14, I will a greater look. I think I have implemented most things in a similar manner, not RGB though. But I can take some inspiration from your code for that. One change I'm planning is to use a single option for color values, as HSV or RGB can be deduced from length of the value.

Color temperature is a different matter, related of course. Should be simple enough to implement (there is also an issue about it: #91). I intend to add two options to allow custom values for lower and upper range, specified in Kelvin and converted to mired internally.

@ultratoto14
Copy link
Collaborator

I used the set_dps you introduced, i fixed the unneeded value and put the corresponding in common.py

My full list of devices:

  • Led Strip HSV mode
  • GU10 RGBW RGB mode
  • GU10 RGBW HSV mode
  • Color Bulb HSV mode

They are from different manufacturers and all the one in HSV are using this 1000 range where the RGB_HSV are using the 255 range.
Do you know HSV lights using the 255 range ?

@postlund
Copy link
Collaborator Author

I would not expect HSV to be limited to 255 like that. This picture explains HSV pretty well:

@ultratoto14
Copy link
Collaborator

;-) my question was not clear. Do you know tuya lights that uses HSV coding for the color and 255 range for brightness and color_temp ? Because if you deduce the kind of color from the length, you can then also deduce the max value for brightness and color_temp.
As many things should be setup for a simple light, if the configurator can help the user in choosing the configuration values, it's a big addition.

@postlund
Copy link
Collaborator Author

Ah, yes, then I understand. No, I don't know about that and I would expect that to not exist either. They however seem to use the same brightness range for white and color, so no distinction needs to be made there. Color temperature uses a different range based on mirad/kelvin range of the lamp and has to be entered separately.

@postlund postlund force-pushed the light_hsv branch 2 times, most recently from 5d510a4 to 722aa70 Compare October 19, 2020 08:25
@postlund postlund changed the title wip: testing with light hsv color support Add support for HSV encoded color lights Oct 19, 2020
@postlund postlund requested a review from rospogrigio October 19, 2020 08:27
@postlund
Copy link
Collaborator Author

Tested and only needs review before merging!

@ultratoto14
Copy link
Collaborator

ultratoto14 commented Oct 19, 2020

Just tested it, two main remarks:

  • Color temp range is not aligned but perhaps it's not the purpose of this PR (cold white not accessible 255-> 1000)
  • When going from colour to white mode, the bulb icon do not switch to the white and keep the old color setup

@postlund
Copy link
Collaborator Author

@ultratoto14 Thanks for testing! Color temperature will be dealt with in #91. Regarding the icon, not sure how that works. Will have to look into that, thanks for reporting!

@postlund
Copy link
Collaborator Author

@ultratoto14 Pushed an update now, can you try if icon works as expected?

@ultratoto14
Copy link
Collaborator

@postlund Icon is now working as expected.

@postlund
Copy link
Collaborator Author

@ultratoto14 Brilliant, thanks! 🎉

@ultratoto14
Copy link
Collaborator

@postlund, i found a remaining small bug about the consistency of the brightness setting.
If you go from white to colour, the brightness is conserved. I think it's the desired behavior.
Once in color, i you change the brightness, it's still working. But when you go back to white, the brightness is the same as before going to color.
Steps to reproduce:

  • Put in white - OK
  • Set brightness to 50% - OK
  • Choose a color - OK brightness still at 50%, color is OK too
  • Change brightness to 100% - OK
  • Change color_temp to get back to white: KO brightness is back to 50%

@postlund
Copy link
Collaborator Author

@ultratoto14 Ok, that's interesting. Maybe I should set white and color brightness at the same time to keep them in sync. I guess we could try that.

@postlund
Copy link
Collaborator Author

@ultratoto14 Loong-shot here, but please try the latest commit and see if it works as expected (or at all).

@ultratoto14
Copy link
Collaborator

ultratoto14 commented Oct 22, 2020

Hi @postlund, sorry for the delay. I still have a couple of hours to test before being unavailable for 3 days.
Unfortunately, the fix does not work. During the test , at the third step, changing brightness when in color, the bulb switch back to white.
Setting the brightness dp when in color mode is switching the bulb to white, it should not be set every time.

@lapy
Copy link

lapy commented Oct 23, 2020

Hi guys,

I hadn't noticed this pull request so I added this feature by myself on my fork.
I tested it on a tuya compatible E14 bulb.

Working:

  • Color selection
  • Color brightness
  • Improved white temp mapping (for me the original code only covered 1/4 of the range)

Please take a look if that helps! (another set of eyes/ideas).

lapy@7d76d91
Please ignore the workspace.xml file :)

Thank you,
Vince

@ultratoto14
Copy link
Collaborator

Hi @postlund, tried to find the problem and it seems that the update and turn on are competing.
You can update the brightness when changing the color_temp between line 171 and 172.

          if not self._is_white_mode:
            await self._device.set_dp(self._brightness, self._config.get(CONF_BRIGHTNESS))
            await self._device.set_dp("white", self._config.get(CONF_COLOR_MODE))

You need to apply the brightness first because of the status updated.
When you will use a single call to apply multiple DPs, the problem may be solved.

@postlund
Copy link
Collaborator Author

@ultratoto14 Seems like @lapy has come a longer way than I have (especially since I haven't prioritized this recently), maybe you can try his commit and see it if works better? At the end of the day I would love to see someone else implement this so I can focus on core stuff instead 🙃

@postlund
Copy link
Collaborator Author

@lapy Send a PR, I can review it for inclusion here and @ultratoto14 can probably test it.

@SmartM-ui
Copy link

@ultratoto14 Seems like @lapy has come a longer way than I have (especially since I haven't prioritized this recently), maybe you can try his commit and see it if works better? At the end of the day I would love to see someone else implement this so I can focus on core stuff instead 🙃

Hi @postlund ,
if I can help I am available to carry out some tests.

Which version are you testing?

@lapy
Copy link

lapy commented Oct 24, 2020

Hi,
This is my pull request #115 if you wanna test it.

Thank you,
Vince

@SmartM-ui
Copy link

Hi,
This is my pull request #115 if you wanna test it.

Thank you,
Vince

OK! Thanks

@SmartM-ui
Copy link

SmartM-ui commented Oct 24, 2020

Hi @postlund ,
I tried the pull # 115 and I must say that as far as the color temperature is concerned it manages to align correctly with the smartlife app.

I was also testing this version # 90, I configured a light bulb via config flow and I could also test the colors and they work correctly and in real time. GREAT!

You just have to fix the color temperature and then you have reached perfection :-)

Thanks

@postlund
Copy link
Collaborator Author

@ultratoto14 Got your email, will respond here so we can decide on how to move forward.

From my point-of-view, it doesn't really matter if we go with my solution or the one by @lapy. I do feel that it'a a bit problematic to not have a steady maintainer behind the code we merge. So I need your input, based on what we have. Should we merge this and continue adding RGB support from @ultratoto14 as well as what else is missing in additional steps? Or should we go with @lapy? I'm up for anything, we just need to increase the pace a bit and get something merged that we can extend upon.

@ultratoto14
Copy link
Collaborator

@postlund, I totally agree with you. I just want to have this included to ensure i can work with it without implementing RGB each time because it's not yet supported. @lapy said he returned his bulb, so he will not maintain the code.
The branch I posted just fixed the brightness pb of your PR, add RGB bulb support and fixed the color_temp.
If it's Ok, I open a PR. As it is based on this one, you close it and link to mine.

@postlund
Copy link
Collaborator Author

Sounds good to me 👍 Let's merge this and continue with additional PRs and writing issues for bugs.

@rospogrigio You can review this now.

Copy link
Owner

@rospogrigio rospogrigio left a comment

Choose a reason for hiding this comment

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

Just one comment, for the rest I think it's ok.

@@ -219,6 +219,8 @@ async def async_added_to_hass(self):
"""Subscribe localtuya events."""
await super().async_added_to_hass()

_LOGGER.debug("Adding %s with configuration: %s", self.entity_id, self._config)
Copy link
Owner

Choose a reason for hiding this comment

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

Do we really want to keep this debug message?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do like this debug print as it will tell us if a certain option is configured or not (it helps when a user thinks a he/she configured an option, but actually didn't).

@postlund postlund merged commit d783293 into master Oct 26, 2020
@postlund postlund deleted the light_hsv branch October 26, 2020 11:09
@postlund
Copy link
Collaborator Author

@ultratoto14 This is merged now. You can rebase your changes on top of master and open a new PR with your changes now.

@ultratoto14
Copy link
Collaborator

@postlund, @rospogrigio, @SmartM-ui the PR120 is created

@SmartM-ui
Copy link

@postlund, @rospogrigio, @SmartM-ui the PR120 is created

Thanks, I'll try now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants