Thanks for spotting all those, corrected here:
- trigger:
- platform: event
event_type: event_template_reloaded
- platform: homeassistant
event: start
- platform: webhook
webhook_id: !secret nuki_bridge_webhook
binary_sensor:
- name: "Nuki Door State"
device_class: door
state: >
{% if trigger.platform == 'webhook' %}
{{ trigger.json.doorsensorState == 3 }}
{% else %}
{{ is_state('sensor.nuki_door_sensor_state', 'open') }}
{% endif %}
availability: >
{% if trigger.platform == 'webhook' %}
{{ trigger.json.doorsensorState != None }}
{% else %}
{{ (is_state('sensor.nuki_door_sensor_state', 'open') or is_state('sensor.nuki_door_sensor_state', 'closed')) }}
{% endif %}
icon: >
{% if trigger.platform == 'webhook' %}
{% set my_state = {1: 'deactivated', 2: 'closed', 3: 'open', 4: 'unknown', 5: 'calibrating'} %}
{% set trigdoor = my_state[trigger.json.doorsensorState] %}
{% set my_state = {0: 'uncalibrated', 1: 'locked', 2:'unlocking', 3: 'unlocked', 4: 'locking', 5: 'unlatched', 6: "unlocked (lock ‘n’ go)", 7: 'unlatching', 254: 'motor blocked', 255: 'undefined'} %}
{% set triglock = my_state[trigger.json.state] %}
{% else %}
{% set trigdoor = states(sensor.nuki_door_sensor_state) %}
{% set triglock = states(sensor.nuki_lock_sensor_state) %}
{% endif %}
{% if (trigdoor == 'open') %}
mdi:door-open
{% elif trigdoor == 'closed' and triglock == 'locked' %}
mdi:door-closed-lock
{% elif trigdoor == 'closed' and triglock == 'unlocked' %}
mdi:door-closed
{% else %}
mdi:alert-box-outline
{% endif %}
attributes:
nuki_id: >
{% if trigger.platform == 'webhook' %}
{{ trigger.json.nukiId }}
{% else %}
{{ states(sensor.nuki_id) }}
{% endif %}
door_state: >
{% set my_state = {1: 'deactivated', 2: 'closed', 3: 'open', 4: 'unknown', 5: 'calibrating'} %}
{% if trigger.platform == 'webhook' %}
{{ my_state[trigger.json.doorsensorState] }}
{% else %}
{{ states(sensor.nuki_door_sensor_state) }}
{% endif %}
lock_state: >
{% set my_state = {0: 'uncalibrated', 1: 'locked', 2:'unlocking', 3: 'unlocked', 4: 'locking', 5: 'unlatched', 6: "unlocked (lock ‘n’ go)", 7: 'unlatching', 254: 'motor blocked', 255: 'undefined'} %}
{% if trigger.platform == 'webhook' %}
{{ my_state[trigger.json.state] }}
{% else %}
{{ states(sensor.nuki_lock_sensor_state) }}
{% endif %}
lock_battery: >
{% if trigger.platform == 'webhook' %}
{{ trigger.json.batteryChargeState }}%
{% else %}
{{ states(sensor.nuki_lock_battery_level) }}
{% endif %}
lock_battery_critical: >
{% if trigger.platform == 'webhook' %}
{{ trigger.json.batteryCritical }}
{% else %}
{{ states(sensor.nuki_lock_battery_critical_state) }}
{% endif %}
keypad_battery_critical: >
{% if trigger.platform == 'webhook' %}
{{ trigger.json.keypadBatteryCritical }}
{% else %}
{{ states(sensor.nuki_keypad_battery_critical_state) }}
{% endif %}
last_update: "{{ strptime(as_timestamp(now()) | timestamp_local, '%Y%m%d %H:%M:%S') }}"
trigger: '{{ trigger.platform }}'
I just did a template reload, and same result, unfortunately.
Here’s what’s in the logs after the reload:
Logger: homeassistant.components.template.binary_sensor
Source: components/template/trigger_entity.py:141
Integration: Template (documentation, issues)
First occurred: 1:59:04 (2 occurrences)
Last logged: 12:00:12
Error rendering icon template for binary_sensor.nuki_door_state: UndefinedError: ‘sensor’ is undefined
Logger: homeassistant.helpers.template
Source: helpers/template.py:1377
First occurred: 1:59:04 (2 occurrences)
Last logged: 12:00:12
Template variable error: ‘sensor’ is undefined when rendering ‘{% if trigger.platform == ‘webhook’ %} {% set my_state = {1: ‘deactivated’, 2: ‘closed’, 3: ‘open’, 4: ‘unknown’, 5: ‘calibrating’} %} {% set trigdoor = my_state[trigger.json.doorsensorState] %} {% set my_state = {0: ‘uncalibrated’, 1: ‘locked’, 2:‘unlocking’, 3: ‘unlocked’, 4: ‘locking’, 5: ‘unlatched’, 6: “unlocked (lock ‘n’ go)”, 7: ‘unlatching’, 254: ‘motor blocked’, 255: ‘undefined’} %} {% set triglock = my_state[trigger.json.state] %} {% else %} {% set trigdoor = sensor.nuki_door_sensor_state %} {% set triglock = sensor.nuki_lock_sensor_state %} {% endif %} {% if (trigdoor == ‘open’) %} mdi:door-open {% elif trigdoor == ‘closed’ and triglock == ‘locked’ %} mdi:door-closed-lock {% elif trigdoor == ‘closed’ and triglock == ‘unlocked’ %} mdi:door-closed {% else %} mdi:alert-box-outline {% endif %}’
Template variable error: ‘sensor’ is undefined when rendering ‘{% if trigger.platform == ‘webhook’ %} {% set my_state = {1: ‘deactivated’, 2: ‘closed’, 3: ‘open’, 4: ‘unknown’, 5: ‘calibrating’} %} {% set trigdoor = my_state[trigger.json.doorsensorState] %} {% set my_state = {0: ‘uncalibrated’, 1: ‘locked’, 2:‘unlocking’, 3: ‘unlocked’, 4: ‘locking’, 5: ‘unlatched’, 6: “unlocked (lock ‘n’ go)”, 7: ‘unlatching’, 254: ‘motor blocked’, 255: ‘undefined’} %} {% set triglock = my_state[trigger.json.state] %} {% else %} {% set trigdoor = states(sensor.nuki_door_sensor_state) %} {% set triglock = states(sensor.nuki_lock_sensor_state) %} {% endif %} {% if (trigdoor == ‘open’) %} mdi:door-open {% elif trigdoor == ‘closed’ and triglock == ‘locked’ %} mdi:door-closed-lock {% elif trigdoor == ‘closed’ and triglock == ‘unlocked’ %} mdi:door-closed {% else %} mdi:alert-box-outline {% endif %}’