Passing input helper to service within button

I am trying to create a button that will call a HACS pyscript based service. The service tester works but my implementation within the button is incorrect. Rather than passing the variable value, it passes the name. I need help with this. Also, as a side note, is it possible to have an “on change” trigger for the cards? Rather than having a separate button I could just have on change of drop down, send service call.

Both options still have the issue of how to pass a Helper variable to pyscript

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: pyscript.setmode
  data:
    mode: input_select.led_cube_mode
  target: {}
icon: mdi:television-ambient-light
name: Set LED Cube Mode

error

2023-10-01 13:24:36.397 INFO (MainThread) [custom_components.pyscript.file.LEDCube.setMode] setMode: got mode input_select.led_cube_mode

That can’t work, this is just a string. :wink: Try it as template:
mode: "{{ states('input_select.led_cube_mode') }}"

tried that, received the following log

2023-10-01 13:33:14.889 INFO (MainThread) [custom_components.pyscript.file.LEDCube.setMode] setMode: got mode {{ states('input_select.led_cube_mode') }}

As Patrick stated you would need a template, but most core cards, including button, do not accept templating. You will have to move your action to a script, then have the button call that script as a service.

Selecting an new option in a dropdown changes the state of the Input select so you can use an automation with a State trigger.

trigger:
  - platform: state
    entity_id: input_select.led_cube_mode
    not_to: unavailable
condition: []
action:
  - service: pyscript.setmode
    data:
      mode: "{{ trigger.to_state.state }}"
    target: {}
1 Like

Thanks, I always forget that! :slight_smile:

Thank you for your help! It works!

What would the mode line for triggering on input_text change? I have the following, but it does not work, I think it is the text line

trigger:
  - platform: state
    entity_id: input_text.led_cube_text
    not_to: unavailable
condition: []
action:
  - service: pyscript.settext
    data:
      text: "{{ trigger.to_state.state }}"
    target: {}

That trigger should work… what does the automation trace show?

…and now it works. May have not saved changes properly. Either way, thank you for the help in getting this working. My own LEDCube now sits on the dashboard!