Need help debugging automation

I’m trying to figure out why this automation trace thinks its calling for heating-only…I think the variable do_cool should be true not false?

This is convoluted because its a portable heat pump unit and Midea put the temp sensor in a shitty location and made the min heating temp possible to set seems to be 60-61F so if the outdoor temp is below the set-point once it sits a few minutes it decides to heat more even though the real room temperature is quite warm (e.g. for this particular trace, the REAL room temperature is 71F and outdoor temp around 50F). Then to make it more annoying, the unit begins heating/cooling at reduced capacity before it reaches the setpoint by 3F (e.g. if I set it to 65F heat it comes on maximum speed when the room is 64F but still heating low-speed when the room is 68F) but in mild weather that is still too much heating/cooling so I made up some “offsets” to try and help create a dead-band in my code.

Side-note, why the heck is it SO HARD to copy anything off the HA web UI now? Every couple seconds it seems to do something that un-highlights everything and shortcuts like CTRL+A don’t work either? And then thanks to all the Javascript I can’t highlight more than what’s on the screen either - it won’t scroll while highlighting. This makes it a LOT more painful to post in forums asking for help! It shouldn’t take me 10 minutes to successfully copy the debug information to a forum post :angry:

Trace Variables:

context:
  id: 01JBVH51YGZV04JF0ZGW0R3WWA
  parent_id: 01JBVH51Y9H1J930XXFWJRPBBR
  user_id: null
current_mode: cool
cool_set: 73
heat_set: 57
max_set: 86
min_set: 61
room_temp: 62
cool_offset: 3
heat_offset: 5
cool_set_too_low: false
cool_set_too_high: false
cool_set_in_range: true
heat_set_too_low: true
heat_set_too_high: false
heat_set_in_range: false
room_below_cool_set: true
room_above_cool_set: false
room_below_heat_set: true
room_above_heat_set: false
room_below_cool_max: true
room_above_cool_max: false
room_below_heat_min: true
room_above_heat_min: false
do_cool: false
do_heat: true
do_max_cool: false
do_min_heat: false

Variable Code:

variables:
  current_mode: '{{ states(''climate.whynter_arc_1230wnh'') }}'
  cool_set: >-
    {{ [states('sensor.whynter_portable_heatpump_hvac_requested_heat_computed')
    |
    int(0),states('sensor.whynter_portable_heatpump_hvac_requested_cool_computed')
    | int(0)]|max }}
  heat_set: >-
    {{ [states('sensor.whynter_portable_heatpump_hvac_requested_heat_computed')
    |
    int(0),states('sensor.whynter_portable_heatpump_hvac_requested_cool_computed')
    | int(0)]|min }}
  max_set: '{{ 86 }}'
  min_set: '{{ 61 }}'
  room_temp: >-
    {{ state_attr('climate.whynter_arc_1230wnh','current_temperature') | int(0)
    }}
  cool_offset: '{{ 3 }}'
  heat_offset: '{{ 5 }}'
  cool_set_too_low: '{{ cool_set < min_set }}'
  cool_set_too_high: '{{ cool_set > max_set }}'
  cool_set_in_range: '{{ cool_set >= min_set and cool_set <= max_set }}'
  heat_set_too_low: '{{ heat_set < min_set }}'
  heat_set_too_high: '{{ heat_set > max_set }}'
  heat_set_in_range: '{{ heat_set >= min_set and heat_set <= max_set }}'
  room_below_cool_set: '{{ room_temp < cool_set-cool_offset }}'
  room_above_cool_set: '{{ room_temp >= cool_set-cool_offset }}'
  room_below_heat_set: '{{ room_temp <= heat_set+heat_offset }}'
  room_above_heat_set: '{{ room_temp > heat_set+heat_offset }}'
  room_below_cool_max: '{{ room_temp < max_set-cool_offset }}'
  room_above_cool_max: '{{ room_temp >= max_set-cool_offset }}'
  room_below_heat_min: '{{ room_temp <= min_set+heat_offset }}'
  room_above_heat_min: '{{ room_temp > min_set+heat_offset }}'
  do_cool: |-
    {{
      (cool_set_too_low) or 
      (cool_set_in_range and room_above_heat_set) or 
      (cool_set_too_high and room_below_cool_set and room_below_cool_max) or
      (cool_set_too_high and room_above_cool_set)
    }}
  do_heat: |-
    {{
      (heat_set_too_low and room_below_heat_set) or 
      (heat_set_too_low and room_above_heat_set and room_above_heat_min) or
      (heat_set_in_range and room_below_cool_set) or 
      (heat_set_too_high)
    }}
  do_max_cool: |-
    {{
      (heat_set_too_low and room_above_heat_set and room_below_heat_min and room_below_cool_max)
    }}
  do_min_heat: |-
    {{
      (cool_set_too_high and room_below_cool_set and room_above_cool_max and room_above_heat_min)
    }}

Entire automation:

alias: Whynter Portable Heatpump HVAC Set Temperatures
id: Whynter Portable Heatpump HVAC Set Temperatures
trace:
  stored_traces: 100
trigger:
  - platform: state
    entity_id:
      - sensor.whynter_portable_heatpump_hvac_requested_heat_computed
      - sensor.whynter_portable_heatpump_hvac_requested_cool_computed
  - platform: state
    entity_id:
      - sensor.whynter_portable_heatpump_hvac_requested_heat_computed
      - sensor.whynter_portable_heatpump_hvac_requested_cool_computed
    for: '00:00:05'
  - platform: state
    entity_id: climate.whynter_arc_1230wnh
    from: 'off'
  - platform: state
    entity_id: climate.whynter_arc_1230wnh
    from: heat
    to: cool
  - platform: state
    entity_id: climate.whynter_arc_1230wnh
    from: cool
    to: heat
mode: queued
condition:
  - condition: state
    entity_id: climate.whynter_arc_1230wnh
    state:
      - cool
      - heat
action:
  - variables:
      current_mode: '{{ states(''climate.whynter_arc_1230wnh'') }}'
      cool_set: >-
        {{
        [states('sensor.whynter_portable_heatpump_hvac_requested_heat_computed')
        |
        int(0),states('sensor.whynter_portable_heatpump_hvac_requested_cool_computed')
        | int(0)]|max }}
      heat_set: >-
        {{
        [states('sensor.whynter_portable_heatpump_hvac_requested_heat_computed')
        |
        int(0),states('sensor.whynter_portable_heatpump_hvac_requested_cool_computed')
        | int(0)]|min }}
      max_set: '{{ 86 }}'
      min_set: '{{ 61 }}'
      room_temp: >-
        {{ state_attr('climate.whynter_arc_1230wnh','current_temperature') |
        int(0) }}
      cool_offset: '{{ 3 }}'
      heat_offset: '{{ 5 }}'
      cool_set_too_low: '{{ cool_set < min_set }}'
      cool_set_too_high: '{{ cool_set > max_set }}'
      cool_set_in_range: '{{ cool_set >= min_set and cool_set <= max_set }}'
      heat_set_too_low: '{{ heat_set < min_set }}'
      heat_set_too_high: '{{ heat_set > max_set }}'
      heat_set_in_range: '{{ heat_set >= min_set and heat_set <= max_set }}'
      room_below_cool_set: '{{ room_temp < cool_set-cool_offset }}'
      room_above_cool_set: '{{ room_temp >= cool_set-cool_offset }}'
      room_below_heat_set: '{{ room_temp <= heat_set+heat_offset }}'
      room_above_heat_set: '{{ room_temp > heat_set+heat_offset }}'
      room_below_cool_max: '{{ room_temp < max_set-cool_offset }}'
      room_above_cool_max: '{{ room_temp >= max_set-cool_offset }}'
      room_below_heat_min: '{{ room_temp <= min_set+heat_offset }}'
      room_above_heat_min: '{{ room_temp > min_set+heat_offset }}'
      do_cool: |-
        {{
          (cool_set_too_low) or 
          (cool_set_in_range and room_above_heat_set) or 
          (cool_set_too_high and room_below_cool_set and room_below_cool_max) or
          (cool_set_too_high and room_above_cool_set)
        }}
      do_heat: |-
        {{
          (heat_set_too_low and room_below_heat_set) or 
          (heat_set_too_low and room_above_heat_set and room_above_heat_min) or
          (heat_set_in_range and room_below_cool_set) or 
          (heat_set_too_high)
        }}
      do_max_cool: |-
        {{
          (heat_set_too_low and room_above_heat_set and room_below_heat_min and room_below_cool_max)
        }}
      do_min_heat: |-
        {{
          (cool_set_too_high and room_below_cool_set and room_above_cool_max and room_above_heat_min)
        }}
  - choose:
      - conditions:
          condition: template
          value_template: |
            {{
              (do_cool and not do_heat) or
              (do_cool and do_heat and current_mode == "cool")
            }}
        sequence:
          - data:
              entity_id: climate.whynter_arc_1230wnh
              hvac_mode: cool
              temperature: '{{ [cool_set,max_set] | min }}'
            action: climate.set_temperature
          - data:
              entity_id: input_number.whynter_portable_heatpump_hvac_last_set_temp
              value: '{{ [cool_set,max_set] | min }}'
            action: input_number.set_value
      - conditions:
          condition: template
          value_template: |
            {{
              (do_heat and not do_cool) or
              (do_heat and do_cool and current_mode == "heat")
            }}
        sequence:
          - data:
              entity_id: climate.whynter_arc_1230wnh
              hvac_mode: heat
              temperature: '{{ [heat_set,min_set] | max }}'
            action: climate.set_temperature
          - data:
              entity_id: input_number.whynter_portable_heatpump_hvac_last_set_temp
              value: '{{ [heat_set,min_set] | max }}'
            action: input_number.set_value
      - conditions:
          condition: template
          value_template: |
            {{ do_max_cool }}
        sequence:
          - data:
              entity_id: climate.whynter_arc_1230wnh
              hvac_mode: cool
              temperature: '{{ max_set }}'
            action: climate.set_temperature
          - data:
              entity_id: input_number.whynter_portable_heatpump_hvac_last_set_temp
              value: '{{ max_set }}'
            action: input_number.set_value
      - conditions:
          condition: template
          value_template: |
            {{ do_min_heat }}
        sequence:
          - data:
              entity_id: climate.whynter_arc_1230wnh
              hvac_mode: heat
              temperature: '{{ min_set }}'
            action: climate.set_temperature
          - data:
              entity_id: input_number.whynter_portable_heatpump_hvac_last_set_temp
              value: '{{ min_set }}'
            action: input_number.set_value

I don’t have any of these issues.
Probably on your end.

That’s not particularly useful…I don’t have this problem with any other websites, just Home Assistant?

So it’s not helpful to let you know what the issue is?
Alright, I’ll leave.

p.s. None of the issues in the video happens on any of the computers I have used

You didn’t do anything to say what the issue is?

“works for me, its your problem” is not useful

Hi Matt Miller,

First that’s pretty impressive. And if you wrote that in the UI editor, I’m even more impressed.

I’m going to say that you have built something that’s basically working, but some of the edge cases are wonky? So I have that right?
The problem for someone that helping you is that there is a lot going on, we don’t have the hardware to test things and we don’t have the motivation to get that deeply involved.

My suggestion is keep breaking the weirdness down. You are doing the right things by having most values in variables, giving you all the information in the trace to see what is happening. Pull out sections of the Jinja into the developer - template sandbox to make sure you are getting what you want to get. Keep at it, you are doing well.

If you get to a point that a specific thing that you can focus on is identified as not working come on back here and ask about that. As a whole it’s a lot to ask others to help with and debug as a whole.

As far as the UI editor goes, I’ll use it to help flesh out something tiny or the base code of something bigger, then I pull it out to Code Server and actually do the editing. For something complicated like this it is not useful at all for me.

Wrote it in a mix of SSH/Vim and some of the Template-editor dev-tool to help with syntax. I much prefer a keyboard over a mouse and enjoy being able to take stuff from “rough idea” comments to massage and then find-replace into code. I break my stuff down into “package YAML” files that I try and keep encapsulated as best I can (also makes it easy to duplicate a chunk of YAML and tweak for a new similar thing, or remove/rename/move to disable in bulk or debug which file is buggy).

My day job is software/systems engineering and most familiar with Java/C++ and C++ I was always using basic text editors so that’s more comfortable and faster than GUIs, still learning the whole “whitespace matters” headache. You can probably see some C++/Java style bleeding thru my templates (because that makes it mentally easier to read for me)

This is also my first time trying to do the automation variables instead of just a bunch of template-sensors (I have been thinking of template sensors as “function calls” in a way to break down my problems into smaller chunks of code…and then can pull up all the history graphs to debug over time). So this is new having to depend on just the traces alone.

Yes, worked perfectly for cooling but has some sharp edges now that we’re having cold mornings (also when I have least time to debug while its acting up before work). Its running heat at times I think it ought to be swapping over to “cooling” to prevent it running at all.

I’m kinda forced to use the UI for seeing the traces (as far as I know) and that’s making it more difficult for me.

In the particular trace I posted I was struggling to figure out why “do_cool” was not true…I think it ought to have been (which would maybe have kept it from flipping to heating-mode) but I was struggling with why. Probably just need to scratch my head harder or something tracing the code.

Well If it does not happen on any of my browsers then we can safely assume that either you run a browser that is not compatible, or you have some add in on your browser that is doing it.
Standard Edge or Chrome works fine.