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

Re-map light brightness range #80

Merged
merged 3 commits into from
Oct 16, 2020
Merged

Re-map light brightness range #80

merged 3 commits into from
Oct 16, 2020

Conversation

postlund
Copy link
Collaborator

Home Assistant uses brightness range 0-255 whilst Tuya somewhere around
29-1092. This commit maps brightness between these two ranges.

@postlund postlund added the enhancement New feature or request label Oct 13, 2020
@postlund postlund requested a review from rospogrigio October 14, 2020 07:43
@postlund
Copy link
Collaborator Author

@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.

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.

And you too should update the YAML samples in __init__.py 😄

mapped = (value - from_lower) * (to_upper - to_lower) / (
from_upper - from_lower
) + to_lower
return int(min(max(mapped, to_lower), to_upper))
Copy link
Owner

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?

Copy link
Collaborator Author

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!

@postlund
Copy link
Collaborator Author

And you too should update the YAML samples in __init__.py 😄

Lol, yeah 😉

@postlund
Copy link
Collaborator Author

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.
@SmartM-ui
Copy link

Here I am!
Nice to read you, I almost worry when you don't answer right away :-)

I installed version # 80, restarted Home Assistant, put this code in my yaml file and restarted HA

localtuya:

  • host: 192.168.1.131 #lampadario studio
    device_id: 6xxxxxxd
    local_key: bxxxxxxxx9
    friendly_name: Lampadario Studio LocalTuya
    protocol_version: "3.3"
    entities:
    • platform: light
      friendly_name: Lampadario Studio LocalTuya
      id: 20
      brightness: 22
      color_temp: 23
      brightness_lower: 10
      brightness_upper: 1000

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:
2020-10-15 20:22:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [6xxxxxxxxxxxxxd] Sending command heartbeat (device type: type_0a)
2020-10-15 20:22:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [6xxxxxxxxxxxxxd] Paylod: b'{}'
2020-10-15 20:22:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [6xxxxxxxxxxxxxd] Waiting for sequence number -100
2020-10-15 20:22:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [6xxxxxxxxxxxxxd] Got heartbeat response
2020-10-15 20:22:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [6xxxxxxxxxxxxxd] Decode payload: b''
2020-10-15 20:22:14 DEBUG (MainThread) [custom_components.localtuya.pytuya] [6xxxxxxxxxxxxxd] Decrypted payload: {}

@postlund
Copy link
Collaborator Author

Oh, I screwed up... Gimmie a moment to fix that.

@postlund
Copy link
Collaborator Author

I have updated the PR now, try updating and run again. Should be smooth sailing now ⛵️

@SmartM-ui
Copy link

I have updated the PR now, try updating and run again. Should be smooth sailing now ⛵️

I'm very happy.
You did great and you outdid yourself
Now the brightness is managed correctly and even the on off status has no more problems.
Great news in this version that surprised me ...
The LocalTuya app can coexist with the SmartLife app and work in real time! WOW
Pierre I Love You !!!! :-)

@postlund
Copy link
Collaborator Author

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:
Copy link
Owner

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?

Copy link
Collaborator Author

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.

@rospogrigio
Copy link
Owner

OK, then.
Feel free to merge if you think it's ready (don't know if you want to wait for feedback from accelle17 for Nebula lights first).

@postlund
Copy link
Collaborator Author

It has been confirmed to work before, so we can take it as a bug if it doesn't work.

@postlund postlund merged commit 98fee92 into master Oct 16, 2020
@postlund postlund deleted the light_range branch October 16, 2020 10:40
@SmartM-ui
Copy link

SmartM-ui commented Oct 16, 2020

Hi @postlund @rospogrigio ,
I found a different value between SmartLife app and LocalTuya regarding the color temp.
Would it be possible to choose the right range for your bulb so that you can have the color temperature gradations?

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: 0%
LocalTuya color_temp: 370

SmartLife color temp: 10%
LocalTuya color_temp: 284

SmartLife color temp: 50%
LocalTuya color_temp: -57

SmartLife color temp: 100%
LocalTuya color temp: -480

Hi, I found a different value between SmartLife app and LocalTuya regarding the color temperatyra.
Would it be possible to choose the right range for your bulb so that you can have the color temperature gradations?

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

@postlund
Copy link
Collaborator Author

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).

@SmartM-ui
Copy link

Well, focus on RGB, much more useful!
This feature would make LocalTuya the ultimate Tuya device management app.
Hope you can find a way to process RGB colors.
If I can help with the tests, I'm available

Have a nice day

You will insert the news regarding the RGB work progress in the topic: #33 ?

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.

3 participants