StyraHem / ShellyForHASS

Shelly smart home platform for Home Assistant
MIT License
619 stars 111 forks source link

[BUG] Shelly H&T does not get discovered #422

Closed TheGroundZero closed 2 years ago

TheGroundZero commented 4 years ago

Environment

shelly: 0.2.0-b6
pyShelly: 0.2.8
developed_by: StyraHem.se
friendly_name: ShellyForHass
Supervisor -
Version 235
Latest version 235
Host system -
Hostname homeassistant
System HassOS 4.12
Deployment production

Shelly firmware: 20200812-091311/v1.8.0@8acf41b0

Describe the bug

Shelly H&T (battery powered) do not appear in device list

Steps to Reproduce

Expected behavior

Screenshots

Traceback/Error logs

Additional context

david-kalbermatten commented 4 years ago

I'm assuming you already tried pressing the internal button of the H&T to have it connect to your Wifi so that ShellyForHass had a fair chance of finding it, right? ;D

Jokes aside, you need to have your Shelly H&T connected to Wifi, which you can either do by removing its power source and then reconnecting it or by pressing the button once, which should give you about 60 seconds or so to get it connected to Home Assistant.

The Shelly H&T only connects to Wifi when the temperature or humidity changed enough to trigger an update. This power-saving measure allows the Shelly H&T to run off a battery for up to a year, otherwise you'd run out of juice rather quickly...

hakana commented 4 years ago

For me this work as it should. You must have CoAP working for the sensors.

TheGroundZero commented 4 years ago

I'm assuming you already tried pressing the internal button of the H&T to have it connect to your Wifi so that ShellyForHass had a fair chance of finding it, right? ;D

I have woken up the H&T by pressing the button whilst HA was rebooting and again after HA was fully booted.
This should've given ShellyForHASS plenty of time to discover my H&T.

Note that my WD2 are still unavailable after yesterday's HA reboot, so ShellyForHASS hasn't rediscover them still and/or didn't retain their last state (which is incorrect anyhow, see #421). I didn't manually wake them, but my doors have been open and closed in between then and now.

Jokes aside, you need to have your Shelly H&T connected to Wifi, which you can either do by removing its power source and then reconnecting it or by pressing the button once, which should give you about 60 seconds or so to get it connected to Home Assistant.

The Shelly H&T only connects to Wifi when the temperature or humidity changed enough to trigger an update. This power-saving measure allows the Shelly H&T to run off a battery for up to a year, otherwise you'd run out of juice rather quickly...

I know that the H&T --whilst running on battery-- goes into sleep and only wakes up on temp/humidity changes, every hour or so, or after pressing the button inside.
However, my H&T have so far never been discovered by ShellyForHASS although I've had them for a couple of weeks so far.
I have 3 of them, so should be odd to have an issue with all 3 of them. I believe 2 of them have the FW upgrade for longer IDs and 1 has only been updated with the regular FW. All of them are at the latest FW version.

There's no issue on the network side, since the H&T are connected to the same WiFi network as my other Shelly's and they all have a static IP configured at both the router and the Shelly itself.

hakana commented 4 years ago

What show protocols for your other devices?

TheGroundZero commented 4 years ago

What show protocols for your other devices?

Is this what you mean? image image

hakana commented 4 years ago

As you can see under protocols you don't have CoAP working in your network. How is your network setup?

TheGroundZero commented 4 years ago

As you can see under protocols you don't have CoAP working in your network. How is your network setup?

HomeAssistant is installed in a VM (proxmox) in my management VLAN.
Shelly's are installed in IoT VLAN.
mDNS forwarding etc. is enabled in my UniFi gateway.
Currently no rules blocking traffic between HA and Shelly's.

Any way for me to test CoAP connection with any of the devices?

TheGroundZero commented 4 years ago

Added the following to configuration.yaml:

logger:
  default: warn
  logs:
    pyShelly: debug

This is in my logs:

Note: 192.168.10.105 is HA, 192.168.60.71-75 are Shelly relays, 90-92 are H&T and 95-96 are DW2. 71-75 are detected immediately, 95-96 not (probably in a few hours), 90-92 never.

2020-09-09 17:11:09 DEBUG (Update loop) [pyShelly] Start update loop, 0:01:00 sec
2020-09-09 17:11:09 DEBUG (Update loop) [pyShelly] Sending CoAP discover UDP
2020-09-09 17:11:09 DEBUG (MainThread) [pyShelly] Sending CoAP discover UDP
2020-09-09 17:11:09 DEBUG (zeroconf-ServiceBrowser__http._tcp.local._267) [pyShelly] Add device by host 192.168.60.71 mDns
2020-09-09 17:11:09 DEBUG (Cloud) [pyShelly] Update from cloud
2020-09-09 17:11:09 DEBUG (zeroconf-ServiceBrowser__http._tcp.local._267) [pyShelly] Add device by host 192.168.60.73 mDns
2020-09-09 17:11:09 DEBUG (zeroconf-ServiceBrowser__http._tcp.local._267) [pyShelly] Add device by host 192.168.60.74 mDns
2020-09-09 17:11:09 DEBUG (zeroconf-ServiceBrowser__http._tcp.local._267) [pyShelly] Add device by host 192.168.60.75 mDns
2020-09-09 17:11:10 DEBUG (zeroconf-ServiceBrowser__http._tcp.local._267) [pyShelly] Add device by host 192.168.60.72 mDns
2020-09-09 17:11:11 DEBUG (Cloud) [pyShelly] POST to Shelly Cloud
2020-09-09 17:11:14 DEBUG (Cloud) [pyShelly] POST to Shelly Cloud
2020-09-09 17:11:19 DEBUG (CoAP) [pyShelly] CoAP msg: 192.168.10.105 b'P\x01\x00\n\xb3cit\x01d\xff'
2020-09-09 17:11:19 DEBUG (CoAP) [pyShelly] CoAP msg: 1 192.168.10.105 bytearray(b'P\x01\x00\n\xb3cit\x01d\xff')
2020-09-09 17:11:19 DEBUG (CoAP) [pyShelly] CoAP msg: 192.168.10.105 b'P\x01\x00\n\xb3cit\x01d\xff'
2020-09-09 17:11:19 DEBUG (CoAP) [pyShelly] CoAP msg: 1 192.168.10.105 bytearray(b'P\x01\x00\n\xb3cit\x01d\xff')
2020-09-09 17:12:09 DEBUG (Update loop) [pyShelly] http://192.168.60.71/settings
2020-09-09 17:12:10 DEBUG (Update loop) [pyShelly] http://192.168.60.71/settings - Ok
2020-09-09 17:12:10 DEBUG (Update loop) [pyShelly] http://192.168.60.71/status
2020-09-09 17:12:10 DEBUG (Update loop) [pyShelly] http://192.168.60.71/status - Ok
2020-09-09 17:12:10 DEBUG (Update loop) [pyShelly] Add device from IP, ******, SHSW-PM, 192.168.60.71
2020-09-09 17:12:10 DEBUG (Update loop) [pyShelly] http://192.168.60.71/settings
2020-09-09 17:12:10 DEBUG (Update loop) [pyShelly] http://192.168.60.71/settings - Ok
2020-09-09 17:12:10 DEBUG (Update loop) [pyShelly] Add device
... couple of "Add device"
2020-09-09 17:12:11 DEBUG (Update loop) [pyShelly] http://192.168.60.74/settings
2020-09-09 17:12:11 DEBUG (Update loop) [pyShelly] http://192.168.60.74/settings - Ok
2020-09-09 17:12:11 DEBUG (Update loop) [pyShelly] http://192.168.60.74/status
2020-09-09 17:12:11 DEBUG (Update loop) [pyShelly] http://192.168.60.74/status - Ok
2020-09-09 17:12:11 DEBUG (Update loop) [pyShelly] Add device from IP, ************, SHSW-PM, 192.168.60.74
2020-09-09 17:12:11 DEBUG (Update loop) [pyShelly] http://192.168.60.74/settings
2020-09-09 17:12:11 DEBUG (Update loop) [pyShelly] http://192.168.60.74/settings - Ok
2020-09-09 17:12:11 DEBUG (Update loop) [pyShelly] Add device
... couple of "Add device"
... same for .72, .73, .75
...
2020-09-09 17:12:13 DEBUG (Update loop) [pyShelly] Sending CoAP discover UDP
2020-09-09 17:12:13 DEBUG (Update loop) [pyShelly] Polling block, 766848 SHSW-PM
2020-09-09 17:12:13 DEBUG (Poll status) [pyShelly] Get status from 766848 Kinderkamer - Lamp
2020-09-09 17:12:13 DEBUG (Poll status) [pyShelly] http://192.168.60.71/status
2020-09-09 17:12:13 DEBUG (CoAP) [pyShelly] CoAP msg: 192.168.10.105 b'P\x01\x00\n\xb3cit\x01d\xff'
2020-09-09 17:12:13 DEBUG (CoAP) [pyShelly] CoAP msg: 1 192.168.10.105 bytearray(b'P\x01\x00\n\xb3cit\x01d\xff')
2020-09-09 17:12:13 DEBUG (Update loop) [pyShelly] Polling block, ************ SHSW-25
2020-09-09 17:12:13 DEBUG (Poll status) [pyShelly] Get status from ************ Buiten - Achterdeur
2020-09-09 17:12:13 DEBUG (Poll status) [pyShelly] http://192.168.60.74/status
2020-09-09 17:12:13 DEBUG (Update loop) [pyShelly] Polling block, ************ SHSW-PM
... Polling .72, .73. .75 as well
2020-09-09 17:12:13 DEBUG (Poll status) [pyShelly] http://192.168.60.71/status - Ok
2020-09-09 17:12:13 DEBUG (Poll status) [pyShelly] Update id:****** state:True stateValue:{'last_event': '', 'event_cnt': 0}
2020-09-09 17:12:13 DEBUG (Poll status) [pyShelly] http://192.168.60.74/status - Ok
... Status for .72, .73, .75 OK as well
2020-09-09 17:12:14 DEBUG (Cloud) [pyShelly] Update from cloud
2020-09-09 17:12:14 DEBUG (Cloud) [pyShelly] POST to Shelly Cloud
2020-09-09 17:12:16 DEBUG (Cloud) [pyShelly] POST to Shelly Cloud
2020-09-09 17:12:28 DEBUG (CoAP) [pyShelly] IGMP fix
2020-09-09 17:13:13 DEBUG (Update loop) [pyShelly] Sending CoAP discover UDP
2020-09-09 17:13:13 DEBUG (CoAP) [pyShelly] CoAP msg: 192.168.10.105 b'P\x01\x00\n\xb3cit\x01d\xff'
2020-09-09 17:13:13 DEBUG (CoAP) [pyShelly] CoAP msg: 1 192.168.10.105 bytearray(b'P\x01\x00\n\xb3cit\x01d\xff')
2020-09-09 17:13:13 DEBUG (Update loop) [pyShelly] Polling block, ****** SHSW-PM
2020-09-09 17:13:13 DEBUG (Poll status) [pyShelly] Get status from ****** Kinderkamer - Lamp
2020-09-09 17:13:13 DEBUG (Poll status) [pyShelly] http://192.168.60.71/status
2020-09-09 17:13:13 DEBUG (Poll status) [pyShelly] Get status from ************ Buiten - Achterdeur
2020-09-09 17:13:13 DEBUG (Poll status) [pyShelly] http://192.168.60.74/status
2020-09-09 17:13:13 DEBUG (Update loop) [pyShelly] Polling block, ************ SHSW-PM
... Polling .72, .73. .75 as well
2020-09-09 17:13:13 DEBUG (Poll status) [pyShelly] http://192.168.60.71/status - Ok
2020-09-09 17:13:13 DEBUG (Poll status) [pyShelly] Update id:766848 state:True stateValue:{'last_event': '', 'event_cnt': 0}
2020-09-09 17:13:13 DEBUG (Poll status) [pyShelly] http://192.168.60.74/status - Ok
2020-09-09 17:13:13 DEBUG (Poll status) [pyShelly] Update id:************ state:False stateValue:{'last_event': '', 'event_cnt': 0}
... Status for .72, .73, .75 OK as well
2020-09-09 17:13:16 DEBUG (Cloud) [pyShelly] Update from cloud
2020-09-09 17:13:16 DEBUG (Cloud) [pyShelly] POST to Shelly Cloud
2020-09-09 17:13:18 DEBUG (Cloud) [pyShelly] POST to Shelly Cloud
2020-09-09 17:13:28 DEBUG (CoAP) [pyShelly] IGMP fix
... status updates again
2020-09-09 17:14:18 DEBUG (Cloud) [pyShelly] Update from cloud
2020-09-09 17:14:18 DEBUG (Cloud) [pyShelly] POST to Shelly Cloud
2020-09-09 17:14:21 DEBUG (Cloud) [pyShelly] POST to Shelly Cloud
2020-09-09 17:14:28 DEBUG (CoAP) [pyShelly] IGMP fix
2020-09-09 17:15:13 DEBUG (Update loop) [pyShelly] Sending CoAP discover UDP
... polling and statuses
2020-09-09 17:26:28 DEBUG (CoAP) [pyShelly] IGMP fix
2020-09-09 17:26:46 DEBUG (Cloud) [pyShelly] Update from cloud
2020-09-09 17:26:46 DEBUG (Cloud) [pyShelly] POST to Shelly Cloud
2020-09-09 17:26:48 DEBUG (Cloud) [pyShelly] POST to Shelly Cloud
... repeat
2020-09-09 17:34:28 DEBUG (CoAP) [pyShelly] IGMP fix
... still no DW2 or H&T to be seen

