[SOLVED] Help in Creating Conditional Cards

Hello everyone,
I would like a bit of your help regarding Conditional Cards.
I have two things I want to create.
Firstly, I have my water heater set up with an automation to turn off after 25 minutes when I turn it On. So, I want to create a Conditional Card where, when it detects the water heater is on, it displays a card with a 25-minute countdown. I’ve managed to create a helper and include it in the card, but I haven’t found an option to automatically trigger it when the water heater turns on.

type: conditional
conditions:
  - condition: state
    entity: switch.sonoff_10018cb227
    state: 'on'
card:
  type: entities
  entities:
    - entity: timer.water_heater
  state_color: true

The other issue I have is that I want to create a Conditional Card containing all my media players. Ideally, I would like it to display only the active one(s) each time. Is this possible?
Below is my first attempt but it doesn’t work.

type: conditional
conditions:
  - condition: state
    entity: media_player.nicks_tv_3
    state_not: 'off'
  - entity: media_player.plex_plex_for_android_tv_nick_s_tv
    state_not: 'off'
  - entity: media_player.playstation_5
    state_not: 'off'
  - entity: media_player.spotify_nick
    state_not: 'off'
card:
  type: custom:layout-card
  layout_type: custom:masonry-layout
  layout: {}
  cards:
    - type: media-control
      entity: media_player.nicks_tv_3
    - type: media-control
      entity: media_player.plex_nick_sony_tv
    - type: media-control
      entity: media_player.spotify_nick
    - type: media-control
      entity: media_player.playstation_5

Not sure exactly what you are asking for here but, if you want the card to show when the timer is running, try this:

  - type: conditional
    conditions:
    - entity: timer.water_heater
      state_not: idle
    card:
      ...

When you create a Conditional Card, you see a big blue field which says that all conditions must be met. So if one mediaplayer is off, the card will not be displayed. Use a Filter Card instead, example:


type: entity-filter
entities:
  - media_player.sony
  - media_player.echo_dotchen
state_filter:
  - operator: '!='
    value: 'off'
card:
  type: custom:layout-card
  layout_type: custom:masonry-layout

The entities that meet the conditions will automatically be displayed without defining them again in the custom card.

The timer starts when you add another action to your automation:


service: timer.start
data:
  duration: "0:25:0"
target:
  entity_id: timer.xy

Thank you for your reply, I really appreciate it.
I attempted your suggestion, and while it worked, I encountered two issues.
1st, despite using the same card layout, the display appears different, lacking the image of the media and the controls.
image

image

and the second one is when plex and Spotify are inactive, the cards are keep being visible.
image

type: entity-filter
entities:
  - media_player.sony_ke_55xh9077
  - media_player.plex_nick_sony_tv
  - media_player.playstation_5
  - media_player.spotify_nick
state_filter:
  - operator: '!='
    value: 'off'
card:
  type: custom:layout-card
  layout_type: custom:masonry-layout
  layout: {}

Regarding the timer for the life of me I cannot get it to work… I definitely do something wrong.
Following jchhnot John advise nothing changed.
as for pedolsky I could not add your code into the automation.

Timer: It’s simply


  action:
    - service: timer.start
      data:
        duration: "0:25:0"
      target:
        entity_id: timer.your_timer

Filter Card: Expected behaviour because the player is not off (it’s idle). Change the state-filter to


state_filter:
  - operator: '=='
    value: 'playing'

or access the extended functionality by using entity:


type: entity-filter
entities:
  - entity: media_player.sony
    state_filter:
    - operator: '!='
      value: 'off'
  - entity: media_player.echo_dotchen
    state_filter:
    - operator: '!='
      value: 'idle'
card:
  type: custom:layout-card
  layout_type: custom:masonry-layout

I can’t explain why the Media Control Card looks different for Spotify, I only heard rumours that the API makes problems sometimes.
Have you tried to put back the cards in Layout Card?

It’s not just the Spotify, its all the cards. they are not displaying as Media Cards.
I’ve tried

card:
  type: media-control

but with no success

As for the timer
I want to create a card that is displaying the timer only when the water heater is on.
And I want for the timer to start when the state of the heater is turned to on.
I’ve tried something like this

type: conditional
conditions:
  - condition: state
    entity: switch.sonoff_10018cb227
    state: 'on'
card:
  type: entities
  entities:
    - entity: timer.water_heater
  state_color: true

I can confirm that the Filter Card is buggy. Somit isn’t an option currently.

Timer:

Did you adjust your automation as what I suggested?

I believe I’ve got it!

type: entity-filter
entities:
  - entity: media_player.sony_ke_55xh9077
    type: media-control
    artwork: cover
    icon: ''
    state_filter:
      - operator: '!='
        value: 'off'
  - entity: media_player.plex_nick_sony_tv
    type: media-control
    artwork: cover
    icon: ''
    state_filter:
      - operator: '!='
        value: unavailable
  - entity: media_player.playstation_5
    type: media-control
    artwork: cover
    icon: ''
    state_filter:
      - operator: '!='
        value: 'off'
  - entity: media_player.spotify_nick_
    type: media-control
    artwork: cover
    icon: ''
    state_filter:
      - operator: '!='
        value: idle
card:
  type: custom:layout-card
  layout_type: custom:masonry-layout
  layout: {}

I don’t understand what exactly I must add to the automation…

alias: Heater Timer
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.sonoff_10018cb227
    from: "off"
    to: "on"
condition: []
action:
  - delay:
      hours: 0
      minutes: 25
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: c79893cf75ff471bf568c96bb6e4c9ca
    entity_id: e068115a0891bc527dd5733c25cf339c
    domain: switch
mode: single

See my comment above. Add another action to your action part.


alias: Heater Timer
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.sonoff_10018cb227
    from: "off"
    to: "on"
condition: []
action:
  - service: timer.start
    data:
      duration: "0:25:0"
    target:
      entity_id: timer.your_timer

  - delay:
      hours: 0
      minutes: 25
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: c79893cf75ff471bf568c96bb6e4c9ca
    entity_id: e068115a0891bc527dd5733c25cf339c
    domain: switch
mode: single

1 Like