I am new to home assistant but not new to development so I understand the concept of conditional states.
I have been attempting to set up some automations with conditions. However, the conditional state seems to be ignored.
This is the automation:
automation:
#+-------------------------------------------------------------
#| Turn on Christmas tree lights if someone is home
#+-------------------------------------------------------------
- alias: 'Christmas'
description: 'Turn on Christmas if home'
trigger:
- platform: sun
event: sunset
offset: "00:45:00"
condition:
- condition: state
entity_id: group.family
state: 'home'
action:
- service: switch.turn_on
entity_id: switch.christmas
I have confirmed the group.family state is ‘not_home’. The automation works because the switch turns on 45 minutes after sunset. But with group.family state as not_home the switch turns on, which it shouldn’t.
I am running version 0.102.1.
Am I missing something with conditionals? I run the check config and get no errors.
Yeah, like Tom says… Its a quirk of the system that really just tests the actions
That’s why anyone who has been through this pain (count yourself amongst them) keeps a spare input boolean around (you’d need a restart to create one otherwise) to insert into triggers to test the conditions as well.
The triggers we either have to use code we’ve used before… Or more often… do it the hard way and test each trigger
Welcome to the club
This behaviour is mentioned in the docs and there are MANY threads about it too
Please note that if you click on Trigger of an automation in the frontend, only the action part will be executed by Home Assistant. That means you can’t test your trigger or condition part that way. It also means that if your automation uses some data from triggers, it won’t work properly as well just because trigger is not defined in this scenario.
Another excellent example of what makes the HA learning curve so damn steep. I have spent days now trying to figure out why my automation conditions persistently fails. It cannot be expected that such completely non-logical behaviour should be perceived as intuitive. No matter how many times I read the DOC’s , I will not be able to remember a detail like this.
Since this contradicts so dramatically with reasonable logic, the trigger button should have a fly-out with a relevant reminder/warning (until this is fixed - which it must be).
Imagine a sunset condition - if I understand this limitation correctly, the automation can only be tested fully once each day! Talk about time consuming dev cycles!
Your frustration and displeasure is evident. Nevertheless, the issue is known and documented. I would recommend the following course of action.
If you find yourself stumped by something, know that many people have come before you and have probably encountered the very same issue. Rather than attempt to re-discover what has already been discovered, do one or more of the following:
refer to the documentation
search the community forum
post a question
One of my very first hurdles I encountered (just over a year ago) involved the MQTT HVAC integration. I read the docs, searched the forum, then finally asked a question and received an answer (which confirmed MQTT HVAC couldn’t do what I wanted).
I once borrowed a SAAB 93 from a friend, and couldn’t figure out where to insert the ignition key. Since I had a physical key in my hand, I logically assumed that there had to be a keyhole somewhere. This situation is too obvious to even think of the possibility that there isn’t any, and you don’t read the manual to figure out something so obvious. It just makes you feel so stupid. I would have asked the owner, but this was before people had cell phones. Eventually I gave up and walked. Anyone who has ever driven a SAAB knows what I’m referring to. And we all know what happened to SAAB.
I’ve never driven a SAAB but I do remember reading about it’s unique placement of the ignition key lock (center console). Always thought it was a unusual location. I guess so did every other car manufacturer because it hardly started a trend.
I’m with you, that the documentation should be better (how is a totally different question), but what you’re talking about, is clearly stated in the documentation, here:
Quote:
Please note that if you click on Trigger of an automation in the frontend, only the action part will be executed by Home Assistant. That means you can’t test your trigger or condition part that way. It also means that if your automation uses some data from triggers, it won’t work properly as well just because trigger is not defined in this scenario.
It is, it’s name changed to ‘run actions’ instead of ‘execute’ a pretty long time ago. And ‘run actions’ does exactly what’s written on the can, it runs the actions