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
72.36k stars 30.29k forks source link

BOND fan control errors #38218

Closed tetragram55 closed 4 years ago

tetragram55 commented 4 years ago

The problem

The BOND fan integration is generating errors when I try to turn fans on/off. I am using fans with on/off toggle control and speed increase / speed decrease remotes. Also the fan speed increase/decrease control did not transfer over from the BOND application. In the Bond app I have a fan power toggle button and a fan speed increase and fan decrease button, but these did not show up in the HA bond integration for these fans.

Environment

I am using Home Assistant 0.113.1

Problem-relevant configuration.yaml

Traceback/Error logs

Logger: homeassistant.core Source: components/bond/fan.py:79 First occurred: 6:44:23 PM (7 occurrences) Last logged: 6:57:40 PM

Error executing service: <ServiceCall fan.turn_on (c:02e523d448524fcfb8534672640c34f2): entity_id=['fan.fan']> Error executing service: <ServiceCall fan.turn_on (c:20c6aa9fbc36416b93fee2a3a431ef84): entity_id=['fan.fan']> Error executing service: <ServiceCall fan.turn_on (c:8b1e973328f449c7a90c27556113f122): entity_id=['fan.fan']> Error executing service: <ServiceCall fan.turn_on (c:83817aca048048d59fee44e5a2083edf): entity_id=['fan.fan']> Error executing service: <ServiceCall fan.turn_on (c:57b542fa44f1434f8005b0e211b64989): entity_id=['fan.fan']> Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/core.py", line 1281, in catch_exceptions await coro_or_task File "/usr/src/homeassistant/homeassistant/core.py", line 1300, in _execute_service await handler.func(service_call) File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 208, in handle_service await self.hass.helpers.service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 471, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 277, in async_update_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 314, in _async_write_ha_state sstate = self.state File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 607, in state return STATE_ON if self.is_on else STATE_OFF File "/usr/src/homeassistant/homeassistant/components/fan/init.py", line 146, in is_on return self.speed not in [SPEED_OFF, None] File "/usr/src/homeassistant/homeassistant/components/bond/fan.py", line 79, in speed return self.speed_list[ha_speed] IndexError: list index out of range

Additional information

Thanks in advance for your help.

marciogranzotto commented 4 years ago

This seems to happen if a Bond only commands with actions IncreaseSpeed and DecreaseSpeed, but not SetSpeed. For this to work properly, HA would need to support +speed and -speed instead of a stateful speed list. @prystupa any ideas?

marciogranzotto commented 4 years ago

Maybe we should do the same that is implemented on the custom component. Only make speed available if max_speed exists in the properties: https://github.com/nguyer/homeassistant-bond-home/blob/master/custom_components/bond/fan.py#L52

prystupa commented 4 years ago

@tetragram55 just to narrow down the problem... Are you seeing the errors in logs, even though the fan turns on and off correctly using HA turn on/turn off controls? Or the fan does not respond to on/off controls?

Also, @terminet85 @marciogranzotto Is one of you able to pull the state from the fan using HTTP? I am curious what the value of "speed" is in the Bond's state when the error occurs. Something like: http://your_bond_ip/v2/devices/your_fan_device_id/state

tetragram55 commented 4 years ago

@prystupa The fan will turn on with an error generated. The off command works with no error. If I just toggle the off button it operates the fan on and off with no errors.

marciogranzotto commented 4 years ago

So, here's a useful tool for debugging the local API: http://bond-react-js.s3.amazonaws.com/index.html (@prystupa I think that will help you as well)

It connects locally to your bond, so you need to be on the same network. You can turn on Live so it updates whenever you do something on the app. @tetragram55 if you can, please send a screenshot of your device's state and properties so we can try to figure this out.

I tried to create a raw-recorded fan with Increase/Decrease Speed, but the behavior I'm seeing is no max_speed and speed always 0:

image

What I think could be happening there is the speed state returning a number greater than 3, which is the fallback for max_speed in the component

tetragram55 commented 4 years ago

@marciogranzotto , I will do that after work and put up the results.

prystupa commented 4 years ago

@marciogranzotto thanks for state log. Unfortunately, speed == 0 is not going to cause the IndexError here:

ha_speed = math.ceil(self._speed * (len(self.speed_list) - 1) / max_speed)
return self.speed_list[ha_speed]

This would return 0-th speed, which is Off. I will wait for @tetragram55 to get the state from real device before I can do an educated fix.

tetragram55 commented 4 years ago

@marciogranzotto I am unable to get the debugging tool to work. I have tried on different PC's but it just won't connect with the debug tool. I can connect with HTTP commands and via the web interface so my connection is good, there's just something with the the tool that isn't working for me. Any suggestions?

prystupa commented 4 years ago

@tetragram55 if you are comfortable with HTTP commands, would you be able to pull the state from your fan with GET like this: http://your_bond_ip/v2/devices/your_fan_device_id/state using Postman or similar? You need to configure the following header for requests:

BOND-Token: "your_token"

Alternatively, if you can run HA locally from dev branch, I added logging that will dump device state on debug level. You need to enable bond debug level like this in the configuration.yaml:

logger:
  default: info
  logs:
    homeassistant.components.bond: debug
terminet85 commented 4 years ago

@prystupa maybe a mistake 'cause I'm not involved to this, sorry.

prystupa commented 4 years ago

@prystupa maybe a mistake 'cause I'm not involved to this, sorry.

Sorry, meant to mention @tetragram55

marciogranzotto commented 4 years ago

@tetragram55 oh sorry, looks like an FW change that is necessary to use that tool is not yet on the release version, only in beta. That change is support to CORS, which is basically adding a header to all requests.

You can do manual HTTP communication or use the tool opening chrome with this commands, that turns off the CORS requirement:

open -n -a "Google Chrome" --args --user-data-dir=/tmp/temp_chrome_user_data_dir --disable-web-security 
tetragram55 commented 4 years ago

@marciogranzotto I will give it a try again tonight, thanks for the help.

tetragram55 commented 4 years ago

@marciogranzotto Here is the screen shot of the bond. Let me know what else I can do to help. image

marciogranzotto commented 4 years ago

That speed 14 is definitely the problem! But I think that the bond should not allow that... I'll investigate that, but what you can do now is use Decrease Speed 14 times so speed gets back to 0, then it should probably work with the integration

prystupa commented 4 years ago

@tetragram55 https://github.com/home-assistant/core/pull/38382 should fix exceptions in the log. As for increase/decrease controls not transferring to HA - I don't think HA has this concept for fans, I don't think this can be done.

tetragram55 commented 4 years ago

The fan will now turn off and on with no errors. The speed control is sending errors.(See below) when I use the call service to change the fan speed. Maybe it is because my fan has speed increase and decrease instead of a 3 speed option?

Log Details (ERROR) Logger: homeassistant.components.websocket_api.http.connection.139950326709936 Source: components/bond/fan.py:113 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 7:18:47 PM (6 occurrences) Last logged: 7:22:05 PM

b'{"_error_id":7,"_error_msg":"bad argument"}\r\n' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 125, in handle_call_service await hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 1265, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1300, in _execute_service await handler.func(service_call) File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 208, in handle_service await self.hass.helpers.service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 454, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 595, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 485, in _handle_entity_call await result File "/usr/src/homeassistant/homeassistant/components/fan/init.py", line 113, in async_set_speed await self.hass.async_add_job(self.set_speed, speed) File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/components/bond/fan.py", line 113, in set_speed self._hub.bond.setSpeed(self._device.device_id, speed=bond_speed) File "/usr/local/lib/python3.8/site-packages/bond/bond.py", line 45, in setSpeed return self.doAction(deviceId, File "/usr/local/lib/python3.8/site-packages/bond/bond.py", line 121, in doAction raise Exception(r.content) Exception: b'{"_error_id":7,"_error_msg":"bad argument"}\r\n'

tetragram55 commented 4 years ago

@prystupa @marciogranzotto Thanks for your help. I can turn fans off and on without errors. As for the speed increase/decrease I can only hope this will one day work. :-)

prystupa commented 4 years ago

@tetragram55 did you manually apply my patch to your existing HA installation? From the logs I do see that it is calling old bond library. dev branch using a different one now.

If you can run dev branch locally test against it when PR is merged?

tetragram55 commented 4 years ago

@prystupa no I did not. Can you point me in the direction of a tutorial on how to do that?

prystupa commented 4 years ago

@prystupa no I did not. Can you point me in the direction of a tutorial on how to do that?

Yes, take a look here: https://developers.home-assistant.io/docs/development_environment I run my development instance on Mac directly, but there is also a Docker option (which didn't work for me as I could not configure shared network between docker and my home devices).

jayceegee87 commented 2 months ago

Apologies if I'm not meant to reopen this, however I appear to be experiencing similar issues. I have a vornado fan (named "Low Profile Fan" that is set up in Bond with the following three commands: toggle on/off, increase speed, and decrease speed.

I've observed the following behaviors: -Home assistant always shows fan state as off -In the entity view, home assistant only provides the following options: Off, Low, Medium, and High -Selecting Off, Low, or Medium turns the fan off. Selecting "High" one time lowers the fan speed. Selecting high a second time turns the fan off. -In the dashboard view, status always shows as off. Selecting "on" (the lightning icon) when fan is running turns fan off. Selecting on when fan is off turns fan on, however state in home assistant immediately changes to off even though the fan continues to run.

