I am trying to convert my hard coded irrigation automation to use and input_number helper.
I do not understand the templating syntax for input_numbers - what is the correct syntax?
alias: Sprinkler Water Cactus hard coded
description: ''
trigger:
- at: '10:00:00'
platform: time
condition:
- condition: template
value_template: '{{ now().strftime(''%j'') | int % 14 == 0}}'
action:
- data: {}
service: script.turn_on
target:
entity_id: script.sprinkler_cactus
mode: single
I want to convert the condition to use and input_number instead of the hard coded 14
If you’re testing the template using the Automation Editor’s Test button, I have bad news. It has a bug and is liable to report errors where none exist.
Copy-paste the template into the Template Editor and test it.
The Template Editor doesn’t like the doubled single-quotes ('') preferred by the Automation Editor. It accepts single-quotes ('), double-quotes ("), but not doubled single-quotes.
Try this in the Template Editor. It uses double-quotes.
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.
You marked your own post as the Solution yet it contains what I had suggested you should use. That’s not how the community uses the Solution tag. It’s assigned to the first, or best, post that identifies the cause of the problem and offers a corrective procedure. Please read the linked FAQ.
What’s the typical duration of the delay? Just a few minutes or much longer?
The reason why I ask is because if Home Assistant is restarted while the delay is counting down, it will be cancelled. It will also be cancelled whenever you execute Reload Automations and that happens in the background every time you click the Save button in the Automation Editor.
If it’s a short duration then the window of opportunity to be accidentally cancelled is narrow. But if it’s a long duration then its more vulnerable to a restart or reload. There are ways to redesign the automation without using a delay that make the automation more robust (unaffected by restart/reload).
up to about 20 minutes, so yes there can be race conditions like that. I have put in watch dog timers in all of the irrigation switches via esp_home’s feature
I would love to see your ideas for working around this issue.
( I did have a drunk test this last year when they hit a power pole and put the server in an unrunable condition. Since then I’ve also added UPSs to all my systems. )
OK, then there’s no danger of them ever being left on for hours.
Basically you would use a timer entity. When you create the timer, ensure you enable its restore option.
Start the timer (using the timer.start service call) either just before or after you execute switch.turn_on. Set the timer’s duration using the value of input_number.cactus_time.
Add an Event Trigger to detect the timer’s timer.finished event then execute switch.turn_off.