Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Switchbot Blind Tilt #86591

Merged
merged 10 commits into from
Feb 17, 2023
Merged

Implement Switchbot Blind Tilt #86591

merged 10 commits into from
Feb 17, 2023

Conversation

jesserockz
Copy link
Member

@jesserockz jesserockz commented Jan 25, 2023

Proposed change

Add support for SwitchBot Blind Tilt

Library changelog: sblibs/pySwitchbot@0.36.4...0.37.1

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @bdraco, @Danielhiversen, @RenierM26, @murtas, @Eloston, @dsypniewski, mind taking a look at this pull request as it has been labeled with an integration (switchbot) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of switchbot can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign switchbot Removes the current integration label and assignees on the issue, add the integration domain after the command.

@jesserockz jesserockz marked this pull request as ready for review January 25, 2023 23:02
@jeremywgleeson
Copy link

I tested locally and it seems like the state is staying unknown (at least for me, 3x devices all show this behavior). Debug logs show nothing useful for debugging this issue.
blind_tilt_not_updating

Additionally, it's causing this error with google assistant integration (possibly related to state showing unavailable): (#43178)

Unexpected error serializing query for <state cover.kitchen_blinds=unknown; current_tilt_position=15, last_run_success=True, device_class=curtain, friendly_name=Kitchen Blinds, supported_features=CoverEntityFeature.SET_TILT_POSITION|STOP_TILT|CLOSE_TILT|OPEN_TILT @ 2023-01-27T18:27:24.252241-08:00>
Unexpected error serializing query for <state cover.office_blinds=unknown; current_tilt_position=0, last_run_success=True, device_class=curtain, friendly_name=Office Blinds, supported_features=CoverEntityFeature.SET_TILT_POSITION|STOP_TILT|CLOSE_TILT|OPEN_TILT @ 2023-01-27T18:27:24.252124-08:00>
Unexpected error serializing query for <state cover.bedroom_blinds=unknown; current_tilt_position=0, last_run_success=True, device_class=curtain, friendly_name=Bedroom Blinds, supported_features=CoverEntityFeature.SET_TILT_POSITION|STOP_TILT|CLOSE_TILT|OPEN_TILT @ 2023-01-27T18:27:24.252353-08:00>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/smart_home.py", line 149, in async_devices_query_response
    devices[devid] = entity.query_serialize()
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/helpers.py", line 676, in query_serialize
    deep_update(attrs, trt.query_attributes())
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/trait.py", line 1919, in query_attributes
    raise SmartHomeError(
homeassistant.components.google_assistant.error.SmartHomeError: Querying state is not supported

@bdraco
Copy link
Member

bdraco commented Jan 28, 2023

I ordered a set of these to test with. Will test this PR when they show up

@bdraco bdraco self-requested a review January 28, 2023 03:41
@ljmerza
Copy link
Contributor

ljmerza commented Jan 30, 2023

I pulled this branch and can confirm everything works great so far

@BelowAverageDev
Copy link
Contributor

BelowAverageDev commented Jan 31, 2023

The way the blinds operate with 50%=open conflicts with the way covers are expected to behave. For example, when exposed to google home, it assumes the blinds are at 100% when open, but they are actually at tilt=50. Because of this, opening to 99% will result in the blinds closing up to tilt=99, but opening to 100% results in an open call setting tilt=50.

This can be worked around by creating a cover template and adding some math to scale and offset tilt values in service calls. However, this has to be done in yaml, and it can be daunting for those without any experience writing HA yaml/programming to do this (without a step-by-step guide). Owners can decide if this is acceptable.

Another option would be implementing a close_direction=up|down|both option to modify behavior (I personally dislike the following, but maybe there's a more friendly way to implement this idea):

  1. Full control (_close_direction=both)
    current implementation
  2. Simple (_close_direction=up|down)
    Scale and offset position calls to fall into restricted range ([0, 50] or [50, 100])
    ex: user chooses _close_direction=down. Set position call to 50% is scaled to fall into range [0,50] and set tilt=25

Example cover template (close down):

example_blinds:
  device_class: blind
  friendly_name: Example Blinds (Simple Down)
  open_cover:
    service: cover.set_cover_tilt_position
    data:
      tilt_position: 50
    target:
      entity_id: cover.example_blinds
  close_cover:
    service: cover.set_cover_tilt_position
    data:
      tilt_position: 0
    target:
      entity_id: cover.example_blinds
  position_template: >
    {{ int(states.cover.example_blinds.attributes.current_tilt_position)*2 }}
  set_cover_position:
    service: cover.set_cover_tilt_position
    data:
      tilt_position: "{{position/2}}"
    target:
      entity_id: cover.example_blinds

BelowAverageDev and others added 2 commits January 31, 2023 14:17
@bdraco
Copy link
Member

bdraco commented Feb 4, 2023

Device showed up. Did some very basic testing. All good 👍

@ljmerza
Copy link
Contributor

ljmerza commented Feb 7, 2023

@Danielhiversen

@bdraco
Copy link
Member

bdraco commented Feb 7, 2023

Please don’t ping asking for reviews

Danielhiversen

@home-assistant home-assistant locked as off-topic and limited conversation to collaborators Feb 7, 2023
@home-assistant home-assistant unlocked this conversation Feb 17, 2023
@bdraco bdraco merged commit a26d41f into dev Feb 17, 2023
@bdraco bdraco deleted the jesserockz-2023-027 branch February 17, 2023 03:06
AlePerla pushed a commit to AlePerla/homeassistant_core that referenced this pull request Feb 17, 2023
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: BelowAverageDeveloper <90269575+BelowAverageDev@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Feb 18, 2023
@frenck frenck added the noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) label Feb 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed integration: switchbot noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) Quality Scale: No score
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants