Closed maxi1134 closed 4 years ago
I did try the following with no success:
${ {% if is_state("light.bedroom_lights", "on")%}
states['light.bedroom_lights'].state === "on" &&
states['light.bedroom_lights'].attributes.rgb_color[0] > 250 &&
states['light.bedroom_lights'].attributes.rgb_color[1] > 250 &&
states['light.bedroom_lights'].attributes.rgb_color[2] > 250 ?
'hue-rotate(0deg)' : 'hue-rotate(' +
states['light.bedroom_lights'].attributes.hs_color[0] + 'deg)' {%
endif%} }
${ states['light.bedroom_lights'].state === "on" ?
states['light.bedroom_lights'].attributes.rgb_color[0] > 250 &&
states['light.bedroom_lights'].attributes.rgb_color[1] > 250 &&
states['light.bedroom_lights'].attributes.rgb_color[2] > 250 ?
'hue-rotate(0deg)' : 'hue-rotate(' +
states['light.bedroom_lights'].attributes.hs_color[0] + 'deg)' }
${ states['light.bedroom_lights'].state === "on" ||
states['light.bedroom_lights'].attributes.rgb_color[0] > 250 &&
states['light.bedroom_lights'].attributes.rgb_color[1] > 250 &&
states['light.bedroom_lights'].attributes.rgb_color[2] > 250 ?
'hue-rotate(0deg)' : 'hue-rotate(' +
states['light.bedroom_lights'].attributes.hs_color[0] + 'deg)' }
This is JavaScript templating, not Jinja2. Before checking a attribute (property) you should check if it exists first.
$(states['light.bedroom_lights'].attributes.rgb_color &&
states['light.bedroom_lights'].attributes.rgb_color[0] > 250 &&
states['light.bedroom_lights'].attributes.rgb_color[1] > 250 &&
states['light.bedroom_lights'].attributes.rgb_color[2] > 250 ?
'hue-rotate(0deg)' : 'hue-rotate(' +
states['light.bedroom_lights'].attributes.hs_color[0] + 'deg)' ) }
Amazing! Thanks!
It doesn't crash anymore, although the color doesn't change anymore as before.
Is it possible that the "states['light.bedroom_lights'].attributes.rgb_color" is returning false? How could I check that?
After further investigation, It seems like you're missing a "{" in your code
$(states['light.bedroom_lights'].attributes.rgb_color &&
states['light.bedroom_lights'].attributes.rgb_color[0] > 250 &&
states['light.bedroom_lights'].attributes.rgb_color[1] > 250 &&
states['light.bedroom_lights'].attributes.rgb_color[2] > 250 ?
'hue-rotate(0deg)' : 'hue-rotate(' +
states['light.bedroom_lights'].attributes.hs_color[0] + 'deg)' ) }
I've added the curly bracket
${(states['light.bedroom_lights'].attributes.rgb_color &&
states['light.bedroom_lights'].attributes.rgb_color[0] > 250 &&
states['light.bedroom_lights'].attributes.rgb_color[1] > 250 &&
states['light.bedroom_lights'].attributes.rgb_color[2] > 250 ?
'hue-rotate(0deg)' : 'hue-rotate(' +
states['light.bedroom_lights'].attributes.hs_color[0] + 'deg)' ) }
And the problem comes back.
Hi there!
I discovered this and so glad I am having a blast using this tool for an interactive floorplan.
Although, I am now encountering an issue where my code doesn't work if my lights are off (Since the hs_color and rgb_color attributes are invalid when the light is off).
This is the code that I have currently working (with the lights on)
How could I add a pre-condition to my conditions? So that the
blob is ignored when the light is off?
Thanks for reading!