Assistance with an automation for 3 x water heaters/geysers - please help if possible

Hi all,
I’m hoping that someone can kindly assist me with my automation’s:

I have 3 x switch entities which are all Tuya devices, added to HA. These 3 x switches control our water heaters/geysers.
(I have setup a schedule using the scheduler-card but for my current setup, this is not ideal so I’d prefer not to use this).

These entities are:

  1. switch.kitchen_geyser_switch_1
  2. switch.mns_geyser_switch_1
  3. switch.main_geyser_switch_1

I’ve tried to create an automation that sets the on off times as seen in the image below. The idea is that this can be easily changed and set back to default using a scene.

Automation attempt:

alias: geyser_schedule
description: ""
trigger:
  - platform: time_pattern
    minutes: /1
action:
  - service: switch.turn_off
    data:
      entity_id:
        - switch.kitchen_geyser_switch_1
        - switch.mns_geyser_switch_1
        - switch.main_geyser_switch_1
  - service: switch.turn_on
    data_template:
      entity_id: >
        {% if is_state('sensor.time',
        states('input_datetime.kitchen_geyser_on_time')) and
        is_state('sensor.date', 'mon-fri') %}
          switch.kitchen_geyser_switch_1
        {% elif is_state('sensor.time',
        states('input_datetime.mns_geyser_on_time')) %}
          switch.mns_geyser_switch_1
        {% elif is_state('sensor.time',
        states('input_datetime.main_geyser_on_time')) %}
          switch.main_geyser_switch_1
        {% endif %}
  - service: switch.turn_off
    data_template:
      entity_id: >
        {% if is_state('sensor.time',
        states('input_datetime.kitchen_geyser_off_time')) and
        is_state('sensor.date', 'mon-fri') %}
          switch.kitchen_geyser_switch_1
        {% elif is_state('sensor.time',
        states('input_datetime.mns_geyser_off_time')) %}
          switch.mns_geyser_switch_1
        {% elif is_state('sensor.time',
        states('input_datetime.mns_geyser_second_off_time')) %}
          switch.mns_geyser_switch_1
        {% elif is_state('sensor.time',
        states('input_datetime.main_geyser_off_time')) %}
          switch.main_geyser_switch_1
        {% elif is_state('sensor.time',
        states('input_datetime.main_geyser_second_off_time')) %}
          switch.main_geyser_switch_1
        {% elif is_state('sensor.time',
        states('input_datetime.main_geyser_third_off_time')) %}
          switch.main_geyser_switch_1
        {% endif %}
  - service: logger.log
    data_template:
      message: >-
        Kitchen Geyser On Time: {{
        states('input_datetime.kitchen_geyser_on_time') }}, Current Time: {{
        states('sensor.time') }}

This is what’s been added to my configuration.yaml:

input_datetime:
  kitchen_geyser_on_time:
    name: Kitchen Geyser On Time
    has_date: false
    has_time: true
    initial: "12:00:00"

  kitchen_geyser_off_time:
    name: Kitchen Geyser Off Time
    has_date: false
    has_time: true
    initial: "13:30:00"

  mns_geyser_on_time:
    name: MNS Geyser On Time
    has_date: false
    has_time: true
    initial: "09:00:00"

  mns_geyser_off_time:
    name: MNS Geyser Off Time
    has_date: false
    has_time: true
    initial: "10:30:00"

  mns_geyser_second_on_time:
    name: MNS Geyser Second On Time
    has_date: false
    has_time: true
    initial: "13:30:00"

  mns_geyser_second_off_time:
    name: MNS Geyser Second Off Time
    has_date: false
    has_time: true
    initial: "15:00:00"

  main_geyser_on_time:
    name: Main Geyser On Time
    has_date: false
    has_time: true
    initial: "04:30:00"

  main_geyser_off_time:
    name: Main Geyser Off Time
    has_date: false
    has_time: true
    initial: "06:00:00"

  main_geyser_second_on_time:
    name: Main Geyser Second On Time
    has_date: false
    has_time: true
    initial: "10:30:00"

  main_geyser_second_off_time:
    name: Main Geyser Second Off Time
    has_date: false
    has_time: true
    initial: "12:00:00"

  main_geyser_third_on_time:
    name: Main Geyser Third On Time
    has_date: false
    has_time: true
    initial: "15:00:00"

  main_geyser_third_off_time:
    name: Main Geyser Third Off Time
    has_date: false
    has_time: true
    initial: "16:00:00"

