It is absolutely unnecessary but if you want continue to learn HA, an idea would be to package your integration as a blueprint.
I will install and test 4.7 after all my “lavori di casa” (my wife is watching me ).
Nice work. Have a good day all !
It is absolutely unnecessary but if you want continue to learn HA, an idea would be to package your integration as a blueprint.
I will install and test 4.7 after all my “lavori di casa” (my wife is watching me ).
Nice work. Have a good day all !
The wife factor is the most important one, particularly for home automations.
I totally forgot I did that comment. Thanks.
I think the next step for this Nuki Card should be to make it a Custom Component, since the official integration is in developement with some of these features, don’t know if it will provide all the sensors though.
But I don’t know where to start, and don’t know if I’m up to the task, sincerely…
Let me know your thoughts…
But I don’t know where to start, and don’t know if I’m up to the task, sincerely…
Well, on my side I am happy with the current solution. Sure, some “packaging” would be nice but anyway it is easy to find it into the forum with the keyword Nuki (I see you have wrote a link to the new solution in the previous thread).
I’m very happy about it too. It does everything I wanted. But it’s difficult to maintain and to configure for novice users. Actually, having moved almost all of the sensors in templates.yaml was a good choice, so 90% of the integration is in that file, and that helps a lot maintaining and configuring it, but a package or a custom component would be better.
I read somewhere that HA supports packages, but I also read they are being deprecated…
Just installed V4.7: it looks very good and I am happy about it too
Thanks again for your effort.
I just added a card in the default dashboard in order to access easily to a big button with HA android app (and another one to be able to check at the same time door status and battery level).
It has been a real pleasure. Happy to have helped in some way.
that was the whole purpose of the card: now every user has all the data needed and all actions available to customize it as they prefer.
glad it’s working fine also for you.
@Friedrieck it’s working fine now, the only issue remaining is that at every HA restart, I see these in the logs, I guess it’s due to the REST calls not being completed yet while HA tries to render the templates, but I’m not sure. Let me know your thoughts…
Not easy to find out about the first warning. Details when you click on it would have been helpful. Assuming it could be the state of the Nuki Lock Sensor State, then maybe try this:
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'} %}
{{ my_state[state_attr('sensor.nuki_endpoint_list', 'lastKnownState')['state']] | default('loading...') }}
Same approach for the other:
- name: "Nuki Device Name"
state: "{{ state_attr('sensor.nuki_endpoint_info','scanResults')[0]['name'] | default('loading...') }}"
icon: mdi:alphabetical-variant
I’m sorry, here are the details for all three.
First:
Logger: homeassistant.helpers.event
Source: helpers/template.py:391
First occurred: 31 May 2021, 22:13:48 (4 occurrences)
Last logged: 31 May 2021, 22:13:48
Error while processing template: Template("{{ state_attr('sensor.nuki_endpoint_info','scanResults')[0]['name'] }}")
Error while processing template: Template("{{ state_attr('sensor.nuki_endpoint_info','scanResults')[0]['rssi'] }}")
Error while processing template: Template("{% if state_attr('sensor.nuki_endpoint_info','scanResults')[0]['paired'] %} connected {% elif not state_attr('sensor.nuki_endpoint_info','scanResults')[0]['paired'] %} disconnected {% else %} Unknown {% endif %}")
Error while processing template: Template("{% if state_attr('sensor.nuki_endpoint_info','scanResults')[0]['paired'] %} mdi:bluetooth-connect {% elif not state_attr('sensor.nuki_endpoint_info','scanResults')[0]['paired'] %} mdi:bluetooth-off {% else %} mdi:bluetooth-audio {% endif %}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 389, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1358, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/local/lib/python3.8/site-packages/jinja2/sandbox.py", line 303, in getitem
return obj[argument]
jinja2.exceptions.UndefinedError: None has no element 0
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 505, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 391, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: None has no element 0
Second:
Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:72
Integration: Template (documentation, issues)
First occurred: 31 May 2021, 22:13:48 (4 occurrences)
Last logged: 31 May 2021, 22:13:48
TemplateError('UndefinedError: None has no element 0') while processing template 'Template("{{ state_attr('sensor.nuki_endpoint_info','scanResults')[0]['name'] }}")' for attribute '_state' in entity 'sensor.nuki_device_name'
TemplateError('UndefinedError: None has no element 0') while processing template 'Template("{{ state_attr('sensor.nuki_endpoint_info','scanResults')[0]['rssi'] }}")' for attribute '_state' in entity 'sensor.nuki_bridge_lock_bt_rssi'
TemplateError('UndefinedError: None has no element 0') while processing template 'Template("{% if state_attr('sensor.nuki_endpoint_info','scanResults')[0]['paired'] %} connected {% elif not state_attr('sensor.nuki_endpoint_info','scanResults')[0]['paired'] %} disconnected {% else %} Unknown {% endif %}")' for attribute '_state' in entity 'sensor.nuki_bridge_lock_bt_state'
TemplateError('UndefinedError: None has no element 0') while processing template 'Template("{% if state_attr('sensor.nuki_endpoint_info','scanResults')[0]['paired'] %} mdi:bluetooth-connect {% elif not state_attr('sensor.nuki_endpoint_info','scanResults')[0]['paired'] %} mdi:bluetooth-off {% else %} mdi:bluetooth-audio {% endif %}")' for attribute '_icon' in entity 'sensor.nuki_bridge_lock_bt_state'
Third:
Logger: homeassistant.helpers.template
Source: helpers/template.py:1366
First occurred: 31 May 2021, 22:13:48 (19 occurrences)
Last logged: 31 May 2021, 22:14:00
Template variable warning: 'None' has no attribute 'batteryCritical' when rendering '{{ state_attr('sensor.nuki_endpoint_list', 'lastKnownState')['batteryCritical'] }}'
Template variable warning: 'None' has no attribute 'keypadBatteryCritical' when rendering '{{ state_attr('sensor.nuki_endpoint_list', 'lastKnownState')['keypadBatteryCritical'] }}'
Template variable warning: 'None' has no attribute 'batteryCharging' when rendering '{% set battery_level = state_attr('sensor.nuki_endpoint_list', 'lastKnownState')['batteryChargeState'] | default(0) | int %} {% if state_attr('sensor.nuki_endpoint_list', 'lastKnownState')['batteryCharging'] %} {{ battery_level }} {% else %} {{ battery_level }} {% endif %}'
Template variable warning: 'None' has no attribute 'timestamp' when rendering '{{ (as_timestamp(state_attr('sensor.nuki_endpoint_list', 'lastKnownState')['timestamp'])) | timestamp_custom("%H:%M (%b %d)") }}'
Template variable warning: No first item, sequence was empty. when rendering '{%- set up_time = as_timestamp(now())-as_timestamp(states('sensor.uptime')) %} {%- macro phrase(name, divisor, mod=None) %} {%- set value = ((up_time // divisor) % (mod if mod else divisor)) | int %} {%- set end = 's' if value > 1 else '' %} {{- '{} {}{}'.format(value, name, end) if value | int > 0 else '' }} {%- endmacro %} {%- set values = [ phrase('week', 60*60*24*7), phrase('day', 60*60*24, 7), phrase('hour', 60*60, 24), phrase('min', 60) ] | select('!=','') | list %} {{ values | first }} ago'
I have another REST polling sensor that was also triggering errors of that sort. Most were solved by the automation below (yes, back to homeassistant start
event), and the rest by default()
in the templates (as in my last post):
alias: MàJ FullUp
description: ''
trigger:
- event: start
platform: homeassistant
condition: []
action:
- delay: '00:00:05'
- entity_id: sensor.fullup
service: homeassistant.update_entity
mode: single
or you live with these errors in your log (but nobody likes it)
Thx for this awesome work.
Just one question: undernuki_bridge_host do I just put in the ip address? Or is it something more?
The IP. As an example:
nuki_bridge_host: "192.168.0.5"
nuki_bridge_port: "8080"
I almost never restart HA (I create/modify automations sometime but it is not needed to restart to take them in account) so I really don’t care. Of course, one would want everything be perfect but in this case, it seems these errors doesn’t have any negative consequences. Thanks again to alexdelprete and the others who helped to build this nice “integration”.
You can use the IP or the HOSTNAME. If you use the hostname, make sure that DNS resolves it.
nuki_bridge_host: "nuki-bridge.axel.dom"
nuki_bridge_port: "8080"
Did you read the instructions and the example regarding the secrets.yaml content? I am showing my configuration there. I use a hostname, but you can use an IP.
it also supports the hostname.