Assistance for coding a card for one appliance with multiple script choices?

I’d like to make a card that activates the on/off status of a fan and also offers several options for speed, all on one line. I saw this example:

image

I have several scripts that set the fan to a certain speed. I’d like each of the icons to activate a different script.

My searches are not finding the right tutorials.

For now, each script is a different line in a card and I’m sure it could be made much more efficient.

to clarify, do you have something that’s working and you’re looking to optimize (your last statement makes it sound like that) or are you not able to figure it out at all?

if you’ve got something that’s close, post what you have. easier for us to mod what you’ve got.

Hi again. Yes, I have individual scripts that accomplish what I need. I’d just like to make it pretty.

To summarize, I have a fan that can only be integrated into HA via a Smartthings integration. Speeds are not directly supported. It will function as a switch and turn on/off, but that is it, using the Smartthings integration.

In order to set speeds, I can either:

  1. Run an imported scene created first within Smartthings.
  2. Use an Alexa Media Player HACS integration to send a voice command directly to an Alexa device as if you’re speaking to it. The fan has Alexa integration that works well and allows % speed commands.

The graphic in the initial post suggested one could run 3 different scenes/scripts with the 3 icons to the right. It was taken from my thread here:

Currently, I have just this:

type: entities
entities:
  - entity: switch.fan_fan_switch
    name: Fan switch
    icon: mdi:ceiling-fan
  - entity: script.set_fan_60
    name: Fan speed 60%
  - entity: script.set_fan_65
    icon: mdi:fan
    name: Fan speed 65%
  - entity: script.set_fan_68
    name: Fan speed 68%
  - entity: script.set_fan_70
    name: Fan speed 70%

Each speed script looks like this:

service: media_player.play_media
target:
  entity_id: media_player.myname_s_echo_dot
data:
  media_content_type: custom
  media_content_id: set fan speed to 60

So it all functions. But it is a blocky chunk of text + buttons I’d like to condense somehow.

look at tap_action for your entities card. see docs here Entities card - Home Assistant

for example (warning, not tested)

entities:
  - entity: switch.fan_fan_switch
    name: Fan switch
    icon: mdi:ceiling-fan
    tap_action:
       action: call-service
       service: media_player.play_media
       target:
          entity_id: media_player.myname_s_echo_dot
       data:
         media_content_type: custom
         media_content_id: set fan speed to 60

a different way would be to use tap_action have it call your script (instead of media_player.play_media) and pass it the speed.

this doesn’t necessarily shrink the lines of code in your entities card, but it does nuke the need to have 4 different scripts doing nearly the same thing.

Thank you for the links!

I was able to condense my many presets into this glance card with tap_action on each icon, which I find much more usable:

image

Still not sure what kind of card the other user was using to create that initial icon layout, but at least I am on the right path with card constructions!

1 Like