-
Notifications
You must be signed in to change notification settings - Fork 568
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
Re-map light brightness range #80
Conversation
@rospogrigio I think this is ready, but I want SmartM-ui (forums) to try it out with #62 before merging. But feel free to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And you too should update the YAML samples in __init__.py
😄
custom_components/localtuya/light.py
Outdated
mapped = (value - from_lower) * (to_upper - to_lower) / ( | ||
from_upper - from_lower | ||
) + to_lower | ||
return int(min(max(mapped, to_lower), to_upper)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not round
instead of int
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only n00bz use round
. So yeah, let's use round
!
Lol, yeah 😉 |
Should be fixed now! |
Home Assistant uses brightness range 0-255 whilst Tuya somewhere around 29-1092. This commit maps brightness between these two ranges.
Here I am! I installed version # 80, restarted Home Assistant, put this code in my yaml file and restarted HA localtuya:
Unfortunately there is still the problem that it fails to turn on the light bulb and after 2 seconds the status returns to off and in any case it cannot manage even the brightness. Log: |
Oh, I screwed up... Gimmie a moment to fix that. |
I have updated the PR now, try updating and run again. Should be smooth sailing now ⛵️ |
I'm very happy. |
That's great @SmartM-ui, thanks for verifying 😀 I guess this PR is ready for review @rospogrigio. |
return int(MAX_MIRED - (((MAX_MIRED - MIN_MIRED) / 255) * self._color_temp)) | ||
except TypeError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens here if CONF_COLOR_TEMP is not configured? Is there a default value to return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value is to return None
, but I should probably add an explicit return for it.
OK, then. |
It has been confirmed to work before, so we can take it as a bug if it doesn't work. |
Hi @postlund @rospogrigio , Here are some examples: Center of the slider on LocalTuya (color temp 258) corresponds to 13% on Smartlife app (instead it should be 50%) other test: SmartLife color temp: 10% SmartLife color temp: 50% SmartLife color temp: 100% Hi, I found a different value between SmartLife app and LocalTuya regarding the color temperatyra. Here are some examples: Center of the slider on LocalTuya (color temp 258) corresponds to 13% on Smartlife app instead it should be 50% How can I do to open a new request for ColorTemp? Thanks |
Yeah, this should be fixed as well. We have some hardcoded color temperatures in our implementation. Ideally lower and upper color temperature should be specified in Kelvin. Should be a simple task if someone has some time (I'm trying to figure out RGB at the moment). |
Well, focus on RGB, much more useful! Have a nice day You will insert the news regarding the RGB work progress in the topic: #33 ? |
Home Assistant uses brightness range 0-255 whilst Tuya somewhere around
29-1092. This commit maps brightness between these two ranges.