#hass.callService formatting

1 messages · Page 1 of 1 (latest)

keen mason
#

I have a button I need to do two things when I press it. Now, I've confirmed that this method works with a simple switch, but I can't figure out how to set the option of an input_selection. Here's the code I'm using:

type: custom:button-card
name: Test
entity: input_select.lcars_calendar_select
tap_action:
  action: navigate
  navigation_path: /dashboard-diningroom/dr_msd
  multi_calls: |
    [[[
      hass.callService('input_select', 'select_option', {
      'entity_id': 'input_select.lcars_calendar_select',
      'option': 'Overall'
      });
    ]]]

I would like the button to set an option ("Overall", in this case) on the listed input helper, "input_select.lcars_calendar_select". I've copied this code from a few places around the internet that were using this, but while the button doesn't throw an error message, it doesn't change the option of the input helper. Hoping someone has some thoughts...ChatGPT's help wasn't, ah, helpful.

violet dirge
#

Your syntax looks like it should work. I copied your code, put in my own entities, and then started working to try to get the navigate to work within the multi_call, assuming the action/multi-call combination wouldn't work. (FYI, I couldn't get it to work in the multi_call.) So, I stepped back to see what using the navigate action does and it worked for me.

#
type: custom:button-card
name: "[[[ return entity.state ]]]"
entity: input_select.night_time_light_color_selector
show_icon: false
tap_action:
  action: navigate
  navigation_path: /dashboard-lab/temp
  multi_calls: |
    [[[
      hass.callService(
        'input_select', 
        'select_option', 
        { 
          'entity_id': 'input_select.night_time_light_color_selector',
          'option': 'red' 
        }
      );
    ]]]
keen mason
#

Interesting that your navigate didn't work, it does for me. Very odd.

It looks like your Jinja is formatted differently from mine, I'll try formatting that the way you have it there in the AM.

violet dirge
#

The navigate as an action did work; trying to get it to work as a hass.callService did not.

placid flower
#

That isn't Jinja, it's JavaScript in the format that custom button card expects

keen mason
#

Ah, sorry. Swapping out the callService operation to flip a switch does work, which makes me wonder if the command is mis-formatted somehow.

#

As in, I know I can use multi_calls and get that to work. Which makes me think that it's not that part I've messed up.

zealous aurora
keen mason
#

I found someone else using it. I had never heard of it either.

zealous aurora
#

Thank you

placid flower
#

I don't know why you would do that vs just making a script and calling it

#

I guess that would replace the action with call-service and you couldn't replicate the existing actions

keen mason
#

Can I navigate with a script? That's where I ran into issues.

placid flower
#

I don't think you can unless you use browser_mod

keen mason
#

Yeah, that's why I was trying to use this very weird way. 😛

#

For instance, I can confirm that this code works, as I'm trying it right now.

type: custom:button-card
name: Test
entity: input_select.lcars_calendar_select
tap_action:
  action: navigate
  navigation_path: /dashboard-diningroom/dr_msd
  multi_calls: |
    [[[
      hass.callService('switch','toggle', { entity_id: 'switch.wemo_mini'} )
    ]]]
#

That wemo switch is connected to a fan, and I can click it on and off. So that makes me think I just have to format the JS correctly to make this work.

#

I guess multi_calls can call a script, so I suppose I can write a script to set the entity option to what I want.

#

So hacky!

keen mason
#

For anyone who comes after after me, here's my solution:

type: custom:button-card
show_name: true
name: test
show_icon: true
tap_action:
  action: custom
  multi_calls: |
    [[[
     hass.callService(
       "script",
       "turn_on",
       { entity_id: "script.msd_cal_select"}
     )

     window.history.pushState(null,"","/dashboard-diningroom/dr_msd");
     window.dispatchEvent(new CustomEvent("location-changed"));
     ]]] 
#

The script sets the option. I'm still convinced this could work just fine if I knew how to format the callService code properly, but it seems it's impossible to find the documentation about that.

#

So, if anyone knows how to format that...I'd appreciate being educated!

mighty gale
#

I'll also agree that your initial syntax looked fine. Did you check for any errors after your service call failed? Case mismatch in option name maybe? Seems like it ought to work.

placid flower
#

do you know where multi_calls is supported?

keen mason
#

I do not. It appears to be undocumented.

A friend of mine just tried the exact code I was trying, and it works for him. So, it's either something on that view / dashboard, or a different version of HA or something. Who knows. Gremlins?

violet dirge
#

I came across the multi_calls a while back when I was trying to set an action for a light entity and a switch entity. Because they're different domains, a turn_off would not work for both but I was looking to avoid setting up a group or relying on a script. I've not been able to find documentation for it but found it mentioned in the forum. I figured it wouldn't work but tried it anyways and it did, in fact work. I've tried looking through custom:button-card's code to find how it works but I don't understand most of what is in there.
Interestingly, @eager badger was trying to accomplish this same task back in January (but he was trying to get it to work with browser_mod.)