I removed those lines from the config and rebooted HA to prevent log becoming too big

nunogia commented 4 years ago

I have COAP and still 2 of my 3 H&T are not found. I have static ip on all 3. But only one is found. Had them working previously.

martin3000 commented 4 years ago

I have this in my log:

Setup failed for shelly: Unable to import component: cannot import name 'async_get_instance' from 'homeassistant.components.zeroconf' (/home/nuc/.local/lib/python3.8/site-packages/homeassistant/components/zeroconf/init.py)

hakana commented 3 years ago

async_get_instance error will be fixed in the next release. If you upgrade HA to the latest version the error will also go away.

About not finding the H&T it is probably because CoAP not working as it should. You can try to enable the igmp_fix. There is also a python proxy you can run to forward CoAP messages from one VLAN to another.

nelsnels commented 3 years ago

I get the same issue with HASS running on a Raspberry PI and ShellyForHASS Release 0.2.1 Beta 1.

With auto-discover through the Shelly cloud : shelly: cloud_auth_key: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" cloud_server: "shelly-XXXXX.shelly.cloud"

My Shelly 3EM is correctly discover but none of my two Shelly H&T are (although they correctly appear in the my.shelly.cloud interface).

The system is running for few days now, I performed several restart of HASS, set fixed IPs, clicked on the Shelly H&T button, but still noting.

I guess the issue shouldn't come from CoAP since the Shelly 3EM work properly, right? Any other ideas?

david-kalbermatten commented 3 years ago

I guess the issue shouldn't come from CoAP since the Shelly 3EM work properly, right? Any other ideas?

@nelsnels This depends on what your Shelly 3EM shows under protocols in ShellyForHass:

Is this what you mean? image

As you can see in this image from the thread above the CoAP protocol isn't listed i.e. the network or its configuration doesn't support it. So if your Shelly 3EM doesn't show CoAP there, your issue is the same as his.

Like hakana said:

As you can see under protocols you don't have CoAP working in your network.

...meaning: no CoAP -> no Shelly H&T, and for that matter, no Shelly Product that runs on batteries since they all use the same way to broadcast changes.