I’m wondering if you guys can help me out. Over time I’ve got many automations and I think with some variables I can work them out together.
For example
I got four automations for when I am at home. Fase 1 - 2 - 3 and 4 for lightning. Every step the lightning would get a little bit brighter and some extra lights would turn on. I’ve got them running in one script now and one automation.
Automation checks if someone is at home
and if the sun is getting below the horizon: if yes; play the script.
Script.
Play fase one, wait ~ 1 hour,
play fase two, wait ~ 1 hour
etc
The problem is / was that this one would run when I am at home. This would trigger the right moment for the lights to turn on. But one I gét home (for example two hours after sunset) this isn’t working. If the script would trigger at that moment instead of @ six PM, it won’t make sense.
So I also got four automations for getting home @ 6PM, 7PM, etc etc
Is it possible to get this into one script or one automation as well?
I think your logic is alittle off here. All 4 of these automations are identical instead of the condition. And your first automation literally covers all the rest.
This condition:
- after: sunset
after_offset: -01:15:00
condition: sun
Causes the automation to fire any time between sunset-1:15 and midnight. The other scripts have a tighter time span, but do the same thing and your first automation spans all the others. So there is no reason to have the others.
I didn’t notice those minor changes. But my point still stands. Your logic is flawed because you’ll be firing all 4 automations, in a seemly random order.
I think we both see or mean something different…It’s true that I’ve got four automations, but they don’t trigger at the same time. If I’m at home - lets say @ 16:20 the first automation will triger. After thet, the script that I’m at home will run and trigger the rest of the automations, turning more lights on and set them brighter.
However what I want and I’m just wondering if it possible (because this works just fine) is if the code can be any better and cleaner
Trigger
Is sensor.someone_home from off to on
is condition sunset down
– minus offset A == turn on light A into brighness 40
– minus offset between A & B == turn on light A into brightness 60
– minus offset between B & C == turn light into brighness 80 + turn on light B
– minus offset after C and before midnight == turn light into brightness 100 + turn on light B + C
Can this be done in one automation or do I need the four I’ve got?
If so; how do I do this?
If I understood your requirements correctly, attempting to combine all four automations into one will produce something like this:
- alias:
trigger:
- platform: state
entity_id: binary_sensor.iemand_in_huis
from: 'off'
to: 'on'
action:
- service: homeassistant.turn_on
data_template:
brightness: " TEMPLATE GOES HERE "
entity_id: " TEMPLATE GOES HERE "
rgb_color: [255,169,84]
- service: homeassistant.turn_on
data_template:
brightness: " TEMPLATE GOES HERE "
entity_id: " TEMPLATE GOES HERE "
rgb_color: [255,169,84]
- service: script.turn_on
data_template:
entity_id: " TEMPLATE GOES HERE "
The automation requires 5 nearly identical templates. The template has to determine the current time and, depending on the current time’s relation to sunset, produce the desired result (brightness value or list of entities). The last template determines if it should run a script (keuken_sfeerverlichting) or a ‘dummy script’ (that does nothing).
The template must perform time calculations that will be considerably messier than the simple way they’re done in a condition. Then you must use this time-calculating template 5 times in this automation. Is this worth the effort? I’d say no but it’s your decision.