Configure Timer to start/stop with Time input

Hello I am fairly new to Home Assistant and this is my first post so if I miss something please excuse me. I need help with I believe might be a value-template issue. I am trying to automate a light by time input. Here is what I have so far. I have a switch that is working and when I execute the automation manually in Home Assistant that also works. The issue is when I ask it to start based on time input it does not work or create any error logs that I can find. I checked to make sure all entities are in place and they are.

################################################################################

Timer Input Box Information

################################################################################
input_boolean:
chicken_coop_light_timer_on_enabled:
name: “chicken_coop_light ON timer”
initial: off
icon: mdi:timer
chicken_coop_light_timer_off_enabled:
name: “chicken_coop_light OFF timer”
initial: off
icon: mdi:timer-off

input_datetime:
turn_chicken_coop_light_on_time:
name: “Turn Chicken Coop Light on at”
has_time: true
has_date: false
initial: “06:00”
turn_chicken_coop_light_off_time:
name: “Turn Chicken Coop Light off at”
has_time: true
has_date: false
initial: “20:00”

################################################################################

Chicken Coop Timer Automation Information

################################################################################
#TURN CHICKEN COOP LIGHT ON AT SPECIFIC TIME

  • id: ‘ChickenCoopLightOn’
    alias: Turn on Chicken Coop Light with Timer
    trigger:
    platform: template
    value_template: “{{ states(‘sensor.time’) == (state_attr(‘input_datetime.turn_chicken_coop_light_on_time’, ‘timestamp’) | int | timestamp_custom(’%H:%M’, False)) }}”
    condition:
    • condition: state
      entity_id: input_boolean.chicken_coop_light_timer_on_enabled
      state: ‘on’
      action:
      entity_id: switch.chickencoop
      service: switch.turn_on

#TURN CHICKEN COOP LIGHT OFF AT SPECIFIC TIME

  • id: ‘ChickenCoopLightOff’
    alias: Turn off Chicken Coop Light with Timer
    trigger:
    platform: template
    value_template: “{{ states(‘sensor.time’) == (state_attr(‘input_datetime.turn_chicken_coop_light_on_time’, ‘timestamp’) | int | timestamp_custom(’%H:%M’, False)) }}”
    condition:
    • condition: state
      entity_id: input_boolean.chicken_coop_light_timer_on_enabled
      state: ‘on’
      action:
      entity_id: switch.chickencoop
      service: switch.turn_off
      image

Any help would be greatly appreciated

Welcome. Please take a look at point 11 here and edit your post accordingly.

Thank you for pointing that out Tom

Let me try this again

################################################################################
## Timer Input Box Information
################################################################################
input_boolean:
  chicken_coop_light_timer_on_enabled:
    name: "chicken_coop_light ON timer"
    initial: off
    icon: mdi:timer
  chicken_coop_light_timer_off_enabled:
    name: "chicken_coop_light OFF timer"
    initial: off
    icon: mdi:timer-off
input_datetime:
  turn_chicken_coop_light_on_time:
    name: "Turn Chicken Coop Light on at"
    has_time: true
    has_date: false
    initial: "06:00"
  turn_chicken_coop_light_off_time:
    name: "Turn Chicken Coop Light off at"
    has_time: true
    has_date: false
    initial: "20:00"
################################################################################
## Chicken Coop Timer Automation Information
################################################################################
#TURN CHICKEN COOP LIGHT ON AT SPECIFIC TIME
- id: 'ChickenCoopLightOn'
  alias: Turn on Chicken Coop Light with Timer
  trigger:
    platform: template
    value_template: "{{ states('sensor.time') == (state_attr('input_datetime.turn_chicken_coop_light_on_time', 'timestamp') | int | timestamp_custom('%H:%M', False)) }}"
  condition:
  - condition: state
    entity_id: input_boolean.chicken_coop_light_timer_on_enabled
    state: 'on'
  action:
    entity_id: switch.chickencoop
    service: switch.turn_on
#TURN CHICKEN COOP LIGHT  OFF AT SPECIFIC TIME
- id: 'ChickenCoopLightOff'
  alias: Turn off Chicken Coop Light with Timer
  trigger:
    platform: template
    value_template: "{{ states('sensor.time') == (state_attr('input_datetime.turn_chicken_coop_light_on_time', 'timestamp') | int | timestamp_custom('%H:%M', False)) }}"
  condition:
  - condition: state
    entity_id: input_boolean.chicken_coop_light_timer_on_enabled
    state: 'on'
  action:
    entity_id: switch.chickencoop
    service: switch.turn_off

See here for a solution:

Though I’d do it like this:

value_template: "{{ states('sensor.time') == states('input_datetime.switch_off')[0:5] }}"

Also, have you seen this?

Hello, thank you for you reply and suggestion. I tried it and it did not work like that but I now see the issue. The input_boolean state is not turning on/off it stays off, so I adjusted that in the configuration and it is now working.

#Input Boolean
input_boolean:
  chicken_coop_light_timer_on_enabled:
    name: "chicken_coop_light ON timer"
    initial: off
    icon: mdi:timer
  chicken_coop_light_timer_off_enabled:
    name: "chicken_coop_light OFF timer"
    initial: off
    icon: mdi:timer-off
#Input Time
input_datetime:
  turn_chicken_coop_light_on_time:
    name: "Turn Chicken Coop Light on at"
    has_time: true
    has_date: false
    initial: "06:00"
  turn_chicken_coop_light_off_time:
    name: "Turn Chicken Coop Light off at"
    has_time: true
    has_date: false
    initial: "20:00"
#TURN CHICKEN COOP LIGHT ON AT SPECIFIC TIME
- id: 'ChickenCoopLightOn'
  alias: Turn on Chicken Coop Light with Timer
  trigger:
    platform: template
    value_template: "{{ states('sensor.time') == (state_attr('input_datetime.turn_chicken_coop_light_on_time', 'timestamp') | int | timestamp_custom('%H:%M', False)) }}"
  condition:
  - condition: state
    entity_id: input_boolean.chicken_coop_light_timer_on_enabled
    state: 'off'
  action:
    entity_id: switch.chickencoop
    service: switch.turn_on
#TURN CHICKEN COOP LIGHT  OFF AT SPECIFIC TIME
- id: 'ChickenCoopLightOff'
  alias: Turn off Chicken Coop Light with Timer
  trigger:
    platform: template
    value_template: "{{ states('sensor.time') == (state_attr('input_datetime.turn_chicken_coop_light_off_time', 'timestamp') | int | timestamp_custom('%H:%M', False)) }}"
  condition:
  - condition: state
    entity_id: input_boolean.chicken_coop_light_timer_off_enabled
    state: 'off'
  action:
    entity_id: switch.chickencoop
    service: switch.turn_off

I do have another issue that I see. When I restart Home Assistant, the input_time, defaults to what is set in the configuration.yaml file and not with what is set on the “Turn Chicken Coop Light on at” input field in Home Assistant Card. Does anyone know how the time, that is set, in the “Turn Chicken Coop Light on at” input field in Home Assistant Card can be retained even after a restart of Home Assistant?

image

input_datetime:
  turn_chicken_coop_light_on_time:
    name: "Turn Chicken Coop Light on at"
    has_time: true
    has_date: false
    initial: "06:00"
  turn_chicken_coop_light_off_time:
    name: "Turn Chicken Coop Light off at"
    has_time: true
    has_date: false
    initial: "20:00"

If you delete the initial value, it will restore the previous state.

1 Like

That worked. Thank you all this has been solved.

I used to do a similar thing with input booleans enabling my automations. Now I just turn the automations on or off. No need for the input booleans or conditions.

1 Like

@tom_l this is exactly what I’m looking to automate my water boiler. Please would you share the code? thanks

Card (you will need the custom button card and custom hui-element cards installed):

entities:
  - entity: automation.upstairs_scheduled_vacuum
    state_color: true
  - entity: automation.downstairs_scheduled_vacuum
    state_color: true
  - entity: automation.vacuum_notifications
    icon: mdi:message-text
    name: Enable State Notifications
    state_color: true
  - entity: input_datetime.vac_on_time
    name: Start Time
  - card_type: horizontal-stack
    cards:
      - entity: input_boolean.vac_mon
        name: Mon
        template: day_button
        type: custom:button-card
      - entity: input_boolean.vac_tue
        name: Tue
        template: day_button
        type: custom:button-card
      - entity: input_boolean.vac_wed
        name: Wed
        template: day_button
        type: custom:button-card
      - entity: input_boolean.vac_thu
        name: Thu
        template: day_button
        type: custom:button-card
      - entity: input_boolean.vac_fri
        name: Fri
        template: day_button
        type: custom:button-card
      - entity: input_boolean.vac_sat
        name: Sat
        template: day_button
        type: custom:button-card
      - entity: input_boolean.vac_sun
        name: Sun
        template: day_button
        type: custom:button-card
    type: custom:hui-element
type: entities

Button Template (place in top of raw edit mode):

button_card_templates:
  day_button:
    color_type: icon
    hold_action:
      action: none
    show_label: false
    show_name: true
    show_state: false
    state:
      - icon: mdi:checkbox-marked-circle
        styles:
          card:
            - border: solid 1px var(--paper-item-icon-active-color)
            - box-shadow: 0px 0px 10px 3px var(--paper-item-icon-active-color)
          name:
            - color: var(--primary-text-color)
        value: 'on'
      - icon: mdi:cancel
        styles: null
        value: 'off'
    styles:
      card:
        - border-radius: 10px
        - border: solid 1px var(--primary-color)
        - box-shadow: none
        - padding: 6px 0px
        - margin: 0px 0px
        - '--ha-card-background': rgba(0, 0, 0, 0)
      grid:
        - grid-template-areas: '"i" "n"'
        - grid-template-rows: 33% auto
        - grid-template-columns: auto
      icon:
        - width: 28px
      name:
        - justify-self: middle
        - align-self: end
        - font-size: 14px
        - padding: 0px 0px
        - color: var(--secondary-text-color)
    tap_action:
      action: toggle

Automation:

- id: f8166a12-f880-4e03-b08a-6c8aa4e4bcb3
  alias: Upstairs Scheduled Vacuum
  trigger:
    platform: time
    at: input_datetime.vac_on_time
  condition:
  - condition: state
    entity_id: binary_sensor.roborock_today
    state: 'on'
  action:
  - service: vacuum.start
    entity_id: vacuum.robovac_upstairs

Binary sensor:

- platform: template
  sensors:
    roborock_today:
      friendly_name: "Roborock Today"
      value_template: >
        {% set day = states('sensor.day_today') %}
        {{ is_state('input_boolean.vac_' ~ day, 'on') and ( is_state('automation.upstairs_scheduled_vacuum', 'on') or is_state('automation.downstairs_scheduled_vacuum', 'on') ) }}

Input booleans:

vac_mon:
  name: Monday
  icon: mdi:calendar

vac_tue:
  name: Tuesday
  icon: mdi:calendar

vac_wed:
  name: Wednesday
  icon: mdi:calendar

vac_thu:
  name: Thursday
  icon: mdi:calendar

vac_fri:
  name: Friday
  icon: mdi:calendar

vac_sat:
  name: Saturday
  icon: mdi:calendar

vac_sun:
  name: Sunday
  icon: mdi:calendar
2 Likes

Hi @tom_l ,
I am a beginner of HA, and I ask for help if possible.
I was trying to insert this beautiful card in lovelace to schedule my vacuu.,
I entered the first part, but I don’t understand where to insert the other 4 program blocks:

  • Button Template
  • Automation (I think in a new automation) but which 'id should I enter
  • Binary sensor
  • Input booleans

thank you

Is there a how-to for beginners for implementing this kind of scheduling?

Thanks.

Read the posts above. Or use this: