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

Exposing action_brightness_delta to allow better blueprints #8369

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

TheUnlimited64
Copy link

This enables home assistant users to have a better dimming experience using automations like, therefore zha is not needed anymore for smooth dimming experience.

[https://github.com/TheUnlimited64/tuya_smart_knob_blueprint](url)

Only issue currently (atleast with mine) is that there seems to be a cooldown after ~2s. If I dimm long enough it stops receiving. But I'm not sure how to mitigate it.

This enables the home assistant community to access the
action_brightness_delta value inside blueprints and therefore have a
much more pleasing dimming experience than before.
@Koenkk
Copy link
Owner

Koenkk commented Nov 24, 2024

This expose should not always be present, since it is only there when the simulated_brightness option is activated. I would add it here instead: https://github.com/Koenkk/zigbee2mqtt/blob/69f728295224c06ce509eb3afdf611b37ca8fa37/lib/extension/homeassistant.ts#L1535 ( if (isDevice && entity.options.simulated_brightness) {

@TheUnlimited64
Copy link
Author

@Koenkk thats a great Idea! Wasn't really sure how the exposing works, but I'm digging deaper. Is there maybe a dev docs? I already have an additional feature for this and potentially more sensors in mind.

But I'm very pleased that I can overwrite pretty much everything with a custom converter, makes developing/testing a breeze :)

Tomorrow or in a few days I'll add it when I figured everything out and put it in the right place

@TheUnlimited64
Copy link
Author

Hi @Koenkk,

I've updated my PR with a new feature implementation called simulated_color_temperature.
The implementation is more straightforward compared to simulated_brightness as my sensor
doesn't provide a command_stop functionality, so the interval would be useless currently.

Additionally, I'd appreciate some guidance on implementing the exposure in homeassistant.ts.
I'm not entirely clear on the exposure line's functionality, which is preventing me from
implementing the correct exposure method.

Could you please provide some direction on this?

Thanks!

@@ -1424,6 +1425,22 @@ const converters1 = {
payload.action_transition_time = msg.data.transtime / 100;
}

if (options.simulated_color_temperature) {
const deltaOpts = options.simulated_color_temperature_delta ?? 500;
Copy link
Owner

Choose a reason for hiding this comment

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

I assume the delta is in Kelvin, I propose to use mireds here as that is what the ZCL uses.

Copy link
Author

Choose a reason for hiding this comment

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

Did change it to midred

const deltaOpts = options.simulated_color_temperature_delta ?? 500;

if (globalStore.getValue(msg.endpoint, 'simulated_color_temperature') === undefined) {
let color_temperature = globalStore.getValue(msg.endpoint, 'simulated_color_temperature_temperature', 2000);
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
let color_temperature = globalStore.getValue(msg.endpoint, 'simulated_color_temperature_temperature', 2000);
let colorTemperature = globalStore.getValue(msg.endpoint, 'simulated_color_temperature_temperature', 2000);

@Koenkk
Copy link
Owner

Koenkk commented Nov 29, 2024

I'm not entirely clear on the exposure line's functionality, which is preventing me from
implementing the correct exposure method.

Can you clarify it a bit more? Then I can help.

…toring

Now no hardcoded min/max values and using midred instead of kelvin
@TheUnlimited64
Copy link
Author

Can you clarify it a bit more? Then I can help.

You suggested instead of exposing the additional information action_brightness_step (and therefore also action_color_step_temperature) to expose it with the homeassistant.ts file. But I'm not sure how that would look like.

Also wouldn't hardcoding it be a bad pattern? A more straight forward principle might be better for future solutions, doesn't it? Maybe we could define base exposes but overwrite them at device level? That way an user has control to expose any mqtt data that it needs. What do you think about this solution?

Also whats a bit ugly is that in the options descriptions often says like default is 20. But that 20 is hardcoded into the converter function itself. I did try to think of an solution to set an default at option level but that wouldn't work with the current architecture. Atleast I can't think of a good way of implementing such functionality and it would presuppose that an option is toggleable via the UI (because if they're default values any option would be turned on automatically)

@TheUnlimited64 TheUnlimited64 marked this pull request as draft November 30, 2024 13:17
@Koenkk
Copy link
Owner

Koenkk commented Dec 1, 2024

An alternative would be to dynamically add it to exposes, you cannot always add it there since not everyone is using this option. Then it can be added here:

if (definition.exposes && Array.isArray(definition.exposes) && !definition.exposes.find((e) => e.name === 'linkquality')) {

(which would mean prepareDefinition needs to receive the options)

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

Successfully merging this pull request may close these issues.

2 participants