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

Support toggle climate device #573

Closed
eyalcha opened this issue Jan 28, 2021 · 35 comments
Closed

Support toggle climate device #573

eyalcha opened this issue Jan 28, 2021 · 35 comments
Labels
enhancement New feature or request

Comments

@eyalcha
Copy link

eyalcha commented Jan 28, 2021

HI,

Not sure if there is already support /solution for my case, but I didn't find ...

I have an aircondition device which doesn't have sepearte on / off commands. No issue to turn off the device. I have off command in the code file. The issue is with the turn on command. To turn on I actually need to send two commands. First to turn on and then send second command (mode temperature fan). Note that all the temperature commands cannt include the on command because if they wer, each up down temperature will toggle device power state.

The solution that I found was to add a pre mode command and send it each time the mode is changed (mode depended). Is there other option to handle this case without changing teh code? If not, is it possible to add support for that?

async def async_set_hvac_mode(self, hvac_mode):
      """Set operation mode."""
      _LOGGER.debug(f"async_set_hvac_mode hvac_mode:{hvac_mode}")
      self._hvac_mode = hvac_mode
      
      if not hvac_mode == HVAC_MODE_OFF:
          self._last_on_operation = hvac_mode

      # Pre mode command
      if not hvac_mode == HVAC_MODE_OFF:
          pre_mode = f"pre_{hvac_mode}"
          _LOGGER.debug(f"Send {pre_mode}")
          if pre_mode in self._commands:
              await self._controller.send(self._commands[pre_mode])
              await asyncio.sleep(self._delay)

      await self.send_command()
      await self.async_update_ha_state()

