gfrancesco / cwww-template-light-ha Goto Github PK
View Code? Open in Web Editor NEWHome Assistant template light to control cold-white / warm-white LED lights
License: MIT License
Home Assistant template light to control cold-white / warm-white LED lights
License: MIT License
Hi @gfrancesco,
thank you a lot for this great code and for sharing!
In my case, manufacturer of the CCT stripe sais, one should not use it wit both cw and ww set to 100% due to temperature overload.
So the LED controller I'm actually using sets cw and ww to both 50% in case of averaged temperature value and full brightness.
If I got you right, this is one part you DID NOT want to happen. In my case, I would like this to happen (100% cct brightness should be the sum of both cw and ww brightness).
Could you help me adopting the code for this purpose?
When using your code, the brightness automatically changes to 50% when changing temperature to 2700 or 6500K, and I guess this is what you wanted to happen. But as I mentioned, this doesn't favor my stripes.
Would be great to have your help.
Thank you a lot and all the best
Benedikt
Currently, it's changing the stored number helper values based on the calculations. This means that when you go above 50% brightness, it starts clamping the temperature, and this is stored, so when you reduce the brightness again, it's not the same temperature it was before increasing the brightness.
I think a good solution to this would be to store the "desired" brightness/temperature rather than the result of the calculations, and do the calculations in local variables while setting the actual shelly lines.
Cool project and appreciate you sharing it. I'm trying to modify this to lights that I have (ww=2700K, cw=4000K) and I keep getting invalid value errors when trying to change the brightness too high or color temperature too high/low. I've updated the color temperature input helper to be consistent with the temperature values (250-370). Not totally sure what I am doing wrong with the code edits I have made.
family_room_fan_light:
friendly_name: "Family Room Fan Light"
value_template: >-
{{ ( state_attr('light.fan', 'brightness') | int(0) +
state_attr('light.fan_light_2', 'brightness') | int(0) ) > 0 }}
level_template: "{{ states('input_number.family_room_fan_brightness') | int(0) }}"
temperature_template: "{{ states('input_number.family_room_fan_color_temperature') | int(370) }}"
set_level:
- service: input_number.set_value
target:
entity_id: input_number.family_room_fan_brightness
data:
value: "{{ brightness | int(0) }}"
- if:
- condition: numeric_state
entity_id: input_number.family_room_fan_brightness
above: 128
then:
- variables:
perc_above_mid: "{{ ((states('input_number.family_room_fan_brightness') | int(0) - 128) / 127) | float(0) }}"
- if:
- condition: numeric_state
entity_id: input_number.family_room_fan_color_temperature
above: 310
then:
- variables:
warmest: "{{ (370 - (perc_above_mid * 60)) | int(370) }}"
- if:
- condition: numeric_state
entity_id: input_number.family_room_fan_color_temperature
above: 0
value_template: "{{ (float(state.state) - warmest) | int(0) }}"
then:
- service: input_number.set_value
target:
entity_id: input_number.family_room_fan_color_temperature
data:
value: "{{ warmest | int(370) }}"
- if:
- condition: numeric_state
entity_id: input_number.family_room_fan_color_temperature
below: 310
then:
- variables:
coldest: "{{ (250 + (perc_above_mid * 60)) | int(250) }}"
- if:
- condition: numeric_state
entity_id: input_number.family_room_fan_color_temperature
below: 0
value_template: "{{ (float(state.state) - coldest) | int(0) }}"
then:
- service: input_number.set_value
target:
entity_id: input_number.family_room_fan_color_temperature
data:
value: "{{ coldest | int(250) }}"
- service: light.turn_on
target:
entity_id: light.family_room_fan_light
set_temperature:
- service: input_number.set_value
target:
entity_id: input_number.family_room_fan_color_temperature
data:
value: "{{ color_temp | int(370) }}"
- if:
- condition: numeric_state
entity_id: input_number.family_room_fan_brightness
above: 128
then:
- variables:
delta_perc_mean_temp: "{{ (((( (states('input_number.family_room_fan_color_temperature') | int(370) - 249) / 121) - 0.5) | abs ) * 2) | float(0) }}"
max_brightness: "{{ ( (1 - delta_perc_mean_temp) * 127 + 128 ) | int(0) }}"
- if:
- condition: numeric_state
entity_id: input_number.family_room_fan_brightness
above: 0
value_template: "{{ (float(state.state) - max_brightness) | int(0) }}"
then:
- service: input_number.set_value
target:
entity_id: input_number.family_room_fan_brightness
data:
value: "{{ max_brightness | int(0) }}"
- service: light.turn_on
target:
entity_id: light.family_room_fan_light
turn_on:
- variables:
ww_ratio: "{{ (( states('input_number.family_room_fan_color_temperature') | int(370) - 249 ) / 121 ) | float(0) }}"
- service: light.turn_on
target:
entity_id: light.fan
data:
brightness: "{{ (2 * states('input_number.family_room_fan_brightness') | int(0) * ww_ratio) | int(0) }}"
- service: light.turn_on
target:
entity_id: light.fan_light_2
data:
brightness: "{{ (2 * states('input_number.family_room_fan_brightness') | int(0) * (1 - ww_ratio) ) | int(0) }}"
turn_off:
- service: light.turn_off
target:
entity_id: light.fan
- service: light.turn_off
target:
entity_id: light.fan_light_2
I get an invalid configuration message when I load this into my configuration.yaml. Does this rely on the template/light integration, or is it standalone?
living_room_strip:
friendly_name: "Living Room Strip"
value_template: >-
{{ ( state_attr('light.light.strip_channel_2', 'brightness') | int(0) +
state_attr('light.light.strip_channel_1', 'brightness') | int(0) ) > 0 }}
level_template: "{{ states('input_number.LRS_LIGHT_TEMPERATURE') | int(0) }}"
temperature_template: "{{ states('input_number.LRS_LIGHT_TEMPERATURE') | int(500) }}"
set_level:
- service: input_number.set_value
target:
entity_id: input_number.LRS_LIGHT_TEMPERATURE
data:
value: "{{ brightness | int(0) }}"
- if:
- condition: numeric_state
entity_id: input_number.LRS_LIGHT_TEMPERATURE
above: 128
then:
- variables:
perc_above_mid: "{{ ((states('input_number.LRS_LIGHT_TEMPERATURE') | int(0) - 128) / 127) | float(0) }}"
- if:
- condition: numeric_state
entity_id: input_number.LRS_LIGHT_TEMPERATURE
above: 327
then:
- variables:
warmest: "{{ (500 - (perc_above_mid * 173)) | int(500) }}"
- if:
- condition: numeric_state
entity_id: input_number.LRS_LIGHT_TEMPERATURE
above: 0
value_template: "{{ (float(state.state) - warmest) | int(0) }}"
then:
- service: input_number.set_value
target:
entity_id: input_number.LRS_LIGHT_TEMPERATURE
data:
value: "{{ warmest | int(500) }}"
- if:
- condition: numeric_state
entity_id: input_number.LRS_LIGHT_TEMPERATURE
below: 327
then:
- variables:
coldest: "{{ (153 + (perc_above_mid * 174)) | int(153) }}"
- if:
- condition: numeric_state
entity_id: input_number.LRS_LIGHT_TEMPERATURE
below: 0
value_template: "{{ (float(state.state) - coldest) | int(0) }}"
then:
- service: input_number.set_value
target:
entity_id: input_number.LRS_LIGHT_TEMPERATURE
data:
value: "{{ coldest | int(153) }}"
- service: light.turn_on
target:
entity_id: light.living_room_strip
set_temperature:
- service: input_number.set_value
target:
entity_id: input_number.LRS_LIGHT_TEMPERATURE
data:
value: "{{ color_temp | int(500) }}"
- if:
- condition: numeric_state
entity_id: input_number.LRS_LIGHT_TEMPERATURE
above: 128
then:
- variables:
delta_perc_mean_temp: "{{ (((( (states('input_number.LRS_LIGHT_TEMPERATURE') | int(500) - 152) / 348) - 0.5) | abs ) * 2) | float(0) }}"
max_brightness: "{{ ( (1 - delta_perc_mean_temp) * 127 + 128 ) | int(0) }}"
- if:
- condition: numeric_state
entity_id: input_number.LRS_LIGHT_TEMPERATURE
above: 0
value_template: "{{ (float(state.state) - max_brightness) | int(0) }}"
then:
- service: input_number.set_value
target:
entity_id: input_number.LRS_LIGHT_TEMPERATURE
data:
value: "{{ max_brightness | int(0) }}"
- service: light.turn_on
target:
entity_id: light.living_room_strip
turn_on:
- variables:
ww_ratio: "{{ (( states('input_number.LRS_LIGHT_TEMPERATURE') | int(500) - 152 ) / 348 ) | float(0) }}"
- service: light.turn_on
target:
entity_id: light.light.strip_channel_2
data:
brightness: "{{ (2 * states('input_number.LRS_LIGHT_TEMPERATURE') | int(0) * ww_ratio) | int(0) }}"
- service: light.turn_on
target:
entity_id: light.light.strip_channel_1
data:
brightness: "{{ (2 * states('input_number.LRS_LIGHT_TEMPERATURE') | int(0) * (1 - ww_ratio) ) | int(0) }}"
turn_off:
- service: light.turn_off
target:
entity_id: light.light.strip_channel_2
- service: light.turn_off
target:
entity_id: light.light.strip_channel_1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.