StyraHem / ShellyForHASS

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

[BUG] Error receiving CoAP UDP, 'NoneType' #626

Closed amrheing closed 2 years ago

amrheing commented 2 years ago

this issue was listet in 2020 and is closed

Environment

Describe the bug

when switching a shelly the state goes back. the switching is not made

Steps to Reproduce

switch a shelly1 or shelly dimmer in my case

Expected behavior

the switching should work

Screenshots

If applicable, add screenshots to help explain your problem.

Traceback/Error logs

2021-12-14 19:46:03 ERROR (CoAP) [pyShelly] Error receiving CoAP UDP, 'NoneType' object has no attribute 'add_job', Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/pyShelly/coap.py", line 187, in _loop self._root.update_block(device_id, device_type, File "/usr/local/lib/python3.9/site-packages/pyShelly/init.py", line 359, in update_block block.update_coap(data, ipaddr) File "/usr/local/lib/python3.9/site-packages/pyShelly/block.py", line 105, in update_coap dev.raise_updated() File "/usr/local/lib/python3.9/site-packages/pyShelly/base.py", line 46, in raise_updated callback(self) File "/config/custom_components/shelly/device.py", line 58, in _updated self._update_ha_state() File "/config/custom_components/shelly/device.py", line 51, in _update_ha_state self.schedule_update_ha_state(True) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 643, in schedule_update_ha_state self.hass.add_job(self.async_update_ha_state(force_refresh)) # type: ignore AttributeError: 'NoneType' object has no attribute 'add_job' Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/pyShelly/coap.py", line 187, in _loop self._root.update_block(device_id, device_type, File "/usr/local/lib/python3.9/site-packages/pyShelly/init.py", line 359, in update_block block.update_coap(data, ipaddr) File "/usr/local/lib/python3.9/site-packages/pyShelly/block.py", line 105, in update_coap dev.raise_updated() File "/usr/local/lib/python3.9/site-packages/pyShelly/base.py", line 46, in raise_updated callback(self) File "/config/custom_components/shelly/device.py", line 58, in _updated self._update_ha_state() File "/config/custom_components/shelly/device.py", line 51, in _update_ha_state self.schedule_update_ha_state(True) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 643, in schedule_update_ha_state self.hass.add_job(self.async_update_ha_state(force_refresh)) # type: ignore AttributeError: 'NoneType' object has no attribute 'add_job'

Additional context

amrheing commented 2 years ago

some more logs:

2021-12-14 20:17:05 ERROR (Poll status) [pyShelly] Error update device status: 84CCA8A5A97D SHSW-1, 'NoneType' object has no attribute 'add_job', Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/pyShelly/block.py", line 290, in _update_status_info File "/usr/local/lib/python3.9/site-packages/pyShelly/base.py", line 46, in raise_updated File "/usr/local/lib/python3.9/site-packages/pyShelly/block.py", line 290, in _update_status_info File "/usr/local/lib/python3.9/site-packages/pyShelly/base.py", line 46, in raise_updated 2021-12-14 20:17:05 ERROR (Poll status) [pyShelly] Error update device status: 84CCA8A5A97D SHSW-1, 'NoneType' object has no attribute 'add_job', Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/pyShelly/block.py", line 290, in _update_status_info File "/usr/local/lib/python3.9/site-packages/pyShelly/base.py", line 46, in raise_updated File "/usr/local/lib/python3.9/site-packages/pyShelly/block.py", line 290, in _update_status_info File "/usr/local/lib/python3.9/site-packages/pyShelly/base.py", line 46, in raise_updated 2021-12-14 20:17:05 ERROR (Poll status) [pyShelly] Error update device status: 8CAAB5437E87 SHSW-PM, 'NoneType' object has no attribute 'add_job', Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/pyShelly/block.py", line 290, in _update_status_info File "/usr/local/lib/python3.9/site-packages/pyShelly/base.py", line 46, in raise_updated File "/usr/local/lib/python3.9/site-packages/pyShelly/block.py", line 290, in _update_status_info File "/usr/local/lib/python3.9/site-packages/pyShelly/base.py", line 46, in raise_updated

pbix commented 2 years ago

I am using Shelly 1 PM and have the same with HA v2021.12.2 and vIntegration 0.3.2 released two days ago, This device is showing Unavailable. Another device Shelly UNI, is working.

File "/usr/local/lib/python3.9/site-packages/pyShelly/coap.py", line 187, in _loop self._root.update_block(device_id, device_type, File "/usr/local/lib/python3.9/site-packages/pyShelly/init.py", line 359, in update_block block.update_coap(data, ipaddr) File "/usr/local/lib/python3.9/site-packages/pyShelly/block.py", line 105, in update_coap dev.raise_updated() File "/usr/local/lib/python3.9/site-packages/pyShelly/base.py", line 46, in raise_updated callback(self) File "/config/custom_components/shelly/device.py", line 58, in _updated self._update_ha_state() File "/config/custom_components/shelly/device.py", line 51, in _update_ha_state self.schedule_update_ha_state(True) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 643, in schedule_update_ha_state self.hass.add_job(self.async_update_ha_state(force_refresh)) # type: ignore AttributeError: 'NoneType' object has no attribute 'add_job' Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/pyShelly/coap.py", line 187, in _loop self._root.update_block(device_id, device_type, File "/usr/local/lib/python3.9/site-packages/pyShelly/init.py", line 359, in update_block block.update_coap(data, ipaddr) File "/usr/local/lib/python3.9/site-packages/pyShelly/block.py", line 105, in update_coap dev.raise_updated() File "/usr/local/lib/python3.9/site-packages/pyShelly/base.py", line 46, in raise_updated callback(self) File "/config/custom_components/shelly/device.py", line 58, in _updated self._update_ha_state() File "/config/custom_components/shelly/device.py", line 51, in _update_ha_state self.schedule_update_ha_state(True) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 643, in schedule_update_ha_state self.hass.add_job(self.async_update_ha_state(force_refresh)) # type: ignore AttributeError: 'NoneType' object has no attribute 'add_job'

hakana commented 2 years ago

Check if you can find the first error from ShellyForHass. You can restart HA and then look for the error. The error you post just saying it was another error before.

pbix commented 2 years ago

I see this in the log prior which might be related. I am not using MQTT so why do I have to enter the MQTT port on the first config page? I am forced to enter so I put the default 1883 there. Then later in the config flow I am requested to enter the MQTT server address and since I have none I entered "0". On that same config page the MQTT port again appears so this is also confusing. How should one complete these fields when not using MQTT?

2021-12-15 21:52:37 INFO (MainThread) [pyShelly] Init 0.3.4 2021-12-15 21:52:37 INFO (MainThread) [custom_components.shelly] pyShelly, 0.3.4 2021-12-15 21:52:37 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/config/custom_components/shelly/init.py", line 330, in start_up pys.start() File "/usr/local/lib/python3.9/site-packages/pyShelly/init.py", line 185, in start self._mqtt_server.start() File "/usr/local/lib/python3.9/site-packages/pyShelly/mqtt_server.py", line 123, in start self._init_socket() File "/usr/local/lib/python3.9/site-packages/pyShelly/mqtt_server.py", line 129, in _init_socket sock.bind((self._root.bind_ip, self._root.mqtt_port)) OSError: [Errno 98] Address in use

image

image

pbix commented 2 years ago

Also these warnings are in the log. I am using HA 2021.12.2 at the moment.

2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity switch.shelly_shuni_1_98cdac251fd1_1 (<class 'custom_components.shelly.switch.ShellySwitch'>) implements device_state_attributes. Please report it to the custom component author. 2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity binary_sensor.shelly_shuni_1_98cdac251fd1_1_switch (<class 'custom_components.shelly.binary_sensor.ShellySwitch'>) implements device_state_attributes. Please report it to the custom component author. 2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.shelly_shuni_1_98cdac251fd1_voltage (<class 'custom_components.shelly.sensor.ShellySensor'>) implements device_state_attributes. Please report it to the custom component author. 2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity switch.shelly_shuni_1_98cdac251fd1_2 (<class 'custom_components.shelly.switch.ShellySwitch'>) implements device_state_attributes. Please report it to the custom component author. 2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity binary_sensor.shelly_shuni_1_98cdac251fd1_2_switch (<class 'custom_components.shelly.binary_sensor.ShellySwitch'>) implements device_state_attributes. Please report it to the custom component author. 2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.shelly_shuni_1_98cdac251fd1_1_temperature (<class 'custom_components.shelly.sensor.ShellySensor'>) implements device_state_attributes. Please report it to the custom component author. 2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.shelly_shuni_1_98cdac251fd1_2_temperature (<class 'custom_components.shelly.sensor.ShellySensor'>) implements device_state_attributes. Please report it to the custom component author.

hakana commented 2 years ago

mqtt_port)) OSError: [Errno 98] A

