Help to link automation together via template

Hi! i have a idea i want to develop but turn out its way more complex than i thought…, i made a automation to let the user enter the hour to turn the heating system OFF and to turn the system ON again, so far its working

code;

  alias: 'Horaire 1 ON '
  description: ''
  trigger:
  - platform: time
    at: input_datetime.horaire_on
    id: input_datetime.horaire_on
  condition: []
  action:
  - service: switch.turn_on
    target:
      entity_id:
      - switch.eau
      - switch.plancher
  mode: single
- id: '1641587395939'
  alias: Horaire 1 Off
  description: ''
  trigger:
  - platform: time
    at: input_datetime.horaire_off
    id: input_datetime.horaire_off
  condition: []
  action:
  - service: switch.turn_off
    target:
      entity_id:
      - switch.eau
      - switch.plancher
  mode: single
- id: '1641587490579'
  alias: Horaire 1 ON switch
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.activation
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: automation.turn_on
    target:
      entity_id:
      - automation.horaire_1_on
      - automation.horaire_off_1
  mode: single
- id: '1641587682135'
  alias: Horaire 1 Off switch
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.activation
    from: 'on'
    to: 'off'
  condition: []
  action:
  - service: automation.turn_off
    target:
      entity_id:
      - automation.horaire_1_on
      - automation.horaire_off_1
  mode: single
- id: '1641588836184'
  alias: Horaire 2 ON
  description: ''
  trigger:
  - platform: time
    at: input_datetime.horaire_2_on
  condition: []
  action:
  - service: switch.turn_on
    target:
      entity_id:
      - switch.eau
      - switch.plancher
  mode: single
- id: '1641588881434'
  alias: Horaire 2 OFF
  description: ''
  trigger:
  - platform: time
    at: input_datetime.horaire_2_off
  condition: []
  action:
  - service: switch.turn_off
    target:
      entity_id:
      - switch.eau
      - switch.plancher
  mode: single
- id: '1641588937454'
  alias: Horaire 2 Switch ON
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.activation_2
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: automation.turn_on
    target:
      entity_id:
      - automation.horaire_2_on
      - automation.horaire_2_off
  mode: single
- id: '1641588990528'
  alias: Horaire 2 Switch OFF
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.activation_2
    from: 'on'
    to: 'off'
  condition: []
  action:
  - service: automation.turn_off
    target:
      entity_id:
      - automation.horaire_2_on
      - automation.horaire_2_off
  mode: single
- id: '1641709497154'

so this board:

tableau1

let the user set the hour to control those switch:

tableau2

and my objective is to make the template wich is reading the mail with hours data to use this data and change the hour of the first board…, the mail reader is already working, its linking the data of the mail to the automation i need help with

template:

template:
- sensor:
  - name: "hour1_OFF"
    unit_of_measurement: "h"
    state: >
       {{ state_attr('sensor.energy_gmail','body')
         | regex_findall_index("lieu de: ([0-9]+) h") }}
  - name: "hour1_ON"
    unit_of_measurement: "h"
    state: >
        {{ state_attr('sensor.energy_gmail','body')
          | regex_findall_index("a ([0-9]+) h") }}

The “mail reader” read the value: 3 h for hour1_OFF and 5 h for hour1_ON and i don’t know what kind of template i could do to make it interact to take this value and set it up in the first board :thinking:

READER

state:

[sensor.hour1_OFF(Home Assistant)

hour1 3
unit_of_measurement: h friendly_name: hour1off

sensor.hour1_ON

hour2 5 unit_of_measurement: h friendly_name: hour1on

In the developper tool i tried some test but am still lost to make the link between the mail data to the board…

{% set time = {
  "hour1_ON": 5,
  "hour1_OFF": 2,
  
} %}

this month: : {{ now().month }} , to this day: {{now().day+1}} , the system turn off at {{ time.hour1_OFF }} the system turn on at {{ time.hour1_ON }}  

output:

this month: : 1 , to this day: 11 , the system turn off at 2 the system turn on at 5 h 

So all the 3 ‘‘system’’ are working but now i can’t figure out to link the 3 systems together… :thinking: any advice would be helpfull! :slight_smile: , am a beginner and am trying my best to learn

Thank you in advance!

I’m itching to take that massive load of automations and reduce them to a single automation of at most 1/3 of the lines. Additionally, to deal with the horrible idea of turning off automations in other automations - that is never necessary, you simply use the state of the input_booleans in the conditions of the automation to prevent it from running.

In answer to your main question though - templating, lots of templating.

{% set h_on_1 = states('sensor.hour1_on')|int(0) %}
{% set t = now() %}
{{ t.hour == h_on_1 }}
{% set h_off_1 = states('sensor.hour1_off')|int(0) %}
{% set t = now() %}
{{ t.hour == h_off_1 }}

They are your template triggers.