I had solidly working automation with the following code:
- id: '1616781183730'
alias: Swimpool Night AWHP Heating
description: Warm up Swimpool by AWHP
trigger:
- platform: time
at: 07:00:00
- platform: time
at: '23:01:00'
condition:
- condition: state
entity_id: input_boolean.swimpoolactive
state: 'on'
action:
- service: '{% set h = now().hour %} {% set m = now().minute %} switch.turn_{{ ''on'' if (h == 23 and m == 01) else ''off'' }}'
entity_id: switch.heatpump_swimpool
- service: '{% set h = now().hour %} {% set m = now().minute %} input_boolean.turn_{{ ''off'' if (h == 07 and m == 00) }}'
entity_id: input_boolean.swimpoolactive
mode: single
After update to 2021.5.5 I have an error:
Logger: homeassistant.config
Source: config.py:443
First occurred: 22:24:13 (1 occurrences)
Last logged: 22:24:13
Invalid config for [automation]: Service {% set h = now().hour %} {% set m = now().minute %} switch.turn_{{ 'on' if (h == 23 and m == 01) else 'off' }} does not match format <domain>.<name> for dictionary value @ data['action'][0]['service']. Got None. (See /config/configuration.yaml, line 14).
It doesnât like the needlessly zero-padded integers in the template. Remove all of the unnecessary leading zeros and the template should work again.
BTW, if you use variables it will help to simplify the templates.
action:
- variables:
h: '{{ now().hour }}'
m: '{{ now().minute }}'
- service: 'switch.turn_{{ ''on'' if h == 23 and m == 1 else ''off'' }}'
entity_id: switch.heatpump_swimpool
- service: 'input_boolean.turn_{{ ''off'' if h == 7 and m == 0 }}'
entity_id: input_boolean.swimpoolactive
Also, there is a potential problem with the template in the second service call. If the time is not â07:00â the template returns nothing which produces input_boolean.turn_ which is a non-existent service call.
Suggested way to handle the final service call:
action:
- variables:
h: '{{ now().hour }}'
m: '{{ now().minute }}'
- service: 'switch.turn_{{ ''on'' if h == 23 and m == 1 else ''off'' }}'
entity_id: switch.heatpump_swimpool
- condition: template
value_template: '{{ h == 7 and m == 0 }}'
- service: input_boolean.turn_off
entity_id: input_boolean.swimpoolactive
Thatâs doing more than what SuperMaximusâ automation does. Are you certain those are the requirements?
Also, it wonât work as you may expect. When triggered at 07:00 the first condition evaluates to false and the execution flow ends there (never reaching the second condition).
If SuperMaximus needs to do one thing at 23:01 and something different at 07:00 then the action should use choose. However, thatâs an assumption because SuperMaximus never explained the automationâs requirements only that it was âsolidly workingâ until upgrading to 2021.5.5. The cause of the failure is the use of zero-padded integers which are no longer considered to be proper integers.
Thanks, everybody!
Yes, the matter was in leading â0â.
My objective is to turn on heatpump_swimpool at 23:01 in case is input_boolean.swimpoolactive is turned on and turn off input_boolean.swimpoolactive & heatpump_swimpool unconditionally at 7:00.
Looking at both of your suggested solutions I see the same output. Do they really differ in terms of action?