Nuki Card with Callback support (supports both Lock & Opener, it replaces the official integration)

okay. rename it and created a new automations.yaml and paste this into it:

- id: "nuki_card_callback"
  alias: Nuki Card Callback
  description: Automation for the Nuki doorlock
  mode: queued
  max: 10
  max_exceeded: warning
  trigger:
    - platform: homeassistant
      id: "trigger_nuki_ha_start"
      event: start
    - platform: webhook
      id: "trigger_nuki_bridge_webhook"
      webhook_id: !secret nuki_bridge_webhook
    - platform: state
      id: "trigger_nuki_bridge_endpoint_list"
      entity_id: sensor.nuki_bridge_endpoint_list
  condition: []
  action:
    - choose:
        - conditions: >
            {{ trigger.id == 'trigger_nuki_ha_start' }}
          sequence:
            - service: input_text.set_value
              target:
                entity_id: input_text.nuki_bridge_callback_url
              data:
                value: >
                  {{ states('input_text.nuki_ha_internal_url') | urlencode }}/api/webhook/{{ states('input_text.nuki_bridge_webhook') | urlencode }}
        - conditions: >
            {{ trigger.id == 'trigger_nuki_bridge_endpoint_list' }}
          sequence:
            - service: input_number.set_value
              target:
                entity_id: input_number.nuki_bridge_door_sensor_state
              data:
                value: >
                  {{ state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['doorsensorState'] if state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['doorsensorState'] != null }}
            - service: input_text.set_value
              target:
                entity_id: input_text.nuki_bridge_door_sensor
              data:
                value: >
                  {{ (states('input_text.nuki_door_sensor_states') | from_json)[state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['doorsensorState'] | string ] if state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['doorsensorState'] != null }}
            - service: input_number.set_value
              target:
                entity_id: input_number.nuki_bridge_lock_sensor_state
              data:
                value: >
                  {{ state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['state'] if state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['state'] != null }}
            - service: input_text.set_value
              target:
                entity_id: input_text.nuki_bridge_lock_sensor
              data:
                value: >
                  {{ (states('input_text.nuki_lock_sensor_states') | from_json)[state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['state'] | string] if state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['state'] != null }}
            - service: input_text.set_value
              target:
                entity_id: input_text.nuki_bridge_last_activity
              data:
                value: >
                  {% if state_attr('sensor.nuki_bridge_endpoint_list', 'lastKnownState')['timestamp'] != null %}
                    {{ as_timestamp(state_attr('sensor.nuki_bridge_endpoint_list','lastKnownState')['timestamp']) | timestamp_custom("%H:%M:%S (%b %d)") }}
                  {% endif %}
            - service: input_text.set_value
              target:
                entity_id: input_text.nuki_bridge_trigger_id
              data:
                value: >
                  {{ trigger.id }}
        - conditions: >
            {{ trigger.id == 'trigger_nuki_bridge_webhook' }}
          sequence:
            - service: input_number.set_value
              target:
                entity_id: input_number.nuki_bridge_door_sensor_state
              data:
                value: >
                  {{ trigger.json.doorsensorState | int }}
            - service: input_text.set_value
              target:
                entity_id: input_text.nuki_bridge_door_sensor
              data:
                value: >
                  {{ (states('input_text.nuki_door_sensor_states') | from_json)[trigger.json.doorsensorState | string] }}
            - service: input_number.set_value
              target:
                entity_id: input_number.nuki_bridge_lock_sensor_state
              data:
                value: >
                  {{ trigger.json.state | int }}
            - service: input_text.set_value
              target:
                entity_id: input_text.nuki_bridge_lock_sensor
              data:
                value: >
                  {{ (states('input_text.nuki_lock_sensor_states') | from_json)[trigger.json.state | string] }}
            - service: input_text.set_value
              target:
                entity_id: input_text.nuki_bridge_last_activity
              data:
                value: >
                  {{ as_timestamp(now()) | timestamp_custom("%H:%M:%S (%b %d)") }}
            - service: input_text.set_value
              target:
                entity_id: input_text.nuki_bridge_trigger_id
              data:
                value: >
                  {{ trigger.id }}
            - service: homeassistant.update_entity
              target:
                entity_id: binary_sensor.nuki_door_sensor_state
            - service: homeassistant.update_entity
              target:
                entity_id: lock.nuki_lock_action
            - service: script.turn_on
              target:
                entity_id: script.nuki_bridge_polling_queue

