My automation to change variable in Variables+History is not working - why?

This is strange. I have this variable set up in Variables+History:

Entity ID: binary_sensor.espresense_aktivert_deaktivert

Friendly name: ESPresense aktivert/deaktivert

It basically decides if other automations should act on ESPresense triggers or not. So I have this condition in those other automations:

  - condition: state
    entity_id: binary_sensor.espresense_aktivert_deaktivert
    state: "on"

If it’s on they unlock the door, if it’s off they don’t. That works as it should. The problem is when I want to turn on and off the state of the binary sensor, done with Aeotec The Button. I need to know if I’m turning it on or off without looking at the GUI, so I have set up separate automations for turning it on and off with long presses of the button, which also triggers a signal (the lock unlocking twice for off and once for on. This is the automations:

alias: Aktivere ESPresense med The button
description: Slå på ESPresense
trigger:
  - platform: device
    device_id: e7a66c58543543b2bc7008490940ceb1
    domain: zwave_js
    type: event.value_notification.central_scene
    property: scene
    property_key: "001"
    endpoint: 0
    command_class: 91
    subtype: Endpoint 0 Scene 001
    value: 2
condition:
  - condition: state
    entity_id: binary_sensor.espresense_aktivert_deaktivert
    state: "off"
    enabled: true
action:
  - service: variable.update_binary_sensor
    target:
      entity_id: binary_sensor.espresense_aktivert_deaktivert
    data:
      value: "true"
      replace_attributes: false
    enabled: true
  - service: lock.unlock
    data:
      entity_id: lock.mastiff_lock
    enabled: true
alias: Deaktivere ESPresense med The button og GUI-knapp
description: Slå avESPresense
trigger:
  - platform: device
    device_id: e7a66c58543543b2bc7008490940ceb1
    domain: zwave_js
    type: event.value_notification.central_scene
    property: scene
    property_key: "001"
    endpoint: 0
    command_class: 91
    subtype: Endpoint 0 Scene 001
    value: 2
condition:
  - condition: state
    entity_id: binary_sensor.espresense_aktivert_deaktivert
    state: "on"
    enabled: true
action:
  - service: variable.update_binary_sensor
    target:
      entity_id: binary_sensor.espresense_aktivert_deaktivert
    data:
      value: "false"
      replace_attributes: false
      enabled: true
  - service: lock.unlock
    data:
      entity_id: lock.mastiff_lock
    enabled: true
  - service: lock.unlock
    data:
      entity_id: lock.mastiff_lock
    enabled: true

For some strange reason turning it works from off to on works, while turning it from on to off does not, even if the automation shows that both triggers, and the right condition fails. Can anybody see what I’m doing wrong here?

Where is this service documented?

@tom_l Thanks for answering! It’s in the custom component’s documentation.

Edit: I have no problems changing the variable from a template switch with the service variable.toggle_binary_sensor, but that didn’t work as it should with the separate scripts either. And I need those to know what I’m changing the value to. I can prehaps watch the variable and use the change in it as a trigger for the signals and use the toggle service for The Button too, but it really shouldn’t be necessary, as far as I can understand the service should work if I find my mistake, whatever that may be.

I tried now, and using the change in the variable as a trigger works without a hitch, which the toggle service with The Button does as well. Strange…

Moved to Third Party Integrations.