Phade
(Phade)
June 9, 2022, 1:14pm
1
Hey Everyone!
I am trying to create a button that will choose a random Nanoleaf effect from a list whenever I tap the button, but I keep getting an error.
show_name: true
show_icon: true
type: button
tap_action:
action: call-service
service: light.turn_on
data:
effect: {{ ['Effect 1', 'Effect 2', 'Effect 3', 'Effect 4', 'Effect 5'] | random | string }}
target:
entity_id: light.nanoleaf
name: Random Canvas Scene
icon_height: 50px
icon: mdi:crop-square
The effect list above is just an example. The effect code correctly returns a string when used in the Template Editor. The random examples I found online seem to match this format, however it fails with this error:
Failed to call service light/turn_on. Attempting to apply effect not in the effect list: â{{ [âEffect 1â, âEffect 2â, âEffect 3â, âEffect 4â, âEffect 5â] | random | string }}â
What could be the problem and how do I fix it?
Thanks again!!
tom_l
June 9, 2022, 1:21pm
2
Core dashboard cards do not accept templates with very few exceptions. This is not one of them.
Unless you use this:
Lovelace Templates
Iâve gone and made a crazy card that allows you to pretty much template anything in Lovelace for your card configurations using any information available on the frontend; states, attributes, user, etc.
Want state/attribute-based icons? DONE!
Want dynamic stacks; vertical vs horizontal based on user? DONE!
Want OR conditionals? DONE!
The list is pretty much endless and Iâm sure you all will come up with some crazy stuff. Be sure to share.
Go nuts! Enjoy!
Also you need to quote single line templates.
Also also it is called service_data
in the tap action.
tap_action:
action: call-service
service: light.turn_on
service_data:
effect: "{{ ['Effect 1', 'Effect 2', 'Effect 3', 'Effect 4', 'Effect 5'] | random | string }}"
target:
entity_id: light.nanoleaf
2 Likes
Phade
(Phade)
June 9, 2022, 1:27pm
3
Interesting. The UI button creator used âdataâ instead of âservice_dataâ. Would this be an error in the UI button creator or are these two synonyms?
tom_l
June 9, 2022, 1:30pm
4
Huh. It seems that this has been changed. Ignore that bit about service_data
. Not sure when it happened.
Phade
(Phade)
June 9, 2022, 1:35pm
5
Ahh, ok.
Would there be a way out-of-box to have a button choose a random value from a list without the need to import a custom card?
Thanks again!
123
(Taras)
June 9, 2022, 1:38pm
6
Make the button call a script. Make the script turn on the light and select a random effect.
1 Like
Phade
(Phade)
June 9, 2022, 2:29pm
7
Sometimes itâs the most obvious things that are overlookedâŚ
Thanks for the pointer. That fixed it!!
1 Like