I attempted to use the bond local api log, and could not connect. Here is my debug log from home assistant: { "home_assistant": { "installation_type": "Home Assistant OS", "version": "2024.7.3", "dev": false, "hassio": true, "virtualenv": false, "python_version": "3.12.4", "docker": true, "arch": "aarch64", "timezone": "America/Phoenix", "os_name": "Linux", "os_version": "6.6.33-haos", "supervisor": "2024.06.2", "host_os": "Home Assistant OS 12.4", "docker_version": "26.1.4", "chassis": "embedded", "run_as_root": true }, "custom_components": { "hacs": { "documentation": "https://hacs.xyz/docs/configuration/start", "version": "1.34.0", "requirements": [ "aiogithubapi>=22.10.1" ] } }, "integration_manifest": { "domain": "bond", "name": "Bond", "codeowners": [ "bdraco", "prystupa", "joshs85", "marciogranzotto" ], "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/bond", "iot_class": "local_push", "loggers": [ "bond_async" ], "quality_scale": "platinum", "requirements": [ "bond-async==0.2.1" ], "zeroconf": [ "_bond._tcp.local." ], "is_built_in": true }, "setup_times": { "null": { "setup": 8.54589743539691e-05 }, "01J34E3ARAEZ1C4BM4ZBTPW3EY": { "wait_import_platforms": -11.49190428305883, "config_entry_setup": 13.037359055015258 } }, "data": { "entry": { "title": "Bond Bridge", "data": { "access_token": "REDACTED", "host": "192.168.12.134" } }, "hub": { "version": { "target": "zermatt", "fw_ver": "v3.21.3.6", "fw_date": "Thu Feb 15 14:49:15 UTC 2024", "uptime_s": 1220773, "boot_patch": "not first boot", "make": "Olibra", "model": "BD-1000", "branding_profile": "OLIBRA_BD1000", "bondid": "ZZGK21796", "upgradehttp": true, "api": 2, "": "50a0f86c", "": "50a0f86c" } }, "devices": [ { "device_id": "f84e179f4ca50c06", "props": { "truststate": false, "": "d4e2fa5b", "_": "d4e2fa5b" }, "attrs": { **"name": "Low Profile Fan",** "type": "CF", "location": "Living Room", "actions": [ "DecreaseSpeed", "IncreaseSpeed", "SetSpeed", "Stop", "TogglePower", "TurnOff", "TurnOn" ], "": "3e1086d0", "": "5cea695b", "commands": { "": "70ee2c3d" }, "state": { "": "dc83e7fb" }, "properties": { "": "d4e2fa5b" }, "skeds": { "": "00000000" } }, "supported_actions": [ "DecreaseSpeed", "SetSpeed", "IncreaseSpeed", "TurnOn", "TurnOff", "Stop", "TogglePower" ] }, { "device_id": "17df9cc1d0f1052d", "props": { "max_speed": 6, "truststate": false, "": "9be84ea4", "": "9be84ea4" }, "attrs": { "name": "South Ceiling Fan", "type": "CF", "location": "Entryway", "actions": [ "DecreaseSpeed", "IncreaseSpeed", "SetDirection", "SetSpeed", "Stop", "ToggleDirection", "TogglePower", "TurnOff", "TurnOn" ], "_": "cf3dc00f", "_": "da701aed", "commands": { "": "9739b902" }, "state": { "": "b4f2371e" }, "properties": { "": "9be84ea4" }, "skeds": { "_": "00000000" } }, "supported_actions": [ "DecreaseSpeed", "SetSpeed", "IncreaseSpeed", "TurnOn", "ToggleDirection", "Stop", "TurnOff", "SetDirection", "TogglePower" ] }, { "device_id": "8e8af3c86ea45459", "props": { "max_speed": 6, "truststate": false, "": "9be84ea4", "": "9be84ea4" }, "attrs": { "name": "North Ceiling Fan", "type": "CF", "location": "Office", "actions": [ "DecreaseSpeed", "IncreaseSpeed", "SetDirection", "SetSpeed", "SetTimer", "Stop", "ToggleDirection", "TogglePower", "TurnOff", "TurnOn" ], "_": "a111f219", "_": "39d953c3", "commands": { "": "d3c75b08" }, "state": { "": "5482203f" }, "properties": { "": "9be84ea4" }, "skeds": { "_": "00000000" } }, "supported_actions": [ "SetTimer", "DecreaseSpeed", "SetSpeed", "IncreaseSpeed", "TurnOn", "ToggleDirection", "Stop", "TurnOff", "SetDirection", "TogglePower" ] } ] } }