Ok, solved it. It wasn’t a catch-22. v5.0 released.
@Friedrieck the problem (and the solution) were the two REST sensors, that contain all the JSON data from the nuki, at startup they are not initialized so fast. If you check their code, I put value_state = “OK” to both of them, so I only needed to check if states() == “OK” to be sure they’re initialized.
- platform: rest
scan_interval: 300
resource_template: "http://{{ states('sensor.nuki_bridge_host') }}:{{ states('sensor.nuki_bridge_port') }}/list?&token={{ states('sensor.nuki_bridge_token') }}"
name: "Nuki Endpoint List"
value_template: "OK"
json_attributes:
- lastKnownState
- firmwareVersion
- nukiId
- name
{% if states('sensor.nuki_endpoint_info') == "OK" %}
{{ state_attr('sensor.nuki_endpoint_info','scanResults')[0]['name'] }}
{% endif %}
If states() is used with an uninitialized sensor, you can’t use none() to test it, because it returnes “unknown”.
So, this doesn’t work:
{% if states('sensor.nuki_endpoint_info') is not none %}
{{ state_attr('sensor.nuki_endpoint_info','scanResults')[0]['name'] }}
{% endif %}
But this works:
{% if states('sensor.nuki_endpoint_info') != "unknown" %}
{{ state_attr('sensor.nuki_endpoint_info','scanResults')[0]['name'] }}
{% endif %}
The alternative method, is to test if state_attr(), without the [0][‘name’], is none():
{% if state_attr('sensor.nuki_endpoint_info','scanResults') is not none %}
{{ state_attr('sensor.nuki_endpoint_info','scanResults')[0]['name'] }}
{% endif %}
This for example doesn’t work:
{% if state_attr('sensor.nuki_endpoint_info','scanResults')[0]['name'] is not none %}
{{ state_attr('sensor.nuki_endpoint_info','scanResults')[0]['name'] }}
{% endif %}
And while looking for some info, I found this.
Endless hours of frustration…literally!! But we made it, in the end. Perseverance is the key.
Thanks for all the advices, going to get some sleep now.