haven’t been using HA for long, moved from Dom to HA.
I’m also NOT a programmer. But I have a task that I’m sure requires a script of some sort.
I use HA to automate my grow room. Nothing else.
The other day we had a power cut and the automation I had for the lights didn’t run as power was restored after the timer event. Obviously have 2 events for the lights, one for on and one for off.
What I would like is a single script that has 2 variables LightsOn and LightsOff and I would like this to be the only place I set the timers. The timers need adjusting during the grow cycle and I don’t want to adjust in multiple locations.
The script also needs to do some sanity checking. for example if we have a power cut and when it comes back on it checks the time to see if the lights should be on or off and sets the state of the light switch appropriately.
Information on my install
Installation method Home Assistant OS
Core 2025.12.4
Supervisor 2025.12.3
Operating System 16.3
Frontend 20251203.3
The light switch is a tasmota device called RelayBoard and the switch is called Lights.
As I have said above, I’m NOT a programmer, I would rather not attempt any programming. Simply put, I do what I do and I do it well, for everything else I get someone who IS good at what I want done and I ask them if they would like to do it for me. So please don’t flame an old retiree.
Include a Time Pattern trigger . Habitually using time pattern triggers is usually something to avoid, but it sounds like the demand on this Home Assistant instance will be pretty low, so it shouldn’t be an issue.
Trigger off the state of the switch changing from ‘unavailable’. Many entities will have a state of “unavailable” if their device disconnects from the network, at startup, or when their integration is reloaded. That makes it a pretty good indicator that you may want to check the time for the lights.
The HA analog to Domoticz’ variables are Helpers. “Date and/or Time” Helpers come in three types, make sure to select Time when you set up the Helpers, since that is what will suit your purposes.
You should end up with two entities input_dateime.lightson and input_dateime.lightsoffthat you can use in your Time triggers and conditions, and whose values can be modified through dashboard cards or scripts/automations.
There are multiple ways all of this could be assembled into an automation…
Here's one way... just make sure to swap in your actual entity IDs if they don't already match
description: "Turn lights on and off based on the values from Time Helpers with redundant triggers in case of power failure etc."
mode: single
triggers:
- trigger: time
at: input_datetime.lightson
id: turn_on
- trigger: time
at: input_datetime.lightsoff
id: turn_off
- trigger: homeassistant
event: start
- trigger: time_pattern
hours: /1
conditions: []
actions:
- choose:
- conditions:
- condition: or
conditions:
- condition: trigger
id: turn_on
- condition: time
after: input_datetime.lightson
before: input_datetime.lightsoff
sequence:
- action: switch.turn_on
metadata: {}
target:
entity_id:
- switch.lights
data: {}
- conditions:
- condition: or
conditions:
- condition: trigger
id: turn_off
- condition: not
conditions:
- condition: time
after: input_datetime.lightson
before: input_datetime.lightsoff
sequence:
- action: switch.turn_off
metadata: {}
target:
entity_id:
- switch.lights
data: {}
OK. so it seems I may have solved this issue. After floundering around I discovered blueprints.
I installed the Smart Light blueprint, and after a bit of faffing about I managed to configure it and got it working. Now I just have to test it under a power failure enviroment during the switch on/off period.
Not sure you read the above. I’m not a programmer. And I clearly don’t know what I’m doing, and AI isn’t something a person of my age has any knowledge of.
What you are trying to do it really pretty basic even for a non-programmer like myself.
Millions of non-programmers using AI to write code. AI codes 99% of my complex automation and blueprints. And what amazing, is you can actually learn from the code the AI builds for you
Your choices are…
take an hour or two to figure out AI to write this pretty simple automation you want
learn from the help Dig gave you (which is more than he gives most that have not tried to figure it out themselves)
hire someone
hope that someone will write it for you for free (which is likely what you are doing now)
Oh, and I dont know what a ‘person of my age’ means… but its not relevant, you are on this forum so you have enough tech know-how to use AI.
I was around far before the Internet existed, when Pong was modern tech
glad you did it. next time it will take you 1 day, then the time after that 3 hours. It does get far easier/quicker. I do complex blueprints code that is 1800 to 2800 lines and it takes me 3 days but ~8 total hours.