Skip to content

Fix for synchronizing fans #1549

Description

@mndti

Hi everyone,

I recently implemented the power_sensor for my fans, but I noticed they only worked/synchronized for the shutdown command. When manually turning them on or restarting Home Assistant with the fans running, they reverted to being off.

Since I couldn't find a solution, I decided to run some tests and realized it was only due to the line self._speed = None.

In my tests, everything worked OK, but more tests may be necessary, or someone might suggest if this is sufficient.

In the folder: /config/custom_components/smartir/fan.py
On line (300): self._speed = None
Change to: self._speed = self._last_on_speed

There's also a warning when restarting Home Assistant:
On line(295):

        if new_state.state == old_state.state:
            return

Change to:

        if old_state is not None and new_state.state == old_state.state:
            return

full code:

        if new_state is None:
            return

        if old_state is not None and new_state.state == old_state.state:
            return
            
        if new_state.state == STATE_ON and self._speed == SPEED_OFF:
            """_LOGGER.warning(f"fan on {self._last_on_speed}")"""
            self._on_by_remote = True
            self._speed = self._last_on_speed
            self.async_write_ha_state()

        if new_state.state == STATE_OFF:
            """_LOGGER.warning("fan off")"""
            self._on_by_remote = False
            if self._speed != SPEED_OFF:
                self._speed = SPEED_OFF
            self.async_write_ha_state()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions