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’.
(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.
- 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.