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

Added CustomClimate, set a couple of custom sensors, added debug_number to easily scrap packets #111

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

brazoayeye
Copy link

Nothing more than title, nothing less.

Described on example.yaml

@brazoayeye brazoayeye changed the title Added CustomClimate Added CustomClimate, set a couple of custom sensors, added debug_number to easily scrap packets Mar 18, 2024
@lanwin
Copy link
Collaborator

lanwin commented Mar 22, 2024

@brazoayeye thank you for that pullrequest!
I want to let you know that I can not look at this before the end of next week.

@Tycorc
Copy link

Tycorc commented May 22, 2024

hey what is the status? I really would like to see the energy consumption added to main.

Thanks

@brezuicabogdan
Copy link

Same here - looking forward for the power consumption sensor.
Let me know if I can help in any way.

Thank you!!

@brazoayeye
Copy link
Author

Same here - looking forward for the power consumption sensor. Let me know if I can help in any way.

Thank you!!

I haven't followed developments in this branch in the last months, but using my branch for me works well (except like 20% of writing fails) and i have the climate option for heating/cooling and dwh. The configuration is not handy for presets and working modes, but that's the only option i found to give flexibility in the config file.

Test and suggestione are well accepted

@brezuicabogdan
Copy link

I'll try flashing it in the next couple of days and have some feedback once I do. I am not using presets so that's a non-issue for me.

Thanks.

@pantherale0
Copy link

Same here - looking forward for the power consumption sensor. Let me know if I can help in any way.

Thank you!!

I have a power consumption sensor via a custom sensor. Here is my config for the heat pump (addr 10:00:00)

  devices:
    - address: "10.00.00"
      outdoor_temperature:
        name: Heat Pump Outdoor temperature
      custom_sensor:
        - name: Heat Pump Voltage
          message: 0x24fc
          device_class: voltage
          state_class: measurement
          unit_of_measurement: V
        - name: Heat Pump Current
          message: 0x8217
          device_class: current
          state_class: measurement
          unit_of_measurement: A
          accuracy_decimals: 1
          filters:
            - multiply: 0.1
        - name: Heat Pump Power
          message: 0x8413
          device_class: power
          state_class: measurement
          unit_of_measurement: W
        - name: Heat Pump Energy
          message: 0x8414
          device_class: energy
          state_class: total_increasing
          unit_of_measurement: kWh
          accuracy_decimals: 1
          filters:
            - multiply: 0.001
        - name: Compressor Frequency
          message: 0x8238
          device_class: frequency
          state_class: measurement
          unit_of_measurement: Hz
          accuracy_decimals: 1
        - name: Target Compressor Frequency
          message: 0x8237
          device_class: frequency
          state_class: measurement
          unit_of_measurement: Hz
          accuracy_decimals: 1
        - name: Fan Speed
          message: 0x823D
          state_class: measurement
          unit_of_measurement: RPM
          accuracy_decimals: 1

Note, the model for my unit is AE050XYDEGEU

@lanwin
Copy link
Collaborator

lanwin commented Jun 11, 2024

@brazoayeye thank you for your pullrequest and all of your work!

I am a little bit torn about this.

On one hand it adds a lot flexibility.

On the other hand I can not see more "climates" controls then the ones you already figured it. What else should come there? And making all configurable adds a lot of complexity witch needs to be supported in the future. I already have problems digging thru your changes. And also, more flexibility means that new users need to understand it, look for the message ids and need to understand what they are doing.

So maybe it would be better to just add specific controls dedicated to the configuration that you already figured out so new users just need to add them and given them a name. Dedicated controls add more code, but usually they tend to be simpler and easier to understand and fix.

@brazoayeye
Copy link
Author

Maybe an easy fix could be a shortcut in the py file to easen the setup of the yaml. But it desn't remove the underground complexity i wasn't able to avoid to allow users to select custom addresses and behavior.

I admit i'm not an expert regarding espHome and that i don't have any experience with heat pumps except from mine, so i can't assume other setups are similar to mine. For example:

  • I know that different heat pumps has different maximum/minimum temperature for heating / dwh
  • In my case the maximum/minimum temperature of the same climate changes changing the working mode in the local interface, I haven't deepen this aspect and I led the range wider letting the local display to reset wrong settings
  • Modes and presets are a mess, they use random names for random functions without a clear explaination. In fact when I tested the system i could select 4 presets for dwh (Eco, Standard, Power, Force) but now I only have 3 in the local display. Maybe because I disabled the heating, but maybe not. In any case I don't know the difference between presets.
  • I suspect all heat pumps have the ON/OFF function splitted from the mode selection, differently from what happens if hASS. Nevertheless the usage of AUTO=0, COOL=1, HEAT=4 and the nasa documentations seems to indicate that also different modes should be used for someone.

Refactoring and simplifications could (and should) be done, but I would like to have a feedback regarding other heat pumps or code suggestions. Otherwise I'll reach a very similar result.
I also discovered custom presets recently, but i haven't implemented them.

This is my first time using github and I made some mistakes trying to amend a commit, but I tried to publish step by step while adding features so you can check modifications easier. If I can help, please tell me how

@Krzysiek1976
Copy link

[brazoayeye] , lanwin
Hi
if you could add a custom sensor:
0x4299 NASA_AHUPANEL_STATIC_PRESSURE
and :
0x8061 ENUM_OUT_DEICE_STEP_INDOOR NASA_OUTDOOR_INDOOR_DEFROST_STEP Indoor unit defrost operation steps 1 Defrost stage 1, 2 Defrost stage 2, 3 Defrost stage 3, 7 Defrost operation end stage, 255 No defrost op
Thank you for your work.

@brazoayeye
Copy link
Author

@Krzysiek1976 Have you seen 0x4299 and 0x8061 in the communication? You can implement them adding a custom sensor for example

      custom_sensor:
        - name: Static pressure
          message: 0x4299
          device_class: pressure
          state_class: measurement
          unit_of_measurement: Pa

@lanwin I think that the project started with the wrong idea of mixing code and parameterizations, and that caused many enums and avoidable rows of code. Imho a refactoring should be done to remove all hardcoded messages and to expand the example to include all working configurations as the list of custom sensors (as provided by pantherale0) and custom climates.
I also did a bad start-due to my inexperience with esp home-adding avoidable sensors and I've already replaced them with the yaml parametrization. I didn't realied that custom sensors existed, because they are not even mentioned in the readme/example, and I'm afraid that many people are suffering and wasting time only because the example is not wide enogh.

This is not intended as a criticism of the work done, that's very good, but only as a point of reflection and a discussion to simplify future work. I also skipped to analyze the non-nasa protocol, that seems much more fixed and less flexible and for wich could be right to keep values fixed.

In my code I decided to call Presets and Mode by number (ex ClimatePreset0Value, ClimateMode3Value) to keep it as transparent as possible to future EspHome changes, but it's probably a fail because the parameterization is counterintuitive. It's probably better to link them directly with espHome enums.

@hnykda
Copy link
Contributor

hnykda commented Jun 30, 2024

I am just randomly passing by through this PR as a user, so I don't know the details, but I think what @brazoayeye makes sense to me and is close to what I know from some other integrations (such as ESPHome Modbus integration, e.g. here).

@lanwin
Copy link
Collaborator

lanwin commented Jul 1, 2024

@brazoayeye I am still not sure what is the best option to go here.

Moving everything to custom_sensor and custom_climates is not as bad as an idea.

But the problem is that this does not includes the non nasa stuff with (as you correctly discovered) it is static and dont use the flexible message. It might be possible to change the non nasa stuff and create an adapter witch converts the non nasa messages to nasa messages and back. But this adds also another layer of indirection. Especially the a message in nasa can be one variable. NonNasa messages often have multiple values and you need to send all of them to make it work.

Maybe its a good split nasa and non nasa into separate components. But then also all features need to get added twice.

