jeppper
(Jeppper)
February 13, 2021, 7:52pm
1
I want to have some lights use a random effect and a certain brightness depending on the chosen effect. The effect part works fine but the brightness level is the one from the previous effect.
This is my script. What is wrong?
- service: light.turn_on
data_template:
entity_id:
- light.stairs
effect: >-
{{ [
"Chase",
"Saw",
"Washing Machine",
"Pacifica",
"Solid",
"Blends"
] |random }}
brightness: >-
{%- if state_attr("light.stairs", "effect") == 'Chase' %}
10
{%- elif state_attr("light.stairs", "effect") == 'Saw' %}
20
{%- elif state_attr("light.stairs", "effect") == 'Washing Machine' %}
30
{%- elif state_attr("light.stairs", "effect") == 'Pacifica' %}
40
{%- elif state_attr("light.stairs", "effect") == 'Solid' %}
50
{%- elif state_attr("light.stairs", "effect") == 'Blends' %}
60
{% endif -%}
Your script is acting as expected. At the time the script executes the effect is the previous one. The effect doesnât change until the service runs.
Youâd need to set the effect only in a service, then delay for like half a second to make sure that the attribute is changed, then set the brightness in a further service call.
jeppper
(Jeppper)
February 13, 2021, 10:56pm
3
You think like this? Is half a second delay possible?
- service: light.turn_on
data_template:
entity_id:
- light.stairs
effect: >-
{{ [
"Chase",
"Saw",
"Washing Machine",
"Pacifica",
"Solid",
"Blends"
] |random }}
- delay: 0:00:01
- service: light.turn_on
data_template:
entity_id:
- light.stairs
brightness: >-
{%- if state_attr("light.stairs", "effect") == 'Chase' %}
10
{%- elif state_attr("light.stairs", "effect") == 'Saw' %}
20
{%- elif state_attr("light.stairs", "effect") == 'Washing Machine' %}
30
{%- elif state_attr("light.stairs", "effect") == 'Pacifica' %}
40
{%- elif state_attr("light.stairs", "effect") == 'Solid' %}
50
{%- elif state_attr("light.stairs", "effect") == 'Blends' %}
60
{% endif -%}
Yeah, exactly like that. For a half second delay change
- delay: 00:00:01
To
- delay:
milliseconds: 500
jeppper
(Jeppper)
February 13, 2021, 11:34pm
5
Thanks for helping, it works fine now
But I have just tried to add an extra attribute, speed. But it returns an error in the logs.
voluptuous.error.MultipleInvalid: extra keys not allowed
Can you tell why?
- service: light.turn_on
data_template:
entity_id:
- light.stairs
effect: >-
{{ [
"Chase",
"Saw",
"Washing Machine",
"Pacifica",
"Solid",
"Blends"
] |random }}
- delay: 0:00:01
- service: light.turn_on
data_template:
entity_id:
- light.stairs
brightness: >-
{%- if state_attr("light.stairs", "effect") == 'Chase' %}
10
{%- elif state_attr("light.stairs", "effect") == 'Saw' %}
20
{%- elif state_attr("light.stairs", "effect") == 'Washing Machine' %}
30
{%- elif state_attr("light.stairs", "effect") == 'Pacifica' %}
40
{%- elif state_attr("light.stairs", "effect") == 'Solid' %}
50
{%- elif state_attr("light.stairs", "effect") == 'Blends' %}
60
{% endif -%}
speed: >-
{%- if state_attr("light.stairs", "effect") == 'Chase' %}
10
{%- elif state_attr("light.stairs", "effect") == 'Saw' %}
20
{%- elif state_attr("light.stairs", "effect") == 'Washing Machine' %}
30
{%- elif state_attr("light.stairs", "effect") == 'Pacifica' %}
40
{%- elif state_attr("light.stairs", "effect") == 'Solid' %}
50
{%- elif state_attr("light.stairs", "effect") == 'Blends' %}
60
{% endif -%}
1 Like
Speed isnât a valid option for the light.turn_on service, all valid options are listed in the table hereâŚ
jeppper
(Jeppper)
February 13, 2021, 11:42pm
7
Okay I see
I wonder what could be used instead.
These are the attributes for the light.
brightness: 40
hs_color: 240,100
rgb_color: 0,0,255
xy_color: 0.136,0.04
effect: Pacifica
intensity: 5
palette: Default
playlist: null
preset: null
speed: 3
friendly_name: Stairs
icon: mdi:stairs
supported_features: 55
I suspect that the speed is part of the effect on the device and not configurable externally. (just a guess)
jeppper
(Jeppper)
February 13, 2021, 11:46pm
9
Okay, sad
But thanks very much for helping
1 Like
jeppper
(Jeppper)
February 17, 2021, 4:46pm
10
I solved the issue regarding speed not beeing possible to use with light.turn.on
I used mqtt instead and have this now. In most cases it works but sometimes one of the templates returns a wrong value.
I tried increasing the delay between âeffectâ and the first template for brightness to 5 seconds, but still same case with wrong values sometimes.
Do you have an idea what could cause this? 5 seconds delay should be more than enough i guess.
- service: light.turn_on
data_template:
entity_id:
- light.trappe
effect: >-
{{ [
"Chase",
"Saw",
"Washing Machine",
"Pacifica",
"Solid",
"Chunchun",
"Colortwinkles",
"Blends"
] |random }}
- delay: 0:00:05
- service: light.turn_on
data_template:
entity_id:
- light.trappe
brightness: >-
{%- if state_attr("light.trappe", "effect") == 'Solid' %}
10
{%- elif state_attr("light.trappe", "effect") == 'Saw' %}
15
{%- elif state_attr("light.trappe", "effect") == 'Washing Machine' %}
15
{%- elif state_attr("light.trappe", "effect") == 'Pacifica' %}
30
{%- elif state_attr("light.trappe", "effect") == 'Chase' %}
15
{%- elif state_attr("light.trappe", "effect") == 'Blends' %}
40
{%- elif state_attr("light.trappe", "effect") == 'Chunchun' %}
30
{%- elif state_attr("light.trappe", "effect") == 'Colortwinkles' %}
40
{% endif -%}
- delay: 0:00:01
- service: mqtt.publish #SPEED mqtt bruges kun til speed og intensity for wled da wled.effect først understøttes i HA fra 0.108
data_template:
topic: wled/trappe/api
payload: >-
{%- if state_attr("light.trappe", "effect") == 'Solid' %}
SX=10
{%- elif state_attr("light.trappe", "effect") == 'Saw' %}
SX=10
{%- elif state_attr("light.trappe", "effect") == 'Washing Machine' %}
SX=5
{%- elif state_attr("light.trappe", "effect") == 'Pacifica' %}
SX=60
{%- elif state_attr("light.trappe", "effect") == 'Chase' %}
SX=50
{%- elif state_attr("light.trappe", "effect") == 'Blends' %}
SX=20
{%- elif state_attr("light.trappe", "effect") == 'Chunchun' %}
SX=1
{%- elif state_attr("light.trappe", "effect") == 'Colortwinkles' %}
SX=40
{% endif -%}
- delay: 0:00:01
- service: mqtt.publish #INTENSITY
data_template:
topic: wled/trappe/api
payload: >-
{%- if state_attr("light.trappe", "effect") == 'Solid' %}
IX=10
{%- elif state_attr("light.trappe", "effect") == 'Saw' %}
IX=15
{%- elif state_attr("light.trappe", "effect") == 'Washing Machine' %}
IX=70
{%- elif state_attr("light.trappe", "effect") == 'Pacifica' %}
IX=55
{%- elif state_attr("light.trappe", "effect") == 'Chase' %}
IX=175
{%- elif state_attr("light.trappe", "effect") == 'Blends' %}
IX=10
{%- elif state_attr("light.trappe", "effect") == 'Chunchun' %}
IX=10
{%- elif state_attr("light.trappe", "effect") == 'Colortwinkles' %}
IX=20
{% endif -%}
That looks fine from here, the only thing I can think is that one of the effects is written differently when itâs displayed as an attribute, like maybe âWashing Machineâ has a capital M when you call the effect, but when itâs displayed as an attribute it has a lowercase M or something?
Otherwise Iâm a bit stumped
jeppper
(Jeppper)
February 18, 2021, 6:41am
12
I looked in the developer tools and alle the attributes have capital letters and looks exactly the same as in the templates⌠strange!