home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.03k stars 31.06k forks source link

Shelly "Authentication expired" repairs appear for ShellySmokePlus #131308

Open kshala opened 5 days ago

kshala commented 5 days ago

The problem

I added all my ShellyPlusSmoke devices with password protected. Every day I get a couple of repair messages that the ShellyPlusSmoke authentication expired. It still seems to work. The device entities are showing data but the logbook shows that the entities are unavailable for a short time.

I haven't changed the passwords. So the repair message doesn't make sense to me and they are bothering.

What version of Home Assistant Core has the issue?

core-2024.11.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Shelly

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

00:24:09.470 host 10.2.4.1:80: RPC device create, MAC: 123456789012
07:32:45.822 Websocket server connection from 10.2.4.1 starting
07:32:45.822 Websocket server connection from 10.2.4.1 ready
07:32:45.852 recv(10.2.4.1): {'src': 'shellyplussmoke-123456789012', 'dst': 'ws', 'method': 'NotifyFullStatus', 'params': {'ts': 1731566804.16, 'ble': {}, 'cloud': {'connected': False}, 'devicepower:0': {'id': 0, 'battery': {'V': 2.99, 'percent': 97}}, 'mqtt': {'connected': False}, 'smoke:0': {'id': 0, 'alarm': False, 'mute': False}, 'sys': {'mac': '123456789012', 'restart_required': False, 'time': None, 'unixtime': None, 'uptime': 2, 'ram_size': 254968, 'ram_free': 160560, 'fs_size': 393216, 'fs_free': 172032, 'cfg_rev': 23, 'kvs_rev': 0, 'webhook_rev': 0, 'available_updates': {}, 'wakeup_reason': {'boot': 'poweron', 'cause': 'undefined'}, 'wakeup_period': 86400, 'reset_reason': 1}, 'wifi': {'sta_ip': '10.2.4.1', 'status': 'got ip', 'ssid': 'MY_WIFI', 'rssi': -56}, 'ws': {'connected': True}}}
07:32:45.852 host 10.2.4.1:80: RPC device initialize
07:32:45.852 Trying to connect to device at 10.2.4.1
07:32:45.871 Connected to 10.2.4.1
07:32:45.871 send(10.2.4.1:80): {'id': 1, 'method': 'Shelly.GetDeviceInfo', 'src': 'aios-140219336950416', 'dst': 'shellyplussmoke-123456789012'}
07:32:45.901 recv(10.2.4.1): {'src': 'shellyplussmoke-123456789012', 'dst': 'ws', 'method': 'NotifyStatus', 'params': {'ts': 1731566804.17, 'ws': {'connected': True}}}
07:32:45.902 recv(10.2.4.1:80): {'id': 1, 'src': 'shellyplussmoke-123456789012', 'dst': 'aios-140219336950416', 'result': {'name': 'Rauchmelder', 'id': 'shellyplussmoke-123456789012', 'mac': '123456789012', 'slot': 1, 'model': 'SNSN-0031Z', 'gen': 2, 'fw_id': '20241011-114442/1.4.4-g6d2a586', 'ver': '1.4.4', 'app': 'PlusSmoke', 'auth_en': True, 'auth_domain': 'shellyplussmoke-123456789012'}}
07:32:45.902 send(10.2.4.1:80): {'id': 2, 'method': 'Shelly.GetConfig', 'src': 'aios-140219336950416', 'dst': 'shellyplussmoke-123456789012', 'auth': {'realm': 'shellyplussmoke-123456789012', 'username': 'admin', 'nonce': 1731736965, 'cnonce': 1731738765, 'response': 'bf1eae0a75d9f6740bdafe9c35a1e013d8c3058386520bffa108e58eacbf3181', 'algorithm': 'SHA-256'}}
07:32:45.902 send(10.2.4.1:80): {'id': 3, 'method': 'Shelly.GetComponents', 'src': 'aios-140219336950416', 'params': {'dynamic_only': True}, 'dst': 'shellyplussmoke-123456789012', 'auth': {'realm': 'shellyplussmoke-123456789012', 'username': 'admin', 'nonce': 1731736965, 'cnonce': 1731738765, 'response': 'bf1eae0a75d9f6740bdafe9c35a1e013d8c3058386520bffa108e58eacbf3181', 'algorithm': 'SHA-256'}}
07:32:46.423 recv(10.2.4.1:80): {'id': 2, 'src': 'shellyplussmoke-123456789012', 'dst': 'aios-140219336950416', 'error': {'code': 401, 'message': '{"auth_type": "digest", "nonce": 1731566804, "nc": 1, "realm": "shellyplussmoke-123456789012", "algorithm": "SHA-256"}'}}
07:32:46.497 recv(10.2.4.1:80): {'id': 3, 'src': 'shellyplussmoke-123456789012', 'dst': 'aios-140219336950416', 'error': {'code': 401, 'message': '{"auth_type": "digest", "nonce": 1731566804, "nc": 1, "realm": "shellyplussmoke-123456789012", "algorithm": "SHA-256"}'}}
07:32:46.497 result(10.2.4.1:80): Shelly.GetConfig(None) -> UndefinedType._singleton
07:32:46.497 result(10.2.4.1:80): Shelly.GetComponents({'dynamic_only': True}) -> UndefinedType._singleton
07:32:46.497 send(10.2.4.1:80): {'id': 4, 'method': 'Shelly.GetConfig', 'src': 'aios-140219336950416', 'dst': 'shellyplussmoke-123456789012', 'auth': {'realm': 'shellyplussmoke-123456789012', 'username': 'admin', 'nonce': 1731566804, 'cnonce': 1731738766, 'response': '3750c3f5b8eac4b28c9d062ca36aa34901139fde7602728ec9ffd583fb5e8dbb', 'algorithm': 'SHA-256'}}
07:32:46.498 send(10.2.4.1:80): {'id': 5, 'method': 'Shelly.GetComponents', 'src': 'aios-140219336950416', 'params': {'dynamic_only': True}, 'dst': 'shellyplussmoke-123456789012', 'auth': {'realm': 'shellyplussmoke-123456789012', 'username': 'admin', 'nonce': 1731566804, 'cnonce': 1731738766, 'response': '3750c3f5b8eac4b28c9d062ca36aa34901139fde7602728ec9ffd583fb5e8dbb', 'algorithm': 'SHA-256'}}
07:32:46.541 recv(10.2.4.1:80): {'id': 4, 'src': 'shellyplussmoke-123456789012', 'dst': 'aios-140219336950416', 'error': {'code': 401, 'message': '{"auth_type": "digest", "nonce": 1731738766, "nc": 1, "realm": "shellyplussmoke-123456789012", "algorithm": "SHA-256"}'}}
07:32:46.558 recv(10.2.4.1): {'src': 'shellyplussmoke-123456789012', 'dst': 'ws', 'method': 'NotifyStatus', 'params': {'ts': 1731738766.49, 'cloud': {'connected': True}}}
07:32:46.586 recv(10.2.4.1:80): {'id': 5, 'src': 'shellyplussmoke-123456789012', 'dst': 'aios-140219336950416', 'error': {'code': 401, 'message': '{"auth_type": "digest", "nonce": 1731738766, "nc": 1, "realm": "shellyplussmoke-123456789012", "algorithm": "SHA-256"}'}}
07:32:46.586 recv(10.2.4.1:80): {'src': 'shellyplussmoke-123456789012', 'dst': 'aios-140219336950416', 'method': 'NotifyStatus', 'params': {'ts': 1731738766.49, 'cloud': {'connected': True}}}
07:32:46.586 result(10.2.4.1:80): Shelly.GetConfig(None) -> UndefinedType._singleton
07:32:46.586 result(10.2.4.1:80): Shelly.GetComponents({'dynamic_only': True}) -> UndefinedType._singleton
07:32:46.586 host 10.2.4.1:80: error: InvalidAuthError(InvalidAuthError('{"auth_type": "digest", "nonce": 1731738766, "nc": 1, "realm": "shellyplussmoke-123456789012", "algorithm": "SHA-256"}'))
07:32:46.586 Websocket client connection from 10.2.4.1:80 closed
07:32:52.543 recv(10.2.4.1): {'src': 'shellyplussmoke-123456789012', 'dst': 'ws', 'method': 'NotifyStatus', 'params': {'ts': 1731738772.48, 'smoke:0': {'id': 0, 'alarm': False}}}
07:32:52.543 host 10.2.4.1:80: RPC device initialize
07:32:52.543 Trying to connect to device at 10.2.4.1
07:32:52.547 recv(10.2.4.1): {'src': 'shellyplussmoke-123456789012', 'dst': 'ws', 'method': 'NotifyStatus', 'params': {'ts': 1731738772.48, 'sys': {'wakeup_reason': {'cause': 'status_update'}}}}
07:32:52.550 recv(10.2.4.1): {'src': 'shellyplussmoke-123456789012', 'dst': 'ws', 'method': 'NotifyEvent', 'params': {'ts': 1731738772.48, 'events': [{'component': 'sys', 'event': 'sleep', 'ts': 1731738772.48}]}}
07:32:52.558  Connected to 10.2.4.1
07:32:52.558 send(10.2.4.1:80): {'id': 6, 'method': 'Shelly.GetDeviceInfo', 'src': 'aios-140219336950416', 'dst': 'shellyplussmoke-123456789012', 'auth': {'realm': 'shellyplussmoke-123456789012', 'username': 'admin', 'nonce': 1731566804, 'cnonce': 1731738766, 'response': '3750c3f5b8eac4b28c9d062ca36aa34901139fde7602728ec9ffd583fb5e8dbb', 'algorithm': 'SHA-256'}}
07:32:52.581 recv(10.2.4.1:80): {'id': 6, 'src': 'shellyplussmoke-123456789012', 'dst': 'aios-140219336950416', 'result': {'name': 'Rauchmelder', 'id': 'shellyplussmoke-123456789012', 'mac': '123456789012', 'slot': 1, 'model': 'SNSN-0031Z', 'gen': 2, 'fw_id': '20241011-114442/1.4.4-g6d2a586', 'ver': '1.4.4', 'app': 'PlusSmoke', 'auth_en': True, 'auth_domain': 'shellyplussmoke-123456789012'}}
07:32:52.581 result(10.2.4.1:80): Shelly.GetDeviceInfo(None) -> {'name': 'Rauchmelder', 'id': 'shellyplussmoke-123456789012', 'mac': '123456789012', 'slot': 1, 'model': 'SNSN-0031Z', 'gen': 2, 'fw_id': '20241011-114442/1.4.4-g6d2a586', 'ver': '1.4.4', 'app': 'PlusSmoke', 'auth_en': True, 'auth_domain': 'shellyplussmoke-123456789012'}
07:32:52.581 send(10.2.4.1:80): {'id': 7, 'method': 'Shelly.GetConfig', 'src': 'aios-140219336950416', 'dst': 'shellyplussmoke-123456789012', 'auth': {'realm': 'shellyplussmoke-123456789012', 'username': 'admin', 'nonce': 1731736972, 'cnonce': 1731738772, 'response': 'db5d3e581d043aad2256f012e7afceb3a6ed913881ef3cfd0c7025120089d693', 'algorithm': 'SHA-256'}}
07:32:52.581 send(10.2.4.1:80): {'id': 8, 'method': 'Shelly.GetComponents', 'src': 'aios-140219336950416', 'params': {'dynamic_only': True}, 'dst': 'shellyplussmoke-123456789012', 'auth': {'realm': 'shellyplussmoke-123456789012', 'username': 'admin', 'nonce': 1731736972, 'cnonce': 1731738772, 'response': 'db5d3e581d043aad2256f012e7afceb3a6ed913881ef3cfd0c7025120089d693', 'algorithm': 'SHA-256'}}
07:32:52.617 recv(10.2.4.1:80): {'id': 7, 'src': 'shellyplussmoke-123456789012', 'dst': 'aios-140219336950416', 'result': {'ble': {'enable': False, 'rpc': {'enable': True}}, 'cloud': {'enable': True, 'server': 'shelly-121-eu.shelly.cloud:6022/jrpc'}, 'devicepower:0': {}, 'mqtt': {'enable': False, 'server': None, 'client_id': 'shellyplussmoke-123456789012', 'user': None, 'ssl_ca': None, 'topic_prefix': 'shellyplussmoke-123456789012', 'rpc_ntf': True, 'status_ntf': False, 'use_client_cert': False, 'enable_rpc': True, 'enable_control': True}, 'smoke:0': {'id': 0, 'name': 'Rauchmelder'}, 'sys': {'device': {'name': 'Rauchmelder', 'mac': '123456789012', 'fw_id': '20241011-114442/1.4.4-g6d2a586', 'discoverable': True}, 'location': {'tz': 'Europe/Berlin', 'lat': 1.8296, 'lon': 2.9813}, 'debug': {'level': 2, 'file_level': None, 'mqtt': {'enable': False}, 'websocket': {'enable': False}, 'udp': {'addr': None}}, 'ui_data': {}, 'rpc_udp': {'dst_addr': None, 'listen_port': None}, 'sntp': {'server': 'time.google.com'}, 'cfg_rev': 23}, 'wifi': {'ap': {'ssid': 'ShellyPlusSmoke-123456789012', 'is_open': True, 'enable': False}, 'sta': {'ssid': 'MY_WIFI', 'is_open': False, 'enable': True, 'ipv4mode': 'dhcp', 'ip': None, 'netmask': None, 'gw': None, 'nameserver': None}, 'sta1': {'ssid': None, 'is_open': True, 'enable': False, 'ipv4mode': 'dhcp', 'ip': None, 'netmask': None, 'gw': None, 'nameserver': None}, 'roam': {'rssi_thr': -80, 'interval': 60}}, 'ws': {'enable': True, 'server': 'ws://10.0.1.2:8123/api/shelly/ws', 'ssl_ca': '*'}}}
07:32:52.662 recv(10.2.4.1:80): {'id': 8, 'src': 'shellyplussmoke-123456789012', 'dst': 'aios-140219336950416', 'result': {'components': [], 'cfg_rev': 23, 'offset': 0, 'total': 0}}
07:32:52.662 result(10.2.4.1:80): Shelly.GetConfig(None) -> {'ble': {'enable': False, 'rpc': {'enable': True}}, 'cloud': {'enable': True, 'server': 'shelly-121-eu.shelly.cloud:6022/jrpc'}, 'devicepower:0': {}, 'mqtt': {'enable': False, 'server': None, 'client_id': 'shellyplussmoke-123456789012', 'user': None, 'ssl_ca': None, 'topic_prefix': 'shellyplussmoke-123456789012', 'rpc_ntf': True, 'status_ntf': False, 'use_client_cert': False, 'enable_rpc': True, 'enable_control': True}, 'smoke:0': {'id': 0, 'name': 'Rauchmelder'}, 'sys': {'device': {'name': 'Rauchmelder', 'mac': '123456789012', 'fw_id': '20241011-114442/1.4.4-g6d2a586', 'discoverable': True}, 'location': {'tz': 'Europe/Berlin', 'lat': 1.8296, 'lon': 2.9813}, 'debug': {'level': 2, 'file_level': None, 'mqtt': {'enable': False}, 'websocket': {'enable': False}, 'udp': {'addr': None}}, 'ui_data': {}, 'rpc_udp': {'dst_addr': None, 'listen_port': None}, 'sntp': {'server': 'time.google.com'}, 'cfg_rev': 23}, 'wifi': {'ap': {'ssid': 'ShellyPlusSmoke-123456789012', 'is_open': True, 'enable': False}, 'sta': {'ssid': 'MY_WIFI', 'is_open': False, 'enable': True, 'ipv4mode': 'dhcp', 'ip': None, 'netmask': None, 'gw': None, 'nameserver': None}, 'sta1': {'ssid': None, 'is_open': True, 'enable': False, 'ipv4mode': 'dhcp', 'ip': None, 'netmask': None, 'gw': None, 'nameserver': None}, 'roam': {'rssi_thr': -80, 'interval': 60}}, 'ws': {'enable': True, 'server': 'ws://10.0.1.2:8123/api/shelly/ws', 'ssl_ca': '*'}}
07:32:52.662 result(10.2.4.1:80): Shelly.GetComponents({'dynamic_only': True}) -> {'components': [], 'cfg_rev': 23, 'offset': 0, 'total': 0}
07:32:52.662 host 10.2.4.1:80: RPC device init finished
07:32:53.018 Websocket client connection from 10.2.4.1:80 closed

