Trigger script directly from a lovelace card button

Hi all,

I’m pretty new to lovelace, and a bit rusty with Home Assistant in general. I’m basically trying to create a button on a picture-glance card, that when pressed, will cast my CCTV camera to my TV. I’ve got as far as creating a script that will cast a locally hosted file (my camera isn’t working with the chromecast yet but that’s a separate issue), and that works fine. However when I press the button on the card I get the popup shown below, and then I have to press ‘Execute’ for the script to actually run.

Is there any way to have the script fire when I press the button on the picture-glance card, and remove the extra step with the popup prompt?
ui-lovelace.yaml

title: Home
views:
  - title: Home
    cards:
      - type: picture-glance
        title: Outside
        entities:
          - group.doorlights
          - script.speaktemperature
        camera_image: camera.outside

scripts.yaml

speaktemperature:
  sequence:
    - service: media_player.play_media
      entity_id: media_player.chromecast_livingroom
      data:
        media_content_id: media_content_id: http://192.168.1.3:8123/local/test.mp4
        media_content_type: video/mp4

1 Like

It’s not a very elegant solution, but a template switch will do the trick

switch:
  - platform: template
    switches:
      speaktemperature:
        value_template: "{{ True }}"
        turn_on:
        turn_off:
          - service: script.speaktemperature

And then put switch.speaktemperature in your picture-glance.

Note: I chose to put the switch as always on, and run the switch on turn_off because I think a switch that’s on looks better on a picture-glance than one that’s off.

I totally agree…can we use an option to execute directly?

Hi, the setting of the “fake” switch must be in the config.yaml ?

No, it could be almost anywhere, in your config, you could create a domain config of switch.yaml (or thingumie.yaml if you prefer) included from config from the switch domain or as I run things from packages, in any one of those. Depends where you are on the path, how much you’ve read and how comfortable you are editing files by hand getting things wrong and having another go. The first is much easier for newbies but means your files get very complicated very quickly. IMO anyway :laughing:

And it’s not fake, it’s real but it is a software construct not existing in the physical world (but HA acts the same)