I don’t have more than one lock, but I guess you need to setup another three shellcommands and use the ID of the second lock in IDNUKISMARTLOCK like I told there →
Configuration.yaml
nuki_lock:
alias: nuki-lock
sequence:
- service: shell_command.nuki_lock
mode: single
nuki1_lock:
alias: nuki1-lock
sequence:
- service: shell_command.nuki1_lock
mode: single
I’m trying @alexdelprete sensors package but I get few errors:
The BT Status and BT RSSI sensors report Unknown/Sconosciuto very often as the following screenshot
And the following errors appear in the HA log:
Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:72
Integration: Template (documentation, issues)
First occurred: 18 maggio 2021, 15:09:44 (4 occurrences)
Last logged: 5:21:37
TemplateError('UndefinedError: 'mappingproxy object' has no attribute 'timestamp'') while processing template 'Template("{{ (as_timestamp(states.sensor.nuki_lock_status.attributes.timestamp)) | timestamp_custom("%H:%M (%b %d)") }}")' for attribute '_state' in entity 'sensor.nuki_last_activity'
Logger: homeassistant.helpers.template
Source: helpers/template.py:1378
First occurred: 18 maggio 2021, 15:09:44 (16 occurrences)
Last logged: 5:22:37
Template variable error: 'mappingproxy object' has no attribute 'timestamp' when rendering '{{ (as_timestamp(states.sensor.nuki_lock_status.attributes.timestamp)) | timestamp_custom("%H:%M (%b %d)") }}'
Logger: homeassistant.components.rest.data
Source: components/rest/data.py:69
Integration: RESTful (documentation, issues)
First occurred: 18 maggio 2021, 15:09:44 (491 occurrences)
Last logged: 7:59:35
Error fetching data: http://192.168.0.84:8080/list?token=xxxxxxxxxx failed with
Error fetching data: http://192.168.0.84:8080/info?token=xxxxxxxxxx failed with Server disconnected without sending a response.
Error fetching data: http://192.168.0.84:8080/list?token=xxxxxxxxxx failed with Server disconnected without sending a response.
Logger: homeassistant.components.rest.sensor
Source: components/rest/sensor.py:181
Integration: RESTful (documentation, issues)
First occurred: 18 maggio 2021, 15:09:44 (491 occurrences)
Last logged: 7:59:35
Empty reply found when expecting JSON data
I did not change anything. Just copied and pasted Alex’s code.
The sensor.nuki_lock_bt_rssi is a signal_strenght device_class sensor. It expects a db value and reports Unknown in the HA system language if that value is not found (as does the Nuki official integration binary sensor). My HA system language is italian, Unknown = Sconosciuto
Okay, if you don’t want to show
The only problem I can imagine aside wrong indentations are old firmware (see this thread above) but since your battery level is shown, this might not the case.
So sometimes you do see the values correctly right? It’s just a matter of connection to the bridge, even if you tried manually, it happens that sometimes the bridge doesn’t answer, it happened to me when I was polling it too frequently. That’s why I changed the scan_interval to 120, I found that polling too frequently led to unreliable results.
Try calling the url from shell repeatedly and see if it always answers correctly.
When you restart HA, if values are ok, it means the code is fine, it’s just that when it refreshes the sensors calling the url again, those 2 values are not ok, so Unknown comes out.
The errors you showed indicate you are having connection issues, probably wifi disconnections or routing issues.
Error fetching data: http://192.168.0.84:8080/list?token=xxxxxxxxxx failed with
Error fetching data: http://192.168.0.84:8080/info?token=xxxxxxxxxx failed with Server disconnected without sending a response.
Error fetching data: http://192.168.0.84:8080/list?token=xxxxxxxxxx failed with Server disconnected without sending a response.
Empty reply found when expecting JSON data
Nothing to do with the code, if the connection is good, the JSON data is returned from the bridge, and the code retrieves and shows the proper values.
I think I figured out. I had to put double quotes in json_attributes in “patform: rest” sections. After two hours no more log errors or “unknown” values.
He says that when restarting HA the 2 values are ok. If you see the errors at the end of his post, it clearly shows he’s having connection problems when calling the bridge URLs. Either the wifi is not reliable or something else.
Thank you Alex but my connection seem to be reliable. During the errors I tried to get the values manually giong with my browser to the “list” and “info” pages and the bridge always returned the values flawlessly (while the HA card was continuing to show “unknown”).
I will remove the quotes to check if the errors will reappear.
Your connection to the bridge is not reliable. The code is ok, if double quotes were needed, I’d have the same problem and you would have all values to Unknown.
Actually the log doesn’t lie. Maybe some interferences which I noticed in some hours of the day since my neighbor installed an ezviz system.
Btw thanks for this useful code!
TemplateError('UndefinedError: 'None' has no attribute 'attributes'') while processing template 'Template("{{ (as_timestamp(states.sensor.nuki_lock_status.attributes.timestamp)) | timestamp_custom("%H:%M (%b %d)") }}")' for attribute '_state' in entity 'sensor.nuki_last_activity'
1:32:53 PM – (ERROR) Template - message first occurred at 1:32:53 PM and shows up 2 times
Template variable error: 'None' has no attribute 'attributes' when rendering '{{ (as_timestamp(states.sensor.nuki_lock_status.attributes.timestamp)) | timestamp_custom("%H:%M (%b %d)") }}'
1:32:53 PM – (ERROR) helpers/template.py - message first occurred at 1:32:53 PM and shows up 2 times