home-assistant

Calling a service from a custom button in homeassistant


I'm looking for help with calling a service from a custom button. I have the following service in developer tools, and calling it works just fine.

service: remote.send_command
data:
  device: Livingroom-aircon
  command: "On"
target:
  entity_id: remote.broadlink_rm4_pro

Hitting the call service button results in my aircon turning on.

In trying to add this function to a dashboard button I have the following

name: Livingroom Aircon
icon: mdi:fan
show_icon: true
type: custom:button-card
tap_action:
  action: call-service
  service: remote.send_command
  data:
    device: Livingroom-aircon
    command: 'On'
  target:
    entity_id: remote.broadlink_rm4_pro
entity: remote.broadlink_rm4_pro

Now, when pressing the button I get an error saying

Failed to call service remote/send_command. required key not provided @data['command']

I've done the same thing with a normal button, and the following works...

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: remote.send_command
  data:
    device: Livingroom-aircon
    command: 'On'
  target:
    entity_id: remote.broadlink_rm4_pro
entity: remote.broadlink_rm4_pro

So, how do I do it from the custom button (later I want to add custom graphics/info/animation)


Solution

  • For custom:button-card to work you need to adjust more than just the type of the card. Have a look at the Github page of the project.

    You need to replace data with service_data and device with entity_id:

    name: Livingroom Aircon
    icon: mdi:fan
    show_icon: true
    type: custom:button-card
    tap_action:
      action: call-service
      service: remote.send_command
      service_data: # changed
        entity_id: Livingroom-aircon # changed
        command: 'On'
      target:
        entity_id: remote.broadlink_rm4_pro
    entity: remote.broadlink_rm4_pro