oyvindwe / connectlife-ha

ConnectLife integration for Home Assistant
GNU General Public License v3.0
61 stars 23 forks source link

Adding support for water_heater / Heat Pump #44

Closed bartashevich closed 3 months ago

bartashevich commented 4 months ago

Hi, I have Hisense Heat Pump and I managed to integrate in Home assistant by adapting code from /bilan/connectlife-api-connector. And now I'm trying to setup permanently using your code.

The thing is, bilan code uses mqtt to create entities, in which I found water_heater https://www.home-assistant.io/integrations/water_heater.mqtt/

But, I'm not being able to set it up properly using your code. Here is my configuration file so far, based on https://developers.home-assistant.io/docs/core/entity/water-heater/

File: 016-502.yaml

device_type: water_heater
properties:
  - property: f_water_tank_temp
    water_heater:
      target: current_temperature
  - property: t_beep
    switch: {}
  - property: t_fan_speed
    switch: {}
  - property: t_sterilization
    switch: {}
  - property: t_vacation
    switch: {}
  - property: t_temp
    water_heater:
      target: target_temperature
      min_value:
        celsius: 20
        fahrenheit: 68
      max_value:
        celsius: 65
        fahrenheit: 149
  - property: t_temp_type
    water_heater:
      target: temperature_unit
      options:
        0: celsius
        1: fahrenheit
  - property: t_work_mode
    water_heater:
      target: operation_list
      options:
        8: eco
        9: heat_pump
        11: performance
        12: electric
  - property: t_power
    water_heater:
      target: is_on

Full API scrape:

[{"wifiId":"xxxxxxxxxxx","deviceId":"yyyyyyyyyyyyy","puid":"zzzzzzzzzzz","deviceNickName":"Heat\u00a0pump","deviceFeatureCode":"502","deviceFeatureName":"502\u81ea\u7814\u70ed\u6c34\u5668","deviceTypeCode":"016","deviceTypeName":"","bindTime":1693922922378,"role":1,"roomId":2716250,"roomName":"default_room","statusList":{"t_work_mode":"9","t_power":"1","t_temp":"35","f_backwater":"0","t_backwater_set":"0","t_vacation":"0","t_air":"0","t_fan_speed":"0","t_sterilization":"0","f_sterilization":"1","t_beep":"0","t_vacation_timeset":"1","t_vacation_timeleft":"0","f_electricity":"0","f_votage":"0","f_power_consumption":"0","f_electric_heating":"0","f_heat_pump":"1","f_water_tank_temp":"60","f_e_push":"0","f_e_displaycom_fault":"0","f_e_coiltemp":"0","f_e_env_temp":"0","f_e_exhaust":"0","f_e_suctiontemp_fault":"0","f_e_solar_temperature":"0","f_e_fan_fault":"0","f_e_upwatertank_fault":"0","f_e_downwatertank_fault":"0","f_e_e2data_fault":"0","f_e_drivecom_fault":"0","f_e_drive_fault":"0","f_e_returnwatertemp_fault":"0","f_e_clockchip_fault":"0","f_e_eanode_fault":"0","f_e_powermodule_fault":"0","oem_host_version":"S1798.6.01.06.RB","daily_energy_kwh":0},"useTime":0,"offlineState":1,"seq":0,"createTime":0}]

I end up only with switch entities working properly. But not water_heater entity is added. Any idea?

oyvindwe commented 4 months ago

But not water_heater entity is added. Any idea?

That entity type is not support yet. It is very similar to climate, so should be easy to add

bartashevich commented 4 months ago

Problem is that climate doesn't accept modes such as heat_pump, electric, performance:

  - property: t_work_mode
    water_heater:
      target: operation_list
      options:
        8: eco
        9: heat_pump
        11: performance
        12: electric
bartashevich commented 4 months ago

Ah, I understand now what you mean by not being supported. This addon doesn't have water_heater.py.

If I use climate.py as a template for water_heater.py, do you think that will be enough to make it work?

oyvindwe commented 4 months ago

Is the fan only on/off?

oyvindwe commented 4 months ago

If I use climate.py as a template for water_heater.py, do you think that will be enough to make it work?

I'm already working on it :)

oyvindwe commented 4 months ago

state is a bit tricky to map, as it cannot be mapped 1-1. We need a new top-level mapping that can map a target property to a set of device properties. I have a similar problem with climate.preset that I am working on.

For now I propose to just map t_power to state ~and t_eco to a separate switch~ [Edit: does not support t_eco]. But what is the "on" state for your heat pump? It must be one of the states here: https://developers.home-assistant.io/docs/core/entity/water-heater#states

oyvindwe commented 4 months ago

Also we can have self defined values for current_operation - or is this the correct mapping comparing with the ConnectLife app?

  - property: t_work_mode
    water_heater:
      target: current_operation
      options:
        8: eco
        9: heat_pump
        11: performance
        12: electric
oyvindwe commented 4 months ago

I have added support for water_heater in version 0.8.0, see PR #46.

I ended up mapping t_power to a switch, as enabling WaterHeaterEntityFeature.ON_OFF did not make any on/off switch turn up on the UI. This feature is not documented on https://developers.home-assistant.io/docs/core/entity/water-heater#states either. I also did not get _attr_state to work.

I have a feeling that the water heater entity needs some love and care in the core repo.

I would still like some feedback on the t_work_mode mapping. I added 0: "off" as an option as well.

bartashevich commented 3 months ago

Thanks for adding, I'll test it in a bit. I'll add more info about modes and fan:

Set modes: t_work_mode: 8 - AUTO, 9 - ECO, 11 - FAST, 12 - ELECTRICHEATING t_power: 0/1 t_air: 0/1 <- does the same as t_fan_speed t_fan_speed: 0/1 <- does the same as t_air ...

Read values: f_electric_heating: 0 - OFF/ECO/AUTO, 1 - ELECTRICHEATING/FAST f_heat_pump: 0 - OFF, 1 - ELECTRICHEATING, 2 - ECO/AUTO/FAST

About t_power, I think it works the same way as airconditioner.

Currently using Bilan addon with my custom changes I got to this: image

image

image

bartashevich commented 3 months ago

Thank you very much!

Just tested and all is working perfectly, except:

Is it possible to create metering entity to actually obtain consumed energy? Because the sensor that comes from API always stays at 0, even in the app.

From API when f_heat_pump = 2, it uses heat_pump and if f_electric_heating = 1 it uses electric heater, since I know that Heat pump uses 750W and electric heater 2050W, it seems possible to obtain cumulative value. FIY, it is possible f_heat_pump = 2 and f_electric_heating = 1, consuming total of 2800W.

Pictures: image image image image

oyvindwe commented 3 months ago

@bartashevich Thank you for your feedback! I will look into the off mode - that should be a quick fix (still only on/off)

From API when f_heat_pump = 2, it uses heat_pump and if f_electric_heating = 1 it uses electric heater

So mode should be mapped to multiple properties, similar to preset for ClimateEntity. This is work in progress, and will take a few days.

The WaterHeaterEntity puzzles me a bit though. I am not able to view state of mode in my HA (I am running against a test server that emulates the ConnectLife API).

Is it possible to create metering entity to actually obtain consumed energy? Because the sensor that comes from API always stays at 0, even in the app.

This should not be built into the integration itself, but it should be possible to create a template sensor that calculates. it.

oyvindwe commented 3 months ago

What happens with t_work_mode when you turn it off? Does it go to 0, or does it remain at the previous value?

bartashevich commented 3 months ago

This should not be built into the integration itself, but it should be possible to create a template sensor that calculates. it.

Maybe it is for the best. Since daily_energy_kwh sensor exists from API, just with the wrong value. I was think about possibility of making it functional.

What happens with t_work_mode when you turn it off? Does it go to 0, or does it remain at the previous value?

t_work_mode remain with the previous value

oyvindwe commented 3 months ago

This should be fixed in version 0.9.0

oyvindwe commented 3 months ago

It turned out t_beep is not really a status property, it's a field you send with other message to enable/disable beeping when controlling the device. I'm guessing your heat pump currently beeps every time Home Assistant sends it a command.

See PR #81 for how to turn that off (included in version 0.12.0)