Writing a rule on the away/home state change. Evrything is working great and now i want to add a welcome light if it is dark.
Already have a sensor for night, evening day and a rule (from different set-up) like this
It’s worth taking a read through the introduction guide that explains how the automation works, and how triggers, conditions and actions all link. Then you end up with something like:
trigger:
platform: state
entity_id: device_tracker.mobile
state: home
condition:
condition: sun
after: sunset
action:
service: switch.turn_on
entity_id: switch.welcome
It’s easy enough to extend and for something that simple you don’t need a template.
Thank you - i have already stolen a lot from your configs.
I did. But getting familiar with HA means learning templating.
So instead of
Rule A
condition state from away to home do stuff A
Rule B
condition state from away to home do stuff B
Rule C
condition state from away to home do stuff C
I just want to have one Rule A and inside fork it
So in this case
Rule A
condition state from away to home
do stuff A
do stuff B
If Night - Do stuff C and if not do stuff D
I know it can be done just to undestand what to put for the templating. As a work around i can use scenes and than run a template like below. But want to operate directly with lights. So entity is already known it’s the action turn_on or turn_off that needs to be templated.
By the way what can i put instead of NONE above? If i leave it blank - i get errors in HA log. So i have to put up an empty scene for this (something like scene.none)
You did! Thank you! Now everything cam together as a puzzle.
And just to emphasize what if here i wanted to do nothing. How can i state that nothing should be done between else and endif?
If you REALLY want to do it like this in a single automation, you can use a condition within your script to stop it from doing the last step unless it’s night or evening.
With that, light.always will always turn on, light.morning will only turn on in the morning, and light.night_or_evening will only turn on at night or in the evening.
Note that I’ve not tested any of this, but it should give you some ideas of how to accomplish what you want.