Problem with a condition in an automation

I have a problem with a specific condition testing an attribute associated with a climate entity. My automation looks like this:

- alias: Daikin_normal
  description: Will adjust settings based on energy price
  trigger:
  - platform: state
    entity_id: sensor.heating_level
    from: Eco
    to: Normal
  condition: "{{ states.climate.gamla_huset.attributes.hvac_action != 'off' }}"
  action:
    service: script.set_daikin_normal

My intention is to run the script set_daikin_normal only if HVAC isn’t turned off, i.e the attibute != ‘off’.

Looking at the attibutes it looks like this:

hvac_modes:
  - fan_only
  - dry
  - cool
  - heat
  - heat_cool
  - 'off'
min_temp: 7
max_temp: 35
target_temp_step: 1
fan_modes:
  - Auto
  - Silence
  - '1'
  - '2'
  - '3'
  - '4'
  - '5'
preset_modes:
  - none
  - away
  - eco
  - boost
swing_modes:
  - 'Off'
  - Vertical
  - Horizontal
  - 3D
current_temperature: 21
temperature: 18
fan_mode: Auto
hvac_action: 'off'
preset_mode: none
swing_mode: 'Off'
friendly_name: Gamla huset
supported_features: 57

(I get this list from states tab in the Developers tool)

hvac_action currently holds the value ‘off’. And I compare the attribute with ‘off’. But still this test fails, i.e. the attribute seems to hold something different than ‘off’. Consequently the script is executed even if the HVAC is turned off.

This puzzles me. I need to find out how this test should be made to avoid calling the script if the HVAC is turned off.

Try this:

- alias: Daikin_normal
  description: Will adjust settings based on energy price
  trigger:
  - platform: state
    entity_id: sensor.heating_level
    from: Eco
    to: Normal
  condition: "{{ not is_state_attr('climate.gamla_huset', 'hvac_action', 'off') }}"
  action:
    service: script.set_daikin_normal

Thanks, but I think this was a false alarm. I added a notification in the script, and included the attribute in the message. So far I haven’t seen ‘off’ in the message.

But still I can’t find out what triggers the HVAC on from a being in an off state. I have searched all my automations and scripts for the specific entity associated with the HVAC, but I can only find any in the script guarded by this condition.

The log indicates it is the guarded script that executes once the HVAC turns on…

Anyway, I will try your proposal and see if this makes any difference.

I understand the rational to avoid using string comparison when doing tests on states or states attributes. So I have changed my code. However, this didn’t solve my problem. After a while my HVAC was on again. My added notification showed hvac_mode ‘idle’ in this case, which confirms the problem is not related to the test as such. But how could the hvac_mode change from ‘off’ to ‘idle’ without any notice?

However, finally it looks like I’ve solved my problem. At least the thermostat has been in a stable ‘off’ status for a couple of days now. I added mode: single in my automation and since then the thermostat is stable. According to the documentation this should be the default mode but I doubt this is the case.