I also fear the complexity a bit. I have 23 years of experience in development and as I was younger I often also preferred ultra generic solutions cause they ware cool. But the last years I mostly moved to use specific code for specific problems and most of the time this turned out to be more reliable and easier to support and change.

Regarding the custom_sensors. My plan is still to add dedicated sensors for most of the basic stuff like power, pressue etc. So you simple need to give them a name.

@hnykda you can not directly compare integrations like Modbus to this one. This is not an NasaProtocol component witch let you adapt to any device that users the NASA protocol. It was designed in the first place to easily add my AC to home assist.

Modbus is also a good example what I mean by being too generic. You have to know how modbus works. Know exactly witch coils and addresses to use and witch modifiers to apply. That is pretty complex for someone how dont is an IT person.

Meybe that is exactly the point. Maybe its better provide a generic "components\samsung_nasa" components along with "components\samsung_ac_nasa" and "components\samsung_ac_nonnasa", witch then works like modbus and the components share the nasa protocol and utility classes underneath. This would allow to create examples for each and reduces complexity. (Component means sub folder not github repository).

Also there is the problem that this project startet mainly for AC devices and now there are also heatpump users. Maybe there also should be "components\samsung_headpump".

So I struggle with where to go now.

I also would like to invite more people to directly change the codebase and make it easier for me (since I am pretty bound to other stuff). But before that happens I need to ensure that we all agree on some basics pricipals and a plan where to go.

Splitting things up also would have the benefit that I could assign maintainers to specific parts like the non nasa stuff where I always will have the problem that I can not test that stuff.

Maybe I should start a discussion and invite the other contributors to this discussion.

@hnykda
Copy link
Contributor

hnykda commented Jul 1, 2024

You are entirely right; I like your thinking about this and really appreciate your careful reasoning around UX as well as developer experience here (also that you think about long-term maintenance, including other contributors ❤️ ).

The proposal for the split looks like a great idea. Seems like that would make it very extensible on all fronts (both generic NASA, making non-nasa stuff separate so not poluting the new stuff, being able to add additional devices next to ACs, such as heatpumps and other stuff, ...)?

