Hi, I’m creating a custom widget. I want to increase/decrease the brightness of several hue bulbs by exactly 10%.
Problem 1: The value is not increased/decreased by 10, but by something 10 +/- 0.12.
If value is 0% usually +10 leads to 9.88%. Next try to increase leads to 19.76% and so on.
If the value is 100%, minus butten reduces the value by 9.88 each time.
Solution 1: No solution yet. Mybe rounding is a solution becaus of translation from a byte value (0-255 to 0-100) - any suggestions?
Yaml code (2 buttons, one label in the middle):
- component: oh-button
config:
action: command
actionCommand: '=items[props.itemHelligkeitHueBadezimmer].state >= 90 ? 100 : items[props.itemHelligkeitHueBadezimmer].state + 10'
actionItem: =props.itemHelligkeitHueBadezimmer
slots:
default:
- component: f7-icon
config:
f7: lightbulb_fill
style:
color: green
- component: Label
config:
text: =Number.parseFloat(items[props.itemHelligkeitHueBadezimmer].state) + "%"
- component: oh-button
config:
action: command
actionCommand: '=items[props.itemHelligkeitHueBadezimmer].state <= 10 ? 0 : items[props.itemHelligkeitHueBadezimmer].state - 10'
actionItem: =props.itemHelligkeitHueBadezimmer
slots:
default:
- component: f7-icon
config:
f7: lightbulb
style:
color: green
Problem 2: If I try set the brigthness to zero, an communication error occurs. If the value is larger than 10, it works (with the code mentioned above, actionCommand of the 2. button).
Solution 2: No solution yet. How can I set the value to zero? This row:
actionCommand: '=items[props.itemHelligkeitHueBadezimmer].state <= 10 ? 0 : items[props.itemHelligkeitHueBadezimmer].state - 10'
Problem 3: If brightness was changed by hue app e.g., value could be an uneven value (22.92% e.g).
Solution 3: Value is adapted depending on current value (plus button for example). But: If rouding is a solution for Problem 1, this approach could change. This is one long row:
actionCommand: '=items[props.itemHelligkeitHueBadezimmer].state >= 90 ? 100 :
items[props.itemHelligkeitHueBadezimmer].state >= 80 ? 90 :
items[props.itemHelligkeitHueBadezimmer].state >= 70 ? 80 :
items[props.itemHelligkeitHueBadezimmer].state >= 60 ? 70 :
items[props.itemHelligkeitHueBadezimmer].state >= 50 ? 60 :
items[props.itemHelligkeitHueBadezimmer].state >= 40 ? 50 :
items[props.itemHelligkeitHueBadezimmer].state >= 30 ? 40 :
items[props.itemHelligkeitHueBadezimmer].state >= 20 ? 30 :
items[props.itemHelligkeitHueBadezimmer].state >= 10 ? 20 : 10'
EDIT:
Regarding Problem 2: Converting the value to string did not solve the isse (like described here).
Problem 4 occured: Value is 0%. Plus-button leads to 9.88%. Next time plus-button leads to 9.8801%, next time to 9.880101% and so on. This is not reproducible…