Custom state card for scripts/scenes with state recognition

Hello,

I just want to share my custom state card I’m using for scenes / scripts:

Instead of having a new line for each script this state card allows you to summarize your scripts like this:

image

In addition to that it is possible to show if a scene/script is active by a binary sensor. In example you can define a mqtt sensor which is updated if you fire your script and the state card will show the current state. In my example I used this configuration:

group.livingroom_harmony:
  friendly_name: Harmony
  icon: mdi:television
  custom_ui_state_card: state-card-custom_scene
  config:
    entities:
      - entity: script.remote_livingroom_harmony_entertain
        friendly_name: TV
        state: binary_sensor.harmony_entertain
      - entity: script.remote_livingroom_harmony_ps4
        friendly_name: PS4
        state: binary_sensor.harmony_ps4
      - entity: script.remote_livingroom_harmony_firetv
        friendly_name: FireTV
        state: binary_sensor.harmony_firetv
      - entity: script.remote_livingroom_harmony_music
        friendly_name: Music
        state: binary_sensor.harmony_music

It is very simple, but maybe it is a help to some of you :slight_smile:

9 Likes

I have been trying to get this to work the whole night but with no luck. Any chance you can show the whole config file so i can have a look what going.

@Eddie1974 Can you post your config files and describe what you would expect? In this example I use it for harmony and use the sensor the platform provides:

group.livingroom_harmony:
  friendly_name: Harmony
  icon: mdi:television
  custom_ui_state_card: state-card-custom_scene
  config:
    entities:
      - entity: script.remote_livingroom_harmony_entertain
        friendly_name: TV
        state: binary_sensor.harmony_entertain
      - entity: script.remote_livingroom_harmony_ps4
        friendly_name: PS4
        state: binary_sensor.harmony_ps4
      - entity: script.remote_livingroom_harmony_firetv
        friendly_name: FireTV
        state: binary_sensor.harmony_firetv
      - entity: script.remote_livingroom_harmony_music
        friendly_name: Music
        state: binary_sensor.harmony_music
harmony_entertain:
  value_template: >-
    {%- if states.remote.livingroom_harmony.attributes.current_activity == 'Entertain' -%}
        True
    {%- else -%}
        False
    {%- endif %}

harmony_firetv:
  value_template: >-
    {%- if states.remote.livingroom_harmony.attributes.current_activity == 'Fire TV' -%}
        True
    {%- else -%}
        False
    {%- endif %}

harmony_ps4:
  value_template: >-
    {%- if states.remote.livingroom_harmony.attributes.current_activity == 'PS4' -%}
        True
    {%- else -%}
        False
    {%- endif %}

harmony_music:
  value_template: >-
    {%- if states.remote.livingroom_harmony.attributes.current_activity == 'Music' -%}
        True
    {%- else -%}
        False
    {%- endif %}

If you have i.e. a script you need to create your own mqtt sensor - This example is described on my GitHub project documentation.

I use it for scenes, got all the script working but it’s not showing up on the front end for some reason.

Post your config and I can help you :slight_smile:

Hi, I would like to use this custom card to show my 4 scenes for my 3 speed fan (sonoff 4 ch mqtt), so to have all the commands in one line and having also the active command highlighted.

so I have 2 questions about it:

  1. I need to create binary sensors and scripts to switch the scenes on? (I use the scenes to turn on only one mqtt switch at time)
  2. how to do it with the scene that just turns off the fan?

Sorry - I know it’s not the best naming. It only support scripts.

  1. Yes, it’s designed to use it with scripts
  2. Use a script

In addition to that my state card needs to be fixed for 0.70 I guess. I will do the next days and keep you updated ok?

1 Like

Thanks for your reply.

So I create and linked the scripts to the already present mqtt switches. Now the group of switches is just looking as any other group of 4 scripts. It is because the fixes needed for 0.70 or I’m still missing something?

Can you post the configuration and a current screenshot? You should definitely see another view than the standard group.

that’s my configuration

in configuration.yaml:

frontend:
themes: !include_dir_merge_named temi/
javascript_version: latest
extra_html_url:
- /local/custom_ui/state-card-custom_scenes.html
- /local/custom_ui/floorplan/ha-floorplan.html

in customize.yaml:

group.ventilatore:
  friendly_name: Ventilatore
  icon: mdi:fan
  custom_ui_state_card: state-card-custom_scene
  config:
  entities:
    - entity: script.vent_vel1
      friendly_name: "1"
      state: switch.vent1
    - entity: script.vent_vel2
      friendly_name: "2"
      state: switch.vent2
    - entity: script.vent_vel3
      friendly_name: "3"
      state: switch.vent3
    - entity: script.vent_off
      friendly_name: "Off"
      state: off

in groups.yaml:

Ventilatore:
  - script.vent1
  - script.vent2
  - script.vent3
  - script.vent_off

the scripts linked turn on and off the mqtt switches (1on-2off-3off, 1off-2on-3-off, 1off-2off-3on, 1off-2off-3off)

and the screenshot
https://i.imgur.com/fbM9sq5.png

I think your indentation is not correct - Try it like:

group.doorlock_maindoor:
  custom_ui_state_card: state-card-custom_scene
  config:
    entities:
      - entity: script.doorlock_maindoor_open
        friendly_name: Öffnen
        state: binary_sensor.dummy_always_on
      - entity: script.doorlock_maindoor_lock
        friendly_name: Verriegeln
        state: binary_sensor.dummy_always_on
      - entity: script.doorlock_maindoor_unlock
        friendly_name: Entriegeln
        state: binary_sensor.dummy_always_on

I checked twice and it’s a mistake I made when pasting into the textbox for posting, but actually the indentation

entities:
  - entity:

is correct. otherwise I think HA would give some errors and get stuck.