Hello,
I am struggling with a template card where I would like to set the mode programmatically.
type: custom:mushroom-template-card
primary: |-
{% if is_state_attr('light.livingroom_main_light', 'night_light', true) %}
normal
{% else %}
moonlight
{% endif %}
icon: mdi:home
icon_color: yellow
layout: vertical
tap_action:
action: call-service
service: yeelight.set_mode
service_data:
entity_id: light.livingroom_main_light
mode: |-
{% if is_state_attr('light.livingroom_main_light', 'night_light', true) %}
normal
{% else %}
moonlight
{% endif %}
entity: light.livingroom_main_light_ambilight
The code above is not working correctly. Upon button click, I get an error that the mode must be of a value normal or moonlight.
The following code works correctly
type: custom:mushroom-template-card
primary: |-
{% if is_state_attr('light.livingroom_main_light', 'night_light', true) %}
normal
{% else %}
moonlight
{% endif %}
icon: mdi:home
icon_color: yellow
layout: vertical
tap_action:
action: call-service
service: yeelight.set_mode
service_data:
entity_id: light.livingroom_main_light
mode: |-
normal
entity: light.livingroom_main_light_ambilight
Do you have any idea, what could be wrong? I really do not understand this. I am pretty sure that the following code should work because when I use it for setting the name, the name is set correctly.
{% if is_state_attr('light.livingroom_main_light', 'night_light', true) %}
normal
{% else %}
moonlight
{% endif %}
Thanks for help.