Setting input_text via Button Card

Hi everyone…

Overwhelmed noob here again.

I’m mucking around with some Phillips Hue scenes which has been fun. I’ve just learned that as scenes are not stateless - when i use a button card to select a scene, I’d like the pressing of the button to update an input_text helper so I can display the currently selected scene on another part of the dashboard.

I’ve look in several spots and subsequently tried a couple of different ways, but I cant get the button press to set the text.

Any ideas please?

Create a script and execute it via service call on tap action.
The script could look like this:


alias: Latest Scene
mode: queued
max: 30
sequence:
  - service: input_text.set_value
    data:
      value: >
        {{ states.scene
        |rejectattr('state', '==', 'unknown')|sort(attribute='state', reverse=true)
        |map(attribute='name')|first }}
    target:
      entity_id: input_text.test

Copy the value part into Developer Tools/Template and check the result.

Thank you… that does work - I owe you a beer!

My next challenge is to call that script as part of the button card. The card is already making a call to set the scene.

tap_action:
action: call-service
service: scene.turn_on
service_data:
entity_id: scene.bedroom_nightlight

I presume I need to make another “service:” call to execute the new script. Again, I’ve tried that and the code editor calls out duplication errors.

Or am I adding this into the script as well?

Thanks again

Yes, you can add the service scene.turn_on as first service call. If you want to be sure, that only that specific scene gets stored in the text helper, you can work with variables:

script:


alias: Latest Scene
mode: queued
max: 30
variables:
  myscene: scene.anrichte_orangenfelder
sequence:
  - service: scene.turn_on
    target:
      entity_id: "{{ myscene }}"
  - service: input_text.set_value
    data:
      value: >
        {{ state_attr(myscene, 'friendly_name') }}
    target:
      entity_id: input_text.test

Dashboard button:


type: button
tap_action:
  action: call-service
  service: script.latest_scene


You can use that button also with another scene by using the variable in the button:


type: button
tap_action:
  action: call-service
  service: script.latest_scene
  data:
    myscene: scene.anrichte_color_burst

Brilliant - thank you.

I cant quite getting working just yet - I get a service not found error which I need to work through. I created the input text field via a Helper

I used this code in the button:

type: button
tap_action:
action: call-service
service: script.scenes
data:
myscene: scene.bedroom_nightlight

and this code in the script itself

alias: scenes
mode: queued
max: 30
variables:
myscene: scene.bedroom_nightlight
sequence:

  • service: scene.turn_on
    target:
    entity_id: “{{ myscene }}”
  • service: input_text.set_value
    data:
    value: |
    “{{ myscene }}”
    target:
    entity_id: input_text.scene_set

Maybe an indentation problem. I can’t see it that way; please use the pre-formatted text tool (coq wheel, first list entry).

I will do that as well - thank you again!!!

In my research, I’ve also read a number of threads pointing to the fact that as the Phillips hue scenes don’t sit in the scenes.yaml file - you can’t use them in automations.

So, as I’m only looking for a push button to display which scene is currently in use, my plan is to create a set of dummy scenes that will never be turned on - but used to return the scene name for display

That’s simply wrong. I use my Hue scenes wherever I want.