refresh your automations, clear the log, fingers crossed that there is an automation called Nuki Card Callback and if so run it.

ps
if I am doing this I this in my log:


Means the automation is working as it should.

No exactly the same error

I tried to set the automation myself manually but it says the intergration doesnt exist

So I believe something is wrong with your setup of the dependencies.
LL or token or whatever.
Start from scratch with a new LL and delete all callbacks, get the old automations.yaml back, etc.

Before I do that I’m getting this in the logs;

Logger: homeassistant.config
Source: config.py:437
First occurred: 19:35:41 (4 occurrences)
Last logged: 19:43:27

Invalid config for [automation]: [id] is an invalid option for [automation]. Check: automation->id. (See /config/configuration.yaml, line 24).
Invalid config for [automation]: [id] is an invalid option for [automation]. Check: automation->id. (See /config/configuration.yaml, line 22).

You are having problems with the configuration of HA, please show your configuration.yaml so we can check if you put the package in the appropriate section.

The packages section has to be under the homeassistant section, as described in the first post:

image

Because the rest sensors get updated when the callback is triggered or when HA starts.

I don’t understand why you ask the inner working of the automation when you still didn’t complete a correct configuration. If you don’t configure it properly don’t expect it to be working correctly.

If you delete that section the Nuki Card is not an automation anymore. If there was a problem in that section you wouldn’t be the first one with this specific issue. Before doubting the code, check your configuration, the problem is specific to your setup. Many people are using the Nuki Card. So, concentrate on your setup, the problem is there.

The automation contained within nuki_card_callback.yaml appears to be the problem as it never gets setup as an automation. i.e. it doesn’t appear in my list of automations.

As Alessandro asked, show us you configuration.yaml. The packages section has to be included in the homeassistant section (pretty much at the top), whereas the include for the automations.yaml has not.

config

Okay, thanks.
Let’s see what happens, when you set homeassistant: and the include for the packages to the very top, right beneath default_config: and all other includes beneath the include for the automations.

Similar like this dude did.

this is your specific issue. you are not pasting correctly the contents of the source code. you have either indentation issues or eol issues. how are you creating the nuki_card_callback.yaml file?

you have the keyword id aligned with automation, when it has to be indented by two spaces, like this:

Show the screenshot of the contents of the nuki_card_callback.yaml file, first 60 lines.

@nofuse I asked you to do so because of this:

Note that each line after homeassistant: is indented two (2) spaces. Since the configuration files in Home Assistant are based on the YAML language, indentation and spacing are important. Also note that seemingly strange entry under customize:.

In your config other !include lines are following homeassistant: which don’t have two spaces. I wonder that this is working - if I do so, my config check throws errors.

I have this at the very beginning of the config:

And all the other !includes (automations.yaml too) are at the very end of the file.

Hi Alessandro, I thought so too yesterday, that’s why I asked him to empty his automations.yaml and paste the code without the two indentation for "- id: "nuki_card_callback""
He told me it would be the same… but never know.

Me too… this is how I learned it from the beginning :wink:

it’s the same because he indents wrong when he pastes the code, so the problem is not the package format.

  • id: “nuki_card_callback” is not aligned with automation, it is the indented by 2.

I am downloading your file and copying in directly to the package folder

If I put two spaces before the other !include lines my config fails

Yes, but this is not what I was asking you to do.

I have moved the homeassistant: entries to the second item in my config file but still the same