Failed to call service script

Hi

I have a script as follows that is called from a card which disarms the alarm if it is on and then opens the garage door, else just opens the garage door. However I get the following error;
‘Failed to call service script/alarm_check. must contain at least one of entity_id, device_id, area_id.’
I only get this error if the alarm is armed. If the alarm is not armed, the door opens without error.

type: custom:mushroom-chips-card
chips:
  - type: alarm-control-panel
    entity: alarm_control_panel.1
  - type: weather
    entity: weather.forecast_home_2
    show_conditions: true
    show_temperature: true
   - type: template
    entity: switch.sonoff_10002eb174
    icon: mdi:garage-variant
    icon_color: brown
    content: ''
    tap_action:
      action: call-service
      service: script.alarm_check
      target: {}
alignment: center

In scripts…

alias: alarm_check
sequence:
  - if:
      - condition: template
        value_template: "{{ states('alarm_control_panel.1')=='armed_away' }}"
    then:
      - service: alarm_control_panel.alarm_disarm
        data: {}
      - service: switch.toggle
        data: {}
        target:
          entity_id: switch.sonoff_10002eb174
    else:
      - service: switch.toggle
        data: {}
        target:
          entity_id: switch.sonoff_10002eb174
mode: single

Can anyone help me with this please, I’m getting dizzy going around in circles!

Thanks

I know nothing about Mushroom cards or why you are having your issue but I suspect you may be misinterpreting what switch.toggle does in your script.

It does the following, if the switch is on, then turn it off. Otherwise if the switch is off, turn it on.

It does not toggle the switch “on then off”, which is what I think you are expecting it to do. Unless you have some other automation to change the switch back to off.

Thanks for your reply Tom_l. The sonoff switch for the garage door is in inching mode so this does work. As mentioned in the previous post, the door opens and shuts as normal when alarm is disarmed.
The error (whatever it is) is in the If/then part of the script I think.

1 Like

Ah that’s ok then.

You should not create entity ids that have object ids beginning with numbers. If you do you will need to use square bracket notation in your templates.

Also you did not specify which alarm control panel to disarm. Try this:

alias: alarm_check
sequence:
  - if:
      - condition: template
        value_template: >
          {{ is_state('alarm_control_panel["1"]', 'armed_away') }}"
    then:
      - service: alarm_control_panel.alarm_disarm
        data: {}
        target:
          entity_id: alarm_control_panel.1
      - service: switch.toggle
        data: {}
        target:
          entity_id: switch.sonoff_10002eb174
    else:
      - service: switch.toggle
        data: {}
        target:
          entity_id: switch.sonoff_10002eb174
mode: single

Thank you Tom

After some experimenting, this is what worked;

alias: alarm_check
sequence:
  - if:
      - condition: template
        value_template: |
          {{ is_state('alarm_control_panel.1', 'armed_away') }}
    then:
      - service: alarm_control_panel.alarm_disarm
        data: {}
        target:
          entity_id: alarm_control_panel.1
      - service: switch.toggle
        data: {}
        target:
          entity_id: switch.sonoff_10002eb174
    else:
      - service: switch.toggle
        data: {}
        target:
          entity_id: switch.sonoff_10002eb174
mode: single