Example of command:

  "commands":{
    "off":"JgC+AGKCICFBPiEfQR8hHx8hIR8fISFAHiEgIB8gPyEfIR8hIh8hHx4hIh8eIR8hHyEfIR8hISAeICIfIR8gP0EfY4IeIT9AICA/ISIfHiEfISIfIT8eIR8hHyE/ICAgHyEiHx4hIh8eIR8hHyEhHx8hHyEfIR8hIR8eIR9BQh9jgR4hP0EfIT8gHyEiHyEfIR8eQSEfHyEfIUEgICAgICAfIR8iHR8hHyEfIR8hIh8eISEgICAeIR8hID9BH4IADQUAAAAAAAAAAAA=",
    "pre_heat":"JgC+AGKCICFBPiEfQR8hHx8hIR8fISFAHiEgIB8gPyEfIR8hIh8hHx4hIh8eIR8hHyEfIR8hISAeICIfIR8gP0EfY4IeIT9AICA/ISIfHiEfISIfIT8eIR8hHyE/ICAgHyEiHx4hIh8eIR8hHyEhHx8hHyEfIR8hIR8eIR9BQh9jgR4hP0EfIT8gHyEiHyEfIR8eQSEfHyEfIUEgICAgICAfIR8iHR8hHyEfIR8hIh8eISEgICAeIR8hID9BH4IADQUAAAAAAAAAAAA=",
    "cool":{
      "auto":{
        "16":"JgDEAGVhISAhHiI+Ih4iHkEeIx0jHiEeIh4iHyEeIT9BICAhHyAhHiEfIR4hHyIeIh4iHiIeIR8hICAgICAfICE/QR9jYCIfICAhPiIeIR9BHiMdIh8hHiIeISAhHiE/QSAhHiEfIh0iHiIfISAgHiEgIR4hHyIeIh4iHiIeIR8hPkIeZGAhICAgID8hHyEfQh0iHiEgIR4iHyEeIR8hQEEeIR8hHiIfIR4iHiIfIR4iHyEeISAhHiIeIh0iHyEfIT5BIYEADQUAAAA=",
@smartHomeHub
Copy link
Collaborator

Yes, just rename the pre_heat key to on

@eyalcha
Copy link
Author

eyalcha commented Jan 28, 2021

Yes, just rename the pre_heat key to on

I saw the "on" option, but as I understand, it will called each time send command is called, so when I just change temperature, the on command will be sent and the aircondition will toggle state ...

    async def send_command(self):
        async with self._temp_lock:
            try:
                self._on_by_remote = False
                operation_mode = self._hvac_mode
                fan_mode = self._current_fan_mode
                swing_mode = self._current_swing_mode
                target_temperature = '{0:g}'.format(self._target_temperature)

                if operation_mode.lower() == HVAC_MODE_OFF:
                    await self._controller.send(self._commands['off'])
                    return

                if 'on' in self._commands:
                    await self._controller.send(self._commands['on'])
                    await asyncio.sleep(self._delay)

@vassilis-panos
Copy link
Member

No, there is no way.

@eyalcha
Copy link
Author

eyalcha commented Jan 28, 2021

No, there is no way.

@vassilis-panos The code I've attached (Pre mode command) handle this case. Maybe there is a bteer way to add it to the official release.

@vassilis-panos
Copy link
Member

Is there a reason why you need a different pre-code for each mode?

@eyalcha
Copy link
Author

eyalcha commented Jan 29, 2021

@vassilis-panos

I assume single pre command (which should turn on the device) is enough but if the pre command sends also the HVAC mode, it will be better to send the correct mode and not to rely on the immediate second command to set the mode correctly.

@vassilis-panos vassilis-panos added the enhancement New feature or request label Feb 2, 2021
@SamTheGeek
Copy link

I also have this issue — I use a Fujitsu AR-REG1U-controlled heat pump (code 1284 in SmartIR). Once the device is powered off, it cannot be powered on from Home Assistant. However, the Broadlink App can send a power-on command by itself.

Perhaps the power-on command could be sent when toggling mode if the state is currently set to off?

@mshuflin
Copy link

I have the same issue with my Daikin FTN-P. It seems like it needs home assistant to send the power on command (along with the temperature or mode command) only when the state is off, otherwise, send only the temperature or mode.

@mshuflin
Copy link

mshuflin commented Mar 30, 2021

@eyalcha your solution worked for me. I know that it is not the case for everyone, but, @vassilis-panos, perhaps it could be implemented as a configurable option?

async def async_set_hvac_mode(self, hvac_mode):
      """Set operation mode."""
      _LOGGER.debug(f"async_set_hvac_mode hvac_mode:{hvac_mode}")
      self._hvac_mode = hvac_mode
      
      if not hvac_mode == HVAC_MODE_OFF:
          self._last_on_operation = hvac_mode

      # Pre mode command
      if not hvac_mode == HVAC_MODE_OFF:
          pre_mode = f"pre_{hvac_mode}"
          _LOGGER.debug(f"Send {pre_mode}")
          if pre_mode in self._commands:
              await self._controller.send(self._commands[pre_mode])
              await asyncio.sleep(self._delay)

      await self.send_command()
      await self.async_update_ha_state()

@stale
Copy link

stale bot commented Jun 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 2, 2021
@mshuflin
Copy link

mshuflin commented Jun 2, 2021

Still valid

@Spirituss
Copy link

Hello,
I have similar issue. When I send command 'off' in case Panasonic was off, it turns in on. Nevertheless, SmatrIR has power on sensor. Why does it send the command while power sensor has 'off' status?

@jpf4e
Copy link

jpf4e commented Jul 20, 2021

I also have a similar issue with my Hisense AC.
Smart IR should detect the state change from "off" to any other state and run the on command before the new state's command.

@jpf4e
Copy link

jpf4e commented Jul 20, 2021

Something like this fixes it for my Hisense AC:

async def async_set_hvac_mode(self, hvac_mode):
      """Set operation mode."""
      _LOGGER.debug(f"async_set_hvac_mode hvac_mode:{hvac_mode}")

      if not hvac_mode == HVAC_MODE_OFF:
          self._last_on_operation = hvac_mode

      # Pre mode command
      if not hvac_mode == HVAC_MODE_OFF and self._hvac_mode == HVAC_MODE_OFF:
          pre_mode = f"pre_{hvac_mode}"
          _LOGGER.debug(f"Send {pre_mode}")
          if pre_mode in self._commands:
              await self._controller.send(self._commands[pre_mode])
              await asyncio.sleep(self._delay)

      self._hvac_mode = hvac_mode

      await self.send_command()
      await self.async_update_ha_state()

@Spirituss
Copy link

Something like this fixes it for my Hisense AC:

Due to incorrect work of SmartIR at the moment I have to realise the same logic via HA script. I appreciate such fixes into the component.

@stephenchew
Copy link

stephenchew commented Jul 22, 2021

Yeah I have a similar issue where my air-conditioner has no idempotent on/off button, the state is kept in the unit itself instead. It's a newer model of Daikin anyway.

Similar to a TV remote, the power button on the remote will send a "power" signal, and it toggles the air-conditioner on/off based on the previous state (stored in the unit).

Inspired by @eyalcha modification above, I made the necessary modification which fits my unit:

def __init__(self, hass, config, device_data):
    # initialisation of other variables...
    # ...
    self._previous_hvac_mode = HVACMode.OFF

async def async_set_hvac_mode(self, hvac_mode):
    """Set operation mode."""
    self._previous_hvac_mode = self._hvac_mode
    self._hvac_mode = hvac_mode
    
    if not hvac_mode == HVACMode.OFF:
        self._last_on_operation = hvac_mode

    # Pre mode command
    # Taken from https://github.com/smartHomeHub/SmartIR/issues/573
    # modified to a generic `on_once` for all non-off operation
    if hvac_mode != HVACMode.OFF:  # don't run if about to turn off
        if self._previous_hvac_mode == HVACMode.OFF:  # only if it's previously off
            if 'on_once' in self._commands:
                await self._controller.send(self._commands['on_once'])
                await asyncio.sleep(self._delay)

    # End pre mode

    await self.send_command()
    self.async_write_ha_state()

Add the attribute on_once in the config file

"commands": {
  "off": "JgCWAAABQwABQgABRAABQ5lRDQsOHQ4dDQwNHQ4LDAwNCwwMDh0NCw0LDgsNHgwMDQsMDA4KDgoNDA0eDR4MDA0LDCALDA0LDQsOCw0dDQwNCwwMDQsOCg0LDh0OCwwMDQsMDA0LDgoNDA0eDQsMDA0eDQsMHwwfDAwOCg4dDQsNDAwfDQsNHgwfDQsNCw0LDgsNAAKcmQANBQ==",
  "on_once": "JgCWAAABQwABQgABRAABQ5lRDQsOHQ4dDQwNHQ4LDAwNCwwMDh0NCw0LDgsNHgwMDQsMDA4KDgoNDA0eDR4MDA0LDCALDA0LDQsOCw0dDQwNCwwMDQsOCg0LDh0OCwwMDQsMDA0LDgoNDA0eDQsMDA0eDQsMHwwfDAwOCg4dDQsNDAwfDQsNHgwfDQsNCw0LDgsNAAKcmQANBQ==",
  "cool": {
    "low": {
      "16": "JgCWAAABQwABQgABRQABQZpRDA0LHw0eDA0MHwwMDAwMDAsOCx8NDAsNCw0MDAwMDB8MDAwfDR4MDQsNCw0MHg0MDB4NDAwMDA0LDQsgCwwNDAwMDAwMDAwNCyALDQsNCw0LDQwMDA0LDA0eDA0MDAweDQwMHg4dDQwMHw0MCw0LDQsfDQwMHg0MDAwMDQsfDQwLAAKdmQANBQ==",

** Things to take note: on_once command is effectively the 'power' command, which toggle the power state of the appliance.

How it behaves:

Scenario 1
GIVEN current state is Off
WHEN changing HVAC mode to either cooling, heating or fan
THEN it'll fire the on_once command to turn on the appliance before sending the respective command

Scenario 2
GIVEN current state is not off (e.g. cooling, heating or fan)
WHEN changing HVAC mode to either cooling, heating or fan
THEN it will only fire the respective command without triggering the on_once command

Scenario 3
GIVEN current state is not off (e.g. cooling, heating or fan)
WHEN changing HVAC mode to off
THEN it will only fire off command to turn the appliance off

⚠️ Edge cases - The state of the appliance is out of sync with the remote

Scenario 4
GIVEN the remote shows that it's cooling but the appliance is actually off
WHEN pressing off button on the remote
THEN it should send off command to turn on the appliance (because off command is effectively a power command)
WHEN pressing off button for the second time
THEN it should send off command again to turn off the appliance
AND both the states are now in sync

Scenario 5
GIVEN the remote shows that it's off but the appliance is actually on (cooling, heating or fan)
WHEN pressing off button on the remote
THEN it should send off command to turn off the appliance
AND both the states are now in sync


To me this is quite a common design that most manufacturers employ when they make a remote, so I really wish this could be incorporated into SmartIR.

rossiluis22 referenced this issue in rossiluis22/SmartIR Aug 23, 2021
@stale
Copy link

stale bot commented Sep 3, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 3, 2021
@Spirituss
Copy link

The problem has not been solved yet. For example, Panasonic air conditioners work incorrectly because have the same command for both POWER ON and POWER OFF action.

@stale stale bot removed the stale label Sep 3, 2021
@mshuflin
Copy link

mshuflin commented Sep 3, 2021 via email

@Paul-Vdp
Copy link

So have I ...

@matteo-vannucchi
Copy link

I have the same problem with a pellet stove, which works perfectly with SmartIR except for the latter always sends on command with every mode change.
The on_once solution from @step-chew looks perfect for my case, too

@Dgomezj
Copy link

Dgomezj commented Feb 14, 2022

Hi, In the meantime this is not added to the official release, is there any way to include the code made by @step-chew in my local installation?

@matteo-vannucchi
Copy link

Hi, In the meantime this is not added to the official release, is there any way to include the code made by @step-chew in my local installation?

Hi, if you know how to, you should modify the file climate.py in the custom_compnents/smartir folder of your HA config, adding the lines from @step-chew's reply

@Dgomezj
Copy link

Dgomezj commented Feb 17, 2022

Thanks a lot @matteo-vannucchi. I've seen the file and I think is pretty easy to modify. I'll give it a try.

@Dgomezj
Copy link

Dgomezj commented Feb 21, 2022

I've added the code to my instalation and it works like a charm.
Thanks @step-chew for the code and thanks @matteo-vannucchi for the guidance.

It would be very nice to have this in the official release.

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2022
@mshuflin
Copy link

mshuflin commented Apr 16, 2022 via email

@stale
Copy link

stale bot commented Aug 13, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 13, 2022
@mshuflin
Copy link

mshuflin commented Aug 13, 2022 via email

@HVPereira
Copy link

I have this issue too!

@stale stale bot removed the stale label Jan 24, 2023
@madjetey
Copy link

@stephenchew's method isn't working with Daikin. Power on_once & Power off commands work but also give the error:

Failed to call service climate/set_hvac_mode. object NoneType can't be used in 'await' expression

Other commands don't work at all: temp, fan speed & swing

@Egglestron
Copy link

Egglestron commented Jan 5, 2025

Hi!
Why is the issue marked as resolved/closed? I have the same need for my Whirlpool PACW212CO and I don't see the aforementioned code merged yet, unless I'm mistaken.
Regards

@pabloromeo
Copy link

Still having this issue. Has this change been merged elsewhere?

@stephenchew
Copy link

stephenchew's method isn't working with Daikin. Power on_once & Power off commands work but also give the error:

Failed to call service climate/set_hvac_mode. object NoneType can't be used in 'await' expression

Other commands don't work at all: temp, fan speed & swing

Sorry @madjetey, I didn't upgrade my component, so I didn't know it breaks until recently. I've updated the code (in the original post). It's been tested it on my hass, and I'm using Daikin too 🙂

Still having this issue. Has this change been merged elsewhere?

@pabloromeo, I have a feeling that this will never be merged, and I'm not sure if there's some other workaround. Since this method works perfectly for me, I'm hanging onto this one for now.

@madjetey
Copy link

I don't recall which version changed this, but it's been working fine for over a year now for me. The last breaking change I had was the most recent update where I had to manually change line 148 in controller.py to 'payload': json.dumps(command) for MQTT commands.

Only issue now is all HVAC commands turn off the air conditioner unit self even when HA says it's on (EG: AC on & adjusting speed turns it off until I apply the speed change again). Same across MQTT & broadlink. Inverse is also true; an AC that is off will turn on if the off command is sent again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet