New to this arena of HA,
I am looking to turn a light strip on between 45 minutes before sunset and 1 hour after sunset using a Philips hue sensor
I will run another automation after that however for now I don’t seem to be getting it right
The light only turns on once then never again
In all honesty i may be doing things out of sync with how HA does however I would appreciate any guidance to assist me on this journey
please put code in via preformatted text instead of a screenshot. it makes it easier for us to edit your code.
your conditions are kinda wacky. you have both before sunset and after sunset in the first condition. which do you mean?
you should also not be using device_id.
you said you want to turn on a light strip 45min before sunset and 1 hour after. is that what you really want? your automation seems to say you want to turn on the light on a motion detection.
thank you for the quick response, appreciated
I am using the visual editor so this is what it put out when I changed to YAML
basically I want the system to only trigger in between 45min BEFORE sunset and 1 hour AFTER sunset on trigger from motion sensor
I am appreciate the fixing my code part however I don’t feel I will learn why and how if someone changes is for me, so if at all possible please could I understand why the code needs to change and what the recommended changes would be, I hope that doesnt sound unappreciative.
Conditions are AND by default, so it looks to me as if your automation will only run if it is both 45 minutes before sunset AND 1 hour after sunset - in other words, never.
So what would the trigger be? Sunset or motion or both
and how would I then create the conditions around the timings I would prefer and how would I make it happen every time the motion sensor is triggered during that time frame
if you change the condition to this, does it do what you want?
what i posted above or this variant (i personaly like this below, but it’s a preference only)
this says:
// do the code if all of the below are true:
// 1) it is before 1 hour AFTER sunset
// 2) it is after 45 minutes BEFORE sunset
- condition: sun
before: sunset
# 1) it is before
before_offset: "01:00:00"
# 1 hour AFTER sunset
- condition: sun
after: sunset
# 2) it is after
after_offset: "-00:45:00"
3 45 minutes BEFORE sunset
sorry, i thought i had a bug and wanted to verify it… so i temporarily deleted. but i restored it now.
no, your code doesn’t make sense to me still.
you asked to learn why… here’s what your code says. forget about reading the code, is this what you intend?
//// do the script if the following are ALL true:
/// 1) if it is currently before 45 minutes before sunset
/// 2) AND also
/// one of the following (1) conditions:
/// 2b)that it is after 1 hour after sunset
# do the script if the following are ALL true:
- condition: sun
# 1)if it is currently before 45 minutes before sunset
before: sunset
before_offset: "00:45:00"
# 2) AND also
- condition: or
# one of the following (1) conditions:
conditions:
- condition: sun
# 2b) that it is after 1 hour after sunset
after: sunset
after_offset: "01:00:00"