Configure Timer to start/stop with Time input

Tags: #<Tag:0x00007f73928646f8>

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.