I’ve tried running the automation but it doesn’t appear to do anything.
Here are 2 x log errors that I got:


Further log details:

Logger: homeassistant.components.automation.geyser_schedule
Source: components/automation/init.py:676
Integration: Automation (documentation, issues)
First occurred: December 6, 2023 at 22:13:01 (97 occurrences)
Last logged: December 6, 2023 at 23:49:01

Error while executing automation automation.geyser_schedule: not a valid value for dictionary value @ data[‘entity_id’]

and

Logger: homeassistant.components.automation.geyser_schedule
Source: helpers/script.py:1783
Integration: Automation (documentation, issues)
First occurred: December 6, 2023 at 22:13:01 (97 occurrences)
Last logged: December 6, 2023 at 23:49:01

geyser_schedule: Error executing script. Invalid data for call_service at pos 2: not a valid value for dictionary value @ data[‘entity_id’]

Any assistance would really be appreciated!

There is no need to trigger the automation every minute of every day, unless you need to turn the switches off every minute (which is what it’s doing as shown).

You can use the Input datetime entities directly in time triggers.

alias: geyser_schedule
description: ""
trigger:
  - platform: time
    at:
      - input_datetime.kitchen_geyser_on_time
      - input_datetime.main_geyser_on_time
      - input_datetime.mns_geyser_on_time
      - input_datetime.kitchen_geyser_off_time
      - input_datetime.main_geyser_off_time
      - input_datetime.main_geyser_second_off_time
      - input_datetime.main_geyser_third_off_time
      - input_datetime.mns_geyser_off_time
      - input_datetime.mns_geyser_second_off_time
action:
  - variables:
      area: "{{ (trigger.entity_id).split('.')[1].split('_')[0] }}"
      target_state: "{{ (trigger.entity_id).split('.')[1].split('_')[-2] }}"
      target: "switch.{{-area-}}_geyser_switch_1"
  - if:
      - condition: template
        value_template: "{{ target_state == 'on' }}"
    then:
      - variables:
          non_targets: |
            {% set geyser_switches = ['switch.kitchen_geyser_switch_1',
            'switch.mns_geyser_switch_1', 'switch.main_geyser_switch_1'] %}
            {{ geyser_switches| reject('eq', target) | list }}
      - service: switch.turn_off
        data: {}
        target:
          entity_id: "{{ non_targets }}"
  - service: switch.turn_{{ target_state }}
    data: {}
    target:
      entity_id: "{{ target }}"
mode: queued
1 Like

Hi I’m getting this error when the automation triggers.

The automation “Geyser On/Off Schedule” (automation.geyser_on_off_schedule) has an action that calls an unknown service: switch.turn_time.

Here is my automation code

alias: Geyser On/Off Schedule
description: ""
trigger:
  - platform: time
    at:
      - input_datetime.geyser_on_time_morning
      - input_datetime.geyser_on_time_evening
      - input_datetime.geyser_off_time_morning
      - input_datetime.geyser_off_time_evening
action:
  - variables:
      area: "{{ (trigger.entity_id).split('.')[1].split('_')[0] }}"
      target_state: "{{ (trigger.entity_id).split('.')[1].split('_')[-2] }}"
      target: switch.sonoff_10014329ac
  - if:
      - condition: template
        value_template: "{{ target_state == 'on' }}"
    then:
      - variables:
          non_targets: |
            {% set geyser_switches = ['switch.sonoff_10014329ac'] %}
            {{ geyser_switches| reject('eq', target) | list }}
      - service: switch.turn_off
        data: {}
        target:
          entity_id: "{{ non_targets }}"
  - service: switch.turn_{{ target_state }}
    data: {}
    target:
      entity_id: "{{ target }}"
mode: queued

You changed the naming convention… you need to update the template to work with the new pattern or edit the entity IDs to to match the old pattern.