If you never plan to use midnight (00:00) for your schedule, then you can use 00:00 to represent an empty value. Just add a condition to the automation that rejects 00:00 so that the action is not executed.
I posted an example in your other topic. Here it is again but with a condition to reject 00:00.
i have a pool, and i control the water-pump with a electric clock in tehe electric board.
i want to control this water-pump with an HA automation over a sonoff basic switch.
so:
On my HA UI i have a map of weekdays, and for each weekday i have 3 time cycles ON/OFF
BUT THE ON AND OFF APEAR 1 MINUTE AFTER THE input_datetime.value
i can try to subtract 1 minute in the if…now() - 00:01 == input_datetime.value
but i didn’t reach the right code…
Any ideias? other way to do it?
i goole it for a long time… i’m surprise… because i think there are lot of automations following this ideia
like garden watering… pools, … even christmas tres… lolololo
Your schedule has:
7 days
3 periods per day
2 states per period
7 x 3 x 2 = 42 input_datetime entities.
That means the automation will need to check 42 entities every minute.
Does the schedule have to be so flexible that you need the ability to set the on/off times using a UI? The alternative is to hard-code the times within the automation. For example, a Time Condition lets you specify the time and day.
if monday
if now = A or B or C
switch on
if now = D or E or F
switch off
but you haven’t shown how that will done in an actual template.
Does the 2 in h_pb_on_2a represent the day of the week? Is that Tuesday or Monday (it depends on whether you consider Sunday or Monday as the first day of the week).
- alias: 'Pool Schedule'
trigger:
platform: time_pattern
minutes: '/1'
condition:
- condition: template
value_template: "{{states('sensor.time') != '00:00'}}"
- condition: template
value_template: >
{% set t = states('sensor.time') %}
{% set ns = namespace(datetime = '') %}
{% set d = now().isoweekday() %}
{% for p in range(1,4) %}
{% for s in range(0,2) %}
{% set dt = 'input_datetime.' ~ d ~ p ~ s %}
{% if t == states(dt)[:5] %}
{% set ns.datetime = dt %}
{% endif %}
{% endfor %}
{% endfor %}
{{ ns.datetime != '' }}
action:
service_template: >
{% set t = states('sensor.time') %}
{% set ns = namespace(datetime = '') %}
{% set d = now().isoweekday() %}
{% for p in range(1,4) %}
{% for s in range(0,2) %}
{% set dt = 'input_datetime.' ~ d ~ p ~ s %}
{% if t == states(dt)[:5] %}
{% set ns.datetime = dt %}
{% endif %}
{% endfor %}
{% endfor %}
switch.turn_{{'on' if ns.datetime[-1] == '1' else 'off'}}
entity_id: switch.sonoff_10009ace1f
Here’s how it works:
The first condition stops execution if the time is 00:00. This permits the use of 00:00 as a do-nothing value.
The second condition uses for-loops to iterate through all input_datetimes for the current day. That means it only needs to check 6 input_datetimes (3 periods x 2 states).
It checks if the current time matches any of the time-values in the 6 input_datetimes.
If the condition fails to find a matching time-value, execution stops. Otherwise, if it finds a match, it proceeds to the action.
The action repeats the same process performed in the condition in order to determine which input_datetime contains the matching time-value.
The last character in the input_datetime’s name is either 1 or 0. This is used to determine if the service should be switch.turn_on or switch.turn_off.
could we have diferent versions…???
i’m runing HassOS 3.11 with RPI 4 4Gb SD32Gb
Blockquote
Invalid config for [automation]: required key not provided @ data[‘action’]. Got None
required key not provided @ data[‘trigger’]. Got None. (See /config/configuration.yaml, line 13).
Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected ‘}’) for dictionary value @ data[‘condition’][1][‘value_template’]. Got None
not a valid value for dictionary value @ data[‘condition’][1][‘condition’]. Got None
required key not provided @ data[‘condition’][1][‘entity_id’]. Got None. (See /config/configuration.yaml, line 13)
for example:
in my code i can’t have ’
don’t work for me
i don’t understand why…!!!..
you did a very good approach in your code…
and i’m sure it’s OK
why not working in my HA?
I already change the 42 input_datetime code in my config.yaml
tuned my UI with new names… went ok
when update Automations.yaml with your code… have erros
could we have diferent versions…???
i’m runing HassOS 3.11 with RPI 4 4Gb SD32Gb
my automations.yaml what i’m doing wrong?
THANKs again
- id: '1583526600964'
- alias: 'piscina_bomba_auto'
trigger:
platform: time_pattern
minutes: '/1'
condition:
- condition: template
value_template: "{{states('sensor.time') != '00:00'}}"
- condition: template
value_template: >
{% set t = states('sensor.time') %}
{% set ns = namespace(datetime = '') %}
{% set d = now().isoweekday() %}
{% for p in range(1,4) %}
{% for s in range(0,2) %}
{% set dt = 'input_datetime.' ~ d ~ p ~ s %}
{% if t == states(dt)[:5] %}
{% set ns.datetime = dt %}
{% endif %}
{% endfor %}
{% endfor %}
{{ ns.datetime != '' %}
action:
service_template: >
{% set t = states('sensor.time') %}
{% set ns = namespace(datetime = '') %}
{% set d = now().isoweekday() %}
{% for p in range(1,4) %}
{% for s in range(0,2) %}
{% set dt = 'input_datetime.' ~ d ~ p ~ s %}
{% if t == states(dt)[:5] %}
{% set ns.datetime = dt %}
{% endif %}
{% endfor %}
{% endfor %}
switch.turn_{{'on' if ns.datetime[-1] == '1' else 'off'}}
entity_id: switch.sonoff_10009ace1f
error
Invalid config for [automation]: required key not provided @ data[‘action’]. Got None
required key not provided @ data[‘trigger’]. Got None. (See /config/configuration.yaml, line 13).
automations.yaml
already updated
- id: '1583526600964'
- alias: 'piscina_bomba_auto'
trigger:
platform: time_pattern
minutes: '/1'
condition:
- condition: template
value_template: "{{states('sensor.time') != '00:00'}}"
- condition: template
value_template: >
{% set t = states('sensor.time') %}
{% set ns = namespace(datetime = '') %}
{% set d = now().isoweekday() %}
{% for p in range(1,4) %}
{% for s in range(0,2) %}
{% set dt = 'input_datetime.' ~ d ~ p ~ s %}
{% if t == states(dt)[:5] %}
{% set ns.datetime = dt %}
{% endif %}
{% endfor %}
{% endfor %}
{{ ns.datetime != '' }}
action:
service_template: >
{% set t = states('sensor.time') %}
{% set ns = namespace(datetime = '') %}
{% set d = now().isoweekday() %}
{% for p in range(1,4) %}
{% for s in range(0,2) %}
{% set dt = 'input_datetime.' ~ d ~ p ~ s %}
{% if t == states(dt)[:5] %}
{% set ns.datetime = dt %}
{% endif %}
{% endfor %}
{% endfor %}
switch.turn_{{'on' if ns.datetime[-1] == '1' else 'off'}}
entity_id: switch.sonoff_10009ace1f