I want to be able to activate my sprinkler on a schedule. For this i want to use a start time, and a duration:
For testing purposes i switch on and off one of my lights.
Activating the light (sprinkler) is not a problem, for this, i have created a time sensor:
- platform: template
sensors:
time_1_start_time:
friendly_name: "Start Time"
device_class: timestamp
value_template: >
{% set entities = "input_number.timer_1_start_hour", "input_number.timer_1_start_minutes" %}
{{ today_at(entities | map('states') | map('int') | list | join(":")) }}
This is the automation that works just fine:
- id: "1769102370985"
alias: Timer 1 Start Time
description: ""
trigger:
- platform: time
at: sensor.time_1_start_time
condition:
- condition: template
value_template: "{{ is_state('input_boolean.timer_1_' ~ ['mon','tue','wed','thu','fri','sat','sun'][now().weekday()], 'on') }}"
action:
- service: light.turn_on
target:
entity_id:
- light.kuche_1
data: {}
mode: single
However now i need to calculate the end time in order to use it in an automation, this i have no idea how to do, can anyone help me?
Schedule helper? That would give you a simple on and off to use as automation triggers.
I would prefer to use another sensor, since i already have it set up that way.
+1 to @Stiltjack , a times of the day
helper will let you set the start time and end time.
If you really want a duration … Perhaps you have multiple irrigation zones and you want one start and the duration on multiple zones, them use a datetime helper set to time only.
you can then find the end time by adding the duration…
{{ states('input_datetime.start_time') + timedelta(minutes=states('input_number.duration') }}
this is essentially the same as what you have but combined the hour and minute helper into a single time helper
I am new to HA and not really sure what you mean. By schedule helper, are you refering to this: Schedule - Home Assistant?
How would i be able to set the values of the schedule dynamically?
All the helpers can be made through the gui in the same place that you probably used to make the input_number helpers that you have above.
I would use a schedule helper if you want different start times on different days.
I would use times of day helper if you wish to specify a time range and have it be the same time range no matter what day
I would use datetime + number helper if you want to specify the start time and a duration
All helpers are designed for you to change the values easily and through the UI to fiddle with them readily