Just set it to 0 to disable the internal MQTT server. Ju probably have another service on that port or running 2 instances of ShellyForHass.

hakana commented 2 years ago

Also these warnings are in the log. I am using HA 2021.12.2 at the moment.

2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity switch.shelly_shuni_1_98cdac251fd1_1 (<class 'custom_components.shelly.switch.ShellySwitch'>) implements device_state_attributes. Please report it to the custom component author. 2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity binary_sensor.shelly_shuni_1_98cdac251fd1_1_switch (<class 'custom_components.shelly.binary_sensor.ShellySwitch'>) implements device_state_attributes. Please report it to the custom component author. 2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.shelly_shuni_1_98cdac251fd1_voltage (<class 'custom_components.shelly.sensor.ShellySensor'>) implements device_state_attributes. Please report it to the custom component author. 2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity switch.shelly_shuni_1_98cdac251fd1_2 (<class 'custom_components.shelly.switch.ShellySwitch'>) implements device_state_attributes. Please report it to the custom component author. 2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity binary_sensor.shelly_shuni_1_98cdac251fd1_2_switch (<class 'custom_components.shelly.binary_sensor.ShellySwitch'>) implements device_state_attributes. Please report it to the custom component author. 2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.shelly_shuni_1_98cdac251fd1_1_temperature (<class 'custom_components.shelly.sensor.ShellySensor'>) implements device_state_attributes. Please report it to the custom component author. 2021-12-15 21:52:51 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.shelly_shuni_1_98cdac251fd1_2_temperature (<class 'custom_components.shelly.sensor.ShellySensor'>) implements device_state_attributes. Please report it to the custom component author.

Fixed in 0.3.3

pbix commented 2 years ago

I set zero as the MQTT port on both configuration screens. I had to return to the config flow after initialization as I was not permitted to set zero on the first screen for MQTT in the beginning. With this done my 1 PM device started working again after restart and many of the log messaged disappeared.

To what "Internal MQTT server" do you refer. Does this integration have an internal MQTT server? I suppose you mean set zero to disable communications with any MQTT server?

Great integration BTW. Thanks for doing it.

hakana commented 2 years ago

Yes, it has a light internal MQTT server that you can use with Shelly Devices. It is an easy way to set up MQTT without installing an MQTT broker etc. Just config the Shelly Device with the IP and port specified in the plugin and you are ready to go.