Disarming a manual alarm control panel in automation with a code

I am trying to disarm a manual alarm control panel in an automation. I can call the service through the dev tools service gui like so (my code isn’t 1111), but if I use my actual code, it disarms.

Now I’m trying to figure out how to put this as an action in my automation. This is what I have, but it didn’t work. I can see that the alarm_disarm service is called after the automation fires in the log, but it doesn’t disarm. I must be missing something in translating from the services gui to the YAML formatting. Is there a better way to directly translate?

I have tried it with and without the entity_id in the data section.

- alias: 'Disarm alarm automatically'
  trigger:
    - platform: state
      entity_id: binary_sensor.alarm_disarm
      to: 'on'
  action:
    - service: alarm_control_panel.alarm_disarm
      entity_id: alarm_control_panel.house_alarm
      data:
        entity_id: alarm_control_panel.house_alarm
        code: !secret alarm_code
    - service: switch.turn_off
      entity_id: switch.siren

The examples in the documentation don’t have codes when disarming in automations.

You have specified the alarm panel entity_id twice.

This should work:

    - service: alarm_control_panel.alarm_disarm
      entity_id: alarm_control_panel.house_alarm
      data:
        code: !secret alarm_code

Buried in my post, I mentioned that I tried it with and without the entity_id in the data section. Do I have to get rid of the other one??? That would be weird if so.

All I know is that this script works for me:

alarm_disarm:
  sequence:
    service: alarm_control_panel.alarm_disarm
    entity_id: alarm_control_panel.house
    data:
      code: !secret alarm_code

I am using the custom component bwalarm though.

Interesting, let me try creating a script and then fire the script from the automation.

You original intuition was correct, but I’m baffled. This is what works for me:

alarm_disarm:
  sequence:
    service: alarm_control_panel.alarm_disarm
    data:
      code: !secret alarm_code
      entity_id: alarm_control_panel.house

Why does it work for you the other way? It is very weird that you would have the entity_id with no data, but then have to move it inside when using data.

The data: key is for additional information that a service my support. The entity id is not additional data. It always needs to be specified but you can do that inside the data if you wish to. So both of these are correct:

alarm_disarm:
  sequence:
    service: alarm_control_panel.alarm_disarm
    data:
      code: !secret alarm_code
      entity_id: alarm_control_panel.house
alarm_disarm:
  sequence:
    service: alarm_control_panel.alarm_disarm
    entity_id: alarm_control_panel.house
    data:
      code: !secret alarm_code

But this is not:

alarm_disarm:
  sequence:
    service: alarm_control_panel.alarm_disarm
    entity_id: alarm_control_panel.house
    data:
      entity_id: alarm_control_panel.house
      code: !secret alarm_code

What I’m saying is that your second code example does not work for me.

It only works when it is inside data

Weird here’s another working example:

  action:
  - service: light.turn_off
    entity_id: light.lifx_bottom_of_stairs
    data:
      transition: 1

If I use the script editor in the GUI to create a new script, then you can only put the entity_id in the data block. I’m beginning the think that having entity_id without data will automatically place it inside the data block and that this functionality is broken for the stock alarm_control_panel component

Guys, I don’t remember where on this forum but not long time ago I saw a discussion about placing entity_id inside or outside data as it’s really confusing to see it in different locations.
The bottom line if I remember it right was: entity_id outside data is just a trick to allow something like:

service: thing.do_something
entity_id: things.my_entity

i.e when you have only one parameter for the service - entity_id.
If you have other parameters, everything goes inside data.
The first form just allows to write less code but I believe eventually it translates into the same code by wrapping everything together as data and passing it to a service.

I agree that there is no need to use entity_id twice unless you really want it… on the other hand, there should be no harm? Does it say anywhere it’s NOT correct?

Well, that means we can safely place entity_id inside OR outside data, but cannot have BOTH at the same time.
And that last bit is a bit weird to me and looks like a bug… but I won’t investigate it further… at least right now. :wink:

I don’t use GUI editor myself and as they introduced a lot of GUI things recently, I wouldn’t be surprised it isn’t working correctly. Open a new issue then.

1 Like

In this case for the manual alarm panel component/platform/integration (?) , you can use entity_id without data, or inside data, but not outside data with data. You also cannot have it in both spots phew. This is directly contradicted by the behavior in the custom alarm panel component and the light example. It isn’t a homogenous answer it seems.

Open a new issue, what else can we do?
I take it you tried not only GUI editor but wrote automations manually and got such a result, right?

Yes. I have tried GUI, which only allows entity_id in the data section. I have tried all combinations manually except with no entity_id at all, the only one that works is the entity_id inside data.

Another example where the entity_id has to be in data or it doesn’t work:

Thanks all

1 Like

this no longer works…

indeed, trying to run this in an automation… any solutions?

if you remove !secret and put your code in automation will work. That was the solution

So this would never work ?

 - service: alarm_control_panel.alarm_disarm
   data:
     code: !secret envisa_code

as I’ve to input code in UI :frowning:
Isn’t this should be considered a bug ?