Issue with heating automation script

Hi,

As my zigbee TRV’s sometimes don’t register the command that HA sends I’m trying to make some kind of check so my heater isn’t burning for hours while the TRV is closed.

What it’s supposed to do:

When the thermostat goes from idle to heating, the TRV’s temperature should go from 5° to 30°. The opposite happens when the thermostat goes from heating to idle. This works perfectly (with a bit of overshooting but that’s not the issue here).

What I want to accomplish:

When I’m sending the change in temperature to the TRV, HA should check after let’s say 5min if the TRV’s temperature is set to 30°, if not it should retry setting the temperature. I want to repeat this twice. If the temperature isn’t 30° after the total of 3 attempts, HA should put the thermostat from heating to idle (stopping the heater from burning without purpose) and send a notification to my phone that the TRV isn’t responding and that the thermostat is turned off.

Via the HA facebook group someone made me this script:

alias: Slaapkamer ClimateTRV Aan
description: ''
trigger:
  - platform: state
    entity_id: climate.slaapkamer
    attribute: hvac_action
    from: idle
    to: heating
condition: []
action:
  - service: climate.set_temperature
    data:
      temperature: 30
    entity_id: climate.trv_slaapkamer
  - alias: >-
      Check every 5 mins for TRV to not be 30, repeat twice if needed, then
      notify
    repeat:
      while:
        - condition: template
          value_template: '{{ state_attr(''climate.trv_slaapkamer'', ''temperature'') != 30 }}'
        - condition: template
          value_template: '{{ repeat.index <= 2 }}'
      sequence:
        choose:
          - conditions:
              - condition: template
                value_template: '{{ repeat.index == 2 }}'
            sequence:
              - service: notify.mobile_app_iphone
                data:
                  message: >-
                    De radiatorkraan heeft 2x niet gereageerd! De verwarming is
                    uitgeschakeld in de slaapkamer!
              - service: climate.turn_off
                target:
                  entity_id: climate.slaapkamer
        default:
          - service: climate.set_temperature
            data:
              temperature: 30
            entity_id: climate.trv_slaapkamer
          - delay: '00:05:00'
mode: single

However there are some issues with the code.

  • Somehow it does not reattempt to set the temperature to 30° but it immediately send a notification after 5min and it does not change the thermostat from heating to idle.
  • Sometimes it just doesn’t do anything at all and the heater keeps on burning while the TRV is set at 5° and I’m not getting a notification.

This script is way over my capabilities to adapt it so I’m hoping that someone will be able to push me in the right direction.

Thanks in advance!

The climate entities don’t match. Your trigger is climate.slaapkamer while the actions are climate.trv_slaapkamer and climate.slaapkamer.

No I think that’s correct.
climate.slaapkamer is the thermostat which triggers the automation when it changed state.
climate.trv_slaapkamer is the radiator valve that must open (30C) and close (5C)

The automation you provided only turns the TRVs on. Would you mind posting the automation that turns the TRVs off?

Since this is created with the UI, you can look at the trace for the automation.

The one to turn off is a different automation.
It’s not made in ui.

The entire picture can help. The only things that sticks out to me in the TRV enable automation is there is not an immediate 5 minute delay to check.

The full sequence turns out to be:

  • action, set to 30
  • see if the temperature is not 30
  • action, set to 30
  • wait 5 minutes
  • see if the temperature is not 30
  • action, set to 30
  • wait 5 minutes
  • see if the temperature is not 30
  • action, set to 30
  • wait 5 minutes
  • see if the temperature is not 30
  • action, climate off, notify

That’s my bad. Maybe the person that helped you generated it with the UI.

As for the ui, I just copied the provided yaml so I don’t know how the person made it.

As for the turning off automation, that’s a simple one. When thermostat goes from heating to idle it sets the trv temp to 5C. There are no further checks in that one.

I don’t have any coding skills so it’s really hard to figure out what’s wrong here… :confused: