I have both a light and a remote (the one with bright and temperature buttons) from Ikea integrated into Hassio. Yesterday, I coded a automation in which when brightness buttons in the remote are pressed, the brightness from the light is either increased or decreased. I used something similar to this and it is perfectly working:
However, I was trying to apply the same sort of code to change the light temperature but it was impossible. I manage to set a specific color through ācolor_tempā attribute but I can not find and attribute in this light that stores the actual ācolor_tempā so I can code something like:
Note: you should ensure that brightness does not exceed 255. Likewise colour temp maximum will depend on your light model. Use conditions to stop the automation from happening if adding 10 will exceed the maximum values.
Tom, I was going to say that the template should be expanded to do the limit checking. But we are just assuming brightness is 255 (dependant on light model but āmostā manufacturers adhere to common sense standard so a pretty sure bet) but the colour temperature ??? I have no idea (2300 to 4800 ??? Or some other equally arbitrary number set!)
Alex seems new(ish) to be doing this but actually got 90% of it right so my hat off to him. If he need to get his head round this and expand it later, then thatās a good strategy.
My question to you is how do you know how far to go?
I tend to persue a solution till itās a gnats āpleasure stickā short of perfection, but that does seem to overwhelm some people
As far as I knew (Iām quite new in HA) before posting the question, states.light.light_name.attributes.brightness gave an integer, but I will double check when I arrive home to be 100% sure.
For sure, what you mention about the conditions to ensure that limits are not exceeded should be introduced in my automation so I will code that, thanks for the advice. I know both brightness limits (0-255) and temperature limits (min_mireds: 153, max_mireds: 500) so that should not be a problem.
I will try this solution and see if I can make it work.
No it doesnāt.
It appears to give a number but its a string.
All states are stored as strings and you have to convert them to a format you can appropriately manipulate, integer in this case
Iāve never heard of mireds (how ignorant am I ?) prolly cos I donāt have any lights with varying color temperatures. Looking at your link itās a brilliant way of linearising colour temperature rather than the apparent inverse square of the degrees Kelvin.
Do all such bulbs expose both as I think (I havenāt paid enough attention to be certain) I have only seen Kelvin previously.
Thank for the link
Me too,
But itās like centigrade, ah! 50Ā° thatās half way between water freezing and boiling (at a given average air pressure at sea level) Iāve got a good feel for that. Go back to Fahrenheit ? - No Thank You !
Given the linearity of the model, it makes absolute sense and Iām sure Iāll get used to it (though Iām going to have to do a lot of conversions before I get there)
I have been trying to implement the temperature change but I have not been able.
Following your suggestion, I recoded the automation and I have the one to change the brightness working like this (I know that I should include the conditions for the limits):
However, if I replicate this automation for color temperature like:
- id: '1574447424187'
alias: Subir Temperatura Luz
description: Incrementa el color de temperatura de la luz. Mas naranja
trigger:
- device_id: f0c96649677f48af84e82f0a949a1118
domain: deconz
platform: device
subtype: right
type: remote_button_short_press
condition: []
action:
- service: light.turn_on
entity_id: light.luz_lampara_salon
data_template:
color_temp: '{{ state_attr(''light.luz_lampara_salon'', ''color_temp'')|int + 100}}'
This is not working. Do you know what am I doing wrong?
Thats what puzzles me. The light has a temperature color which I can modify via the Lovelace interface, but it does not seem to have an attribute color_temp:
Hereās a reusable script. The parameters are the light entity to control, the number of steps you wish to have, and the number of steps to adjust (can be negative). For example, steps -2 and total_steps 5 would decrease the colour temperature by 2/5 of the range of the light.
alias: Change relative colour temperature
fields:
total_steps:
name: Total steps
description: Number of steps between minimum and maximum clour temperature
selector:
number:
min: 1
max: 10
step: 1
required: true
default: 5
light_entity:
selector:
entity: {}
name: Entity
required: true
description: The light entity to adjust
steps:
selector:
number:
min: -10
max: 10
step: 1
name: Steps
description: Steps to adjust
default: 1
required: true
sequence:
- service: light.turn_on
data:
color_temp: |-
{{ min(
max(
(state_attr(light_entity, 'color_temp') or 0) + steps *
((state_attr(light_entity, 'max_mireds') or 1000) - (state_attr(light_entity, 'min_mireds') or 0))
/ total_steps,
state_attr(light_entity, 'min_mireds') or 0
),
state_attr(light_entity, 'max_mireds') or 1000
)
}}
data_template:
entity_id: "{{ light_entity }}"
icon: mdi:sun-thermometer-outline
mode: single
I attempted the same thing in parallel with kelvin, itās not working either. I thought perhaps they were conflicting, but I canāt get either to operate.
The template values show up correctly in the dev tools template editor.
This appears to be a problem with the smartthings integration I had to access these bulbs through. I am using Cloudflared to access my domain. Getting a p.client_exceptions.ClientResponseError: 520, message=āServer Error (520)ā, url=āhttps://api.smartthings.com/v1/devices/---redacted---/commandsā