Btw. you might consider renaming the repository before it gets too popular (removing the ac suffix or changing it to something entirely generic like samsung_comms or whatever). It seems to be already outdated 😁 (that's the dark side of writing too good software).

Btw. I would consider asking directly the HA/ESPHome maintainers/developers for an opinion, I suspect this will be a very common issue/consideration, and they might be willing to help. And if not them, maybe someone from similar projects might?

@north3221
Copy link
Contributor

@brazoayeye I think this is great work, although I have to agree with @lanwin. My personal opinion is this project should be kept as the interface with the AC/Heatpump for controls and sensors as needed.

I actually wouldn't even have the climate that @lanwin put in the project already. Exposing the controls needed allows for all users to build their own climate control in HA the way they see fit. I use weather compensation and have a complex set up that controls the needed compensation curve. Other will have all sorts of different set up.

So why complicate this project?

I also wouldn't put all the sensors hard coded in there @lanwin - you have created the ability to add custom sensor, to @brazoayeye's point people may not know about them, and certainly not all the options available of them. So I suggest we add more examples, maybe not in the examples.yaml, maybe we create some sensor example yaml's to help users. I'll raise a pr to add some examples

We could also do with expanding the custom sensor, or adding more custom sensor types

So then we just have the controls implemented and sensors can be added using the custom sensor approach, keeping the code as simple as possible but the flexibility everyone needs. I'll pick up more on your how to proceed with project discussion @lanwin

@brazoayeye
Copy link
Author

I made this modification to allow my HASS to control the heating/ DWH temperature to follow photovoltaic production.

Not knowing all code stuffs already presents, and not finding anything related or fitting my needs in the examples, I supposed there weren't any other way to change the setpoint except from coding a new one.

I've chosen the climate instead of a simple control because it (nearly) perfectly fits the samsung concept with Set - read - presets - modes so It seemed the most logic option even for HASS views.
Actually i implemented presets / Modes before knowing they are quite useless. I hoped that changing them I could have changed setpoint limits or maximum power used by the device, but it isn't

@north3221
Copy link
Contributor

So now I added the PRs for sensors and other stuff I have done, I have implemented a climate control using the esphome climate and the sensors for the Samsung heatpump. So I think it makes sense to share yaml examples for people to implement their own instead of adding a custom climate to the code.

I may be missing something, what are you not able to do using an esphome climate control?

@brazoayeye
Copy link
Author

I don't know what you mean with espHome climate control, because this is my first project with esp home and i didn't reach my goal without programming.

I have two setpoint, one for dwh and another for heating/cooling. Both have their status temperature. One have a climate mode, the other have a preset. I use esphome terms but i don't know how they are called by samsung.

Presets are like eco - standard - power for dwh
Modes are like heating - cooling - auto for heating.

Could I implement them without my code?
Check my example.yaml for addresses and other infos

Thanks

@north3221
Copy link
Contributor

@brazoayeye yeah this is my first go of using esphome, so I am far from an expert. I am just learning, but you can configure whatever you want in it. Take a look in their docs at the climate thermostat and there is all the other components you can setup.

So I have set up DHW with the samsung heatpump, I need to do a proper example.yaml etc but for now, here is my config.. you need the indoor device controls I added

    water_heater_power:
        name: "DHW Power"
        id: dhw_power
      water_temperature:
        id: hot_water_current_temp
      water_heater_mode:
        id: hotwater_mode
      water_target_temperature:
        id: hot_water_target_temp

NB Using id only and no name makes it internal (wont be exposed to home assistant)

Then to create my domestic hot water climate I add this to my esphome yaml:

climate:
  - platform: thermostat
    name: "Hot Water"
    id: climate_hot_water
    sensor: hot_water_current_temp
    min_heating_off_time: 300s
    min_heating_run_time: 300s
    min_idle_time: 30s
    on_state:
      - number.set:
          id: hot_water_target_temp
          value: !lambda return { x.target_temperature };
      - if:
          condition:
            switch.is_on: dhw_power
          then:
            - select.set:
                id: hotwater_mode
                option: !lambda |-
                  if (id(climate_hot_water).target_temperature > id(hp_dhw_max_temp).state) {
                    return { "Standard" };
                  } else {
                    return { "Eco" };
                  }
    preset_change:
      - if:    
          condition:
            lambda: return id(climate_hot_water).preset == CLIMATE_PRESET_BOOST;
          then:
            - component.suspend: dhw_preset_mode
            - delay: 45min
            - component.resume: dhw_preset_mode
    heat_action:
      - switch.turn_on: dhw_power
      - select.set:
          id: hotwater_mode
          option: !lambda |-
              if (id(climate_hot_water).target_temperature > id(hp_dhw_max_temp).state) {
                return { "Standard" };
              } else {
                return { "Eco" };
              }
    idle_action:
      - switch.turn_off: dhw_power
    heat_deadband: 5
    heat_overrun: 0
    default_preset: ECO
    preset:
      - name: ECO
        default_target_temperature_low: 40 °C
      - name: HOME
        default_target_temperature_low: 45 °C
      - name: AWAY
        default_target_temperature_low: 20 °C
      - name: BOOST
        default_target_temperature_low: 55 °C
      - name: SLEEP
        default_target_temperature_low: 70 °C
    visual:
      min_temperature: 20
      max_temperature: 70
      temperature_step:
        target_temperature: 1
        current_temperature: 0.1

I've left the automations within the climate config so you can see them, but you can prob take those out. I set up a sensor with id hp_dhw_max_temp, this is the temp at which the heat pump is set to use the compressor to heat hot water, so when I request water hotter than that (which I do overnight on cheap rate) it flicks it out of eco and into standard. We should be able to get that from 0x427C but it doesnt work for me so I hard coded it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants