Can't get thi Scheduler to work

Ha
I’m trying tu get my working automation schedule to work with the adition of day of the week schedule.
My initial working code is this:

- id: Sprinkler_Schedule
  alias: Sprinkler Schedule
  trigger:
  - minutes: /1
    platform: time_pattern
    seconds: '0'
  condition:
  - condition: template
    value_template: '{{ states(''sensor.time'') ==  states(''sensor.sprinklertime'')}}'
  action:
  - data:
      entity_id: switch.sprinklerzone1
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve1.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone1
    service: homeassistant.turn_off
  - data:
      entity_id: switch.SprinklerZone2
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve2.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone2
    service: homeassistant.turn_off
  - data:
      entity_id: switch.SprinklerZone3
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve3.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone3
    service: homeassistant.turn_off
  - data:
      entity_id: switch.SprinklerZone4
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve4.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone4
    service: homeassistant.turn_off
  - data:
      message: Sprinkler done.
    service: persistent_notification.create

Now I added the needed input_boolean to define the days of operation, and added some condition and, or , With template, and using state function, niether are working … any clue to hel me ?
My automation using template:

- id: Sprinkler_Schedule
  alias: Sprinkler Schedule
  trigger:
  - minutes: /1
    platform: time_pattern
    seconds: '0'
  condition:
    condition: and
    conditions:
    - condition: template
      value_template: '{{ states(''sensor.time'') ==  states(''sensor.sprinklertime'')}}'
    - condition: or
      conditions:
      - condition: template
        value_template: '{{ states(''input_boolean.monday'') == on }} and states(''sensor.dayoftheweek'') == Monday }}'
      - condition: template
        value_template: '{{ states(''input_boolean.tuesday'') == on }} and states(''sensor.dayoftheweek'') == Tuesday }}'
      - condition: template
        value_template: '{{ states(''input_boolean.wednesday'') == on }} and states(''sensor.dayoftheweek'') == Wednesday }}'
      - condition: template
        value_template: '{{ states(''input_boolean.thursday'') == on }} and states(''sensor.dayoftheweek'') == Thursday }}'
      - condition: template
        value_template: '{{ states(''input_boolean.friday'') == on }} and states(''sensor.dayoftheweek'') == Friday }}'
      - condition: template
        value_template: '{{ states(''input_boolean.saturday'') == on }} and states(''sensor.dayoftheweek'') == Saturday }}'
      - condition: template
        value_template: '{{ states(''input_boolean.sunday'') == on }} and states(''sensor.dayoftheweek'') == Sunday }}'
  action:
  - data:
      entity_id: switch.sprinklerzone1
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve1.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone1
    service: homeassistant.turn_off
  - data:
      entity_id: switch.SprinklerZone2
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve2.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone2
    service: homeassistant.turn_off
  - data:
      entity_id: switch.SprinklerZone3
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve3.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone3
    service: homeassistant.turn_off
  - data:
      entity_id: switch.SprinklerZone4
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve4.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone4
    service: homeassistant.turn_off
  - data:
      message: Sprinkler done.
    service: persistent_notification.create

My automation using States :

- id: Sprinkler_Schedule
  alias: Sprinkler Schedule
  trigger:
  - minutes: /1
    platform: time_pattern
    seconds: '0'
  condition:
    condition: and
    conditions:
    - condition: template
      value_template: '{{ states(''sensor.time'') ==  states(''sensor.sprinklertime'')}}'
   - condition: or
     conditions:
     - condition: state
       entity_id: input_boolean.monday
       state: 'on'
     - condition: and
       conditions:
       - condition: state
         entity_id: sensor.dayoftheweek
         state: Monday
    - condition: or
      conditions:
      - condition: state
        entity_id: input_boolean.tuesday
        state: 'on'
      - condition: and
        conditions:
        - condition: state
          entity_id: sensor.dayoftheweek
          state: Tuesday
    - condition: or
      conditions:
      - condition: state
        entity_id: input_boolean.wednesday
        state: 'on'
      - condition: and
        conditions:
        - condition: state
          entity_id: sensor.dayoftheweek
          state: Wednesday
     - condition: or
       conditions:
       - condition: state
         entity_id: input_boolean.thursday
         state: 'on'
       - condition: and
         conditions:
         - condition: state
           entity_id: sensor.dayoftheweek
           state: Thursday
     - condition: or
       conditions:
       - condition: state
         entity_id: input_boolean.friday
         state: 'on'
       - condition: and
         conditions:
         - condition: state
           entity_id: sensor.dayoftheweek
           state: Friday
     - condition: or
       conditions:
       - condition: state
         entity_id: input_boolean.saturday
         state: 'on'
       - condition: and
         conditions:
         - condition: state
           entity_id: sensor.dayoftheweek
           state: Saturday
     - condition: or
       conditions:
       - condition: state
         entity_id: input_boolean.sunday
         state: 'on'
       - condition: and
         conditions:
         - condition: state
           entity_id: sensor.dayoftheweek
           state: Sunday
  action:
  - data:
      entity_id: switch.sprinklerzone1
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve1.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone1
    service: homeassistant.turn_off
  - data:
      entity_id: switch.SprinklerZone2
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve2.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone2
    service: homeassistant.turn_off
  - data:
      entity_id: switch.SprinklerZone3
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve3.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone3
    service: homeassistant.turn_off
  - data:
      entity_id: switch.SprinklerZone4
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve4.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone4
    service: homeassistant.turn_off
  - data:
      message: Sprinkler done.
    service: persistent_notification.create
- id: Sprinkler_Schedule
  alias: Sprinkler Schedule
  trigger:
    platform: template
    value_template: >
      {% set today = 'input_boolean.' ~ (states('sensor.dayoftheweek') | lower) %}
      {{ states('sensor.time') == states('sensor.sprinklertime') and is_state(today, 'on') }}
  action:
  - data:
      entity_id: switch.sprinklerzone1
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve1.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone1
    service: homeassistant.turn_off
  - data:
      entity_id: switch.SprinklerZone2
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve2.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone2
    service: homeassistant.turn_off
  - data:
      entity_id: switch.SprinklerZone3
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve3.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone3
    service: homeassistant.turn_off
  - data:
      entity_id: switch.SprinklerZone4
    service: homeassistant.turn_on
  - delay: 00:0{{ states.input_number.valve4.state | int }}:00
  - data:
      entity_id: switch.SprinklerZone4
    service: homeassistant.turn_off
  - data:
      message: Sprinkler done.
    service: persistent_notification.create

Explanation:

  • The first line of value_template creates a variable called today. This variable contains a string with the current day. Today is Sunday so it will look like this: input_boolean.sunday
  • The second line checks if the current time is equal to sprinklertime and if input_boolean.sunday is on.
  • If all tests are true then the automation proceeds to execute the action.
  • Because value_template contains the sensor.time entity, it will be evaluated every minute (because sensor.time changes state every minute).

Note:
I don’t believe the delay templates need an int filter (the result of a template is always a string). Nevertheless, I Ieft them as-is; you can remove them if you wish. They’re needed because the state value of an input_number is a string in the form of a float.

I’ve got a sensor template to format the output of my hour and minutes input_number slider to the 00:00:00 format of the time sensor, so it add a leading 0 in case the chosen value are one digit.
This part work allright, my problem is with the “and”-“or” conditions

- platform: template
  sensors:
    sprinklertime:
      friendly_name: 'Sprinkler Time'
      value_template: '{% if states.input_number.sprinklerhour.state|float < 10%}0{% endif %}{{ states.input_number.sprinklerhour.state | int }}:{% if states.input_number.sprinklerminutes.state|float < 10%}0{% endif %}{{ states.input_number.sprinklerminutes.state |int }}'

The conditions are not required if you use the Template Trigger I shared in my previous post.

The template of sensor.sprinklertime can be reduced to this:

- platform: template
  sensors:
    sprinklertime:
      friendly_name: 'Sprinkler Time'
      value_template: >
        {{ '{:02d}:{:02d}'.format(states('input_number.sprinklerhour')|int, states('input_number.sprinklerminutes')|int) }}

Greate, it’s workin as intended :rofl: :grinning:
Thank you so much

1 Like