Additional information

Debug logs show a bunch of 401 error codes with changing nonce. The error may be caused by a missing unixtime assuming that these shellys require time from an SNTP. I created a local network SNTP server (chrony) but this didn't help. Also I don't know if the error is more a race condition with two messages sent parallely with failing authentication. Assuming that a 401 response generates a new nonce. Two 401 that close to each other would generate two nonce. Combined with lacking synchronization in the Shelly firmware I believe the issue is the concurrent call to shelly and calling the device in sequentially should be more robust.

home-assistant[bot] commented 5 days ago

Hey there @balloob, @bieniu, @thecode, @chemelli74, @bdraco, mind taking a look at this issue as it has been labeled with an integration (shelly) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `shelly` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign shelly` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


shelly documentation shelly source (message by IssueLinks)

thecode commented 5 days ago

Your log clearly show that the device rejects the connection reporting the authentication data is invalid, it doesn't matter if you didn't change it, the one stored in HA probably doesn't match the one on the device. Entities will keep updating since the device push data to HA on changes, but some of them won't work.

07:32:46.586 host 10.2.4.1:80: error: InvalidAuthError(InvalidAuthError 

You need to manually wake up the device using the button and reauthenticate it with HA, after this it should work, when you do it keep the debug log and if it still happens upload the new log.

kshala commented 5 days ago

I’ve done re authentication already. I never changed the password on the device but followed the repair instructions entering the password. Within a day or two new repairs appear and ask to enter the password again. The logs I posted are made after the issue happened again.

One time I gone through all repair messages and entered the passwords. Then reboot ha. Within a day about five new repairs appeared. I have ten smoke detectors. Since the devices boot every 24 hours I believe the issue isn’t 100% reproducible.

I created an automaton that sends a push notification when a persistent notification (like repair) is added. When I manually start the device (the taps on the button) there is a 50% chance to get a notification. Sometimes it takes two or three boot up to make the notification appear.