Hi,
I’m new to HA and Lovelace so please bear with me.
I want to display my different lights on lovelace with the light-card. But because I have quite many lights, I want to only display 1 room at a time on the light page.
So I figured I’ll use entity-buttons to flip an input_boolean and depending on input_booleans it will display a room.
So created the buttons like this for the first 2 rooms.
cards:
- type: horizontal-stack
cards:
- type: entity-button
name: Livingroom light
entity: input_boolean.button_livingroom
tap_action: toggle
- type: entity-button
name: Kitchen light
entity: input_boolean.button_kitchen
tap_action: toggle
Then created automation which toggles others off, so no more than 1 room will be displaed.
-
alias: Livingroom lights
trigger:
platform: state
entity_id: input_boolean.button_livingroom
to: ‘on’
action:
service: input_boolean.turn_off
entity_id: input_boolean.button_kitchen -
alias: Kitchen lights
trigger:
platform: state
entity_id: input_boolean.button_kitchen
to: ‘on’
action:
service: input_boolean.turn_off
entity_id: input_boolean.button_livingroom
This is working fine. Pressing button toggles 1 room on and the other off. All good so far.
However… Now I want to show cards in lovelace depending on these input_booleans.
Tried several different things, but wont work properly.
Is it possible to somehow use if, elif, else statements in the ui-lovelace.yaml file?
If it is, then I don’t now how. This is not working.
- type: horizontal-stack
cards: >
{% if is_state('input_boolean.button_livingroom', 'on') %}
- type: light
entity: light.livingroomspots
name: Spots
{% elif is_state('input_boolean.button_kitchen', 'on') %}
- type: light
entity: light.kitchentable
name: Kitchentable
{% else %}
- type: light
entity: light.livingroomspots
name: Spots
{% endif %}
Also tried with conditional card, but this wont refresh properly. So it only works if I manually refresh the page or switch to another card and then go back. So the conditional card it the closest to a solution I’ve come.
It works but requires some kind of refresh. Is there some command I could include in the automation that would do this?
- type: conditional
conditions:
- entity: input_boolean.button_livingroom
state: "on"
card:
type: light
entity: light.livingroomspots
name: Spots
- type: conditional
conditions:
- entity: input_boolean.button_kitchen
state: "on"
card:
type: light
entity: light.kitchentable
name: Kitchentable
Any help appreciated highly