Cosmin.FRC
(Cosmin F.)
September 8, 2024, 3:41pm
1
Hi guys,
I need to create a template sensor (I guess) to show the remaining time for my sprinkler system.
To set the irrigation time I use an input_number helper, but the irrigation time is not the same every day, it depends on other variables like precipitation and previous day highest temperature. Could this be possible?
BR,
Cosmin
jchh
((not John))
September 8, 2024, 3:59pm
2
Yes, if the end-time is predictable (can be calculated) you can probably template it.
If you share the variables and the logic you want to use, we can help create your sensor.
Sir_Goodenough
((SG) WhatAreWeFixing.Today)
September 8, 2024, 4:35pm
3
Cosmin.FRC
(Cosmin F.)
September 8, 2024, 4:46pm
4
Let’s say yesterday highest temp. was 30°C and no rain, today the sprinklers will run for 30 minutes. If yesterday the highest temp. was 25°C and also no rain, the sprinklers would run for 20 min.
That is the logic of the automation and time input.
jchh
((not John))
September 8, 2024, 4:52pm
5
Ok, that’s quite easy.
Can you share your sensors (max* temp yesterday, rain yesterday etc)?
[Edit: typos*]
Cosmin.FRC
(Cosmin F.)
September 8, 2024, 5:54pm
6
Yes I can, but the pump (switch) running time is set by an script wich uses an input_number to set the time delay. So I think this input_number is the reference, right? Or am I wrong? The whole automation is a bit more complex and uses a bunch of template sensors, binary sensors, scripts, helpers. What exactly should I share?
Cosmin.FRC
(Cosmin F.)
September 8, 2024, 6:12pm
7
Thanks. I already have the automation working, I only need a sensor to show me the time remaining till the end of the irrigation time. Just like a countdown till the end of the irrigation time.
Hellis81
(Hellis81)
September 8, 2024, 6:28pm
8
Why not just use a timer instead
It gives you a visible countdown state and will survive reloads and reboots (as delays won’t).
jchh
((not John))
September 8, 2024, 6:37pm
9
Share the script and the automation.
Cosmin.FRC
(Cosmin F.)
September 8, 2024, 6:42pm
10
I need to input the time for each scenario.
Cosmin.FRC
(Cosmin F.)
September 8, 2024, 6:44pm
11
Automation:
alias: “Aspersoare: Verifică dacă trebuie irigat”
description: Verifică dacă trebuie pornită irigarea.
trigger:
platform: time
at: “07:30:00”
condition:
condition: time
weekday:
choose:
conditions:
condition: numeric_state
entity_id: input_number.aspersoare_temperatura_maxima_masurata
above: 30
condition: numeric_state
entity_id: sensor.aspersoare_precipitatii_totale
below: “20.1”
sequence:
data:
value: 40
target:
entity_id: input_number.aspersoare_durata_irigare
action: input_number.set_value
data: {}
action: script.aspersoare_pornire_irigare
conditions:
condition: numeric_state
entity_id: input_number.aspersoare_temperatura_maxima_masurata
above: 25
below: 30
condition: numeric_state
entity_id: sensor.aspersoare_precipitatii_totale
below: “15.1”
sequence:
data:
value: 25
target:
entity_id: input_number.aspersoare_durata_irigare
action: input_number.set_value
data: {}
action: script.aspersoare_pornire_irigare
conditions:
condition: numeric_state
entity_id: input_number.aspersoare_temperatura_maxima_masurata
above: 20
below: 25
condition: numeric_state
entity_id: sensor.aspersoare_precipitatii_totale
below: “10.1”
sequence:
data:
value: 15
target:
entity_id: input_number.aspersoare_durata_irigare
action: input_number.set_value
data: {}
action: script.aspersoare_pornire_irigare
conditions:
condition: numeric_state
entity_id: input_number.aspersoare_temperatura_maxima_masurata
above: 15
below: 20
condition: numeric_state
entity_id: sensor.aspersoare_precipitatii_totale
below: “10.1”
sequence:
data:
value: 10
target:
entity_id: input_number.aspersoare_durata_irigare
action: input_number.set_value
data: {}
action: script.aspersoare_pornire_irigare
default:
mode: single
Script:
alias: “Aspersoare: Pornire irigare”
sequence:
data:
message: >-
Aspersoarele au pornit pentru {{
states(“input_number.aspersoare_durata_irigare”) | int }} minute pe
fiecare zonă.
action: notify.mobile_app_s_galaxy_s24_ultra
type: turn_on
device_id: e5e7ea5cf32c84f67d7e7bd5aa601544
entity_id: d75809e12a1a2d8afac75d4eb72c6539
domain: switch
delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
type: turn_on
device_id: 9cdec95d0d469e873707a0dc0e74550d
entity_id: 7d6abd6f08e1fc73fa24045c352910c8
domain: switch
delay:
minutes: |
{{ states(“input_number.aspersoare_durata_irigare”) | int }}
type: turn_off
device_id: 9cdec95d0d469e873707a0dc0e74550d
entity_id: 7d6abd6f08e1fc73fa24045c352910c8
domain: switch
type: turn_on
device_id: 9cdec95d0d469e873707a0dc0e74550d
entity_id: f9d029e7e4d7d1b5a3297ea148dd48b6
domain: switch
delay:
minutes: |
{{ states(“input_number.aspersoare_durata_irigare”) | int }}
type: turn_off
device_id: 9cdec95d0d469e873707a0dc0e74550d
entity_id: f9d029e7e4d7d1b5a3297ea148dd48b6
domain: switch
type: turn_off
device_id: e5e7ea5cf32c84f67d7e7bd5aa601544
entity_id: d75809e12a1a2d8afac75d4eb72c6539
domain: switch
data: {}
enabled: true
action: script.aspersoare_reseteaza_valorile
data:
message: Irigare finalizată!
title: Aspersoare
action: notify.mobile_app_s_galaxy_s24_ultra
mode: single
icon: mdi:sprinkler
Hellis81
(Hellis81)
September 8, 2024, 7:17pm
12
And your saying a timer can’t be changed?
Cosmin.FRC
(Cosmin F.)
September 8, 2024, 7:25pm
14
I don’t know. Never used it in scripts or automations.
Hellis81
(Hellis81)
September 8, 2024, 7:28pm
15
Can you perhaps think very hard and you might figure it out.
A good clue is that I suggested timer.
If you want to cheat then you are allowed to open the documentations and read.
Cosmin.FRC
(Cosmin F.)
September 8, 2024, 7:33pm
16
I’ve read the documentation and I will give it a try. I will make a test automation to see how it performs. Thanks.
I use this in a script to set a variable time for my grill timer:
data:
duration: 00:{{ states('input_number.grill_time') | int }}:00
target:
entity_id: timer.grill
action: timer.start
Very simplistic, though, because I only need to set it between 1 and 99 minutes - and the card I’m using to show it even ‘converts’ it to h:mm:ss when I set it for more than 59min.
type: custom:timer-bar-card
entities:
- entity: timer.grill
name: Time
- entity: input_select.announce_timer
name: 'Action:'
bar_direction: rtl
bar_foreground: '#eee'
bar_background: 'var(--mdc-theme-primary, #620088)'
sync_issues: ignore
tom_l
September 8, 2024, 9:22pm
18
Here’s how I do it with an input number:
template:
- sensor:
- name: "Zone 1 Time Remaining"
unique_id: 79d11323-4107-40c3-bfb6-2e1dcf65e711
icon: "mdi:timelapse"
unit_of_measurement: "min"
state: >
{% if is_state('switch.zone_1', 'on') %}
{{ [ (states('input_number.zone_1_run_time')|int(0) - (as_timestamp(now()) - as_timestamp(states.switch.zone_1.last_changed))/60)|round(0, default = 0) ,0 ]|max }}
{% else %}
0
{% endif %}
Cosmin.FRC
(Cosmin F.)
September 12, 2024, 8:56pm
19
Hi,
Thanks for your answers. I will try your variants but for the moment I am having some wardware problems. I will post as soon as I work them out.
BR,
Cosmin