Solving Automation Logic with OR and AND Conditions

Hey everyone, I wanted to share my experience with setting up a smart home automation that involves both OR and AND conditions. It was a bit tricky at first, but I managed to get it working smoothly! :tada:

So, my goal was to automate my blinds to open under specific conditions. I wanted them to open if the sun was above the horizon OR if it was after sunrise. Sounds simple enough, right? But when I first tried setting this up, I couldn’t get the logic to work properly. Here’s what I did:

  1. Understanding the Conditions: I realized I needed to use both numeric_state and sun conditions in my automation. The numeric_state condition checks if the sun elevation is above 0, while the sun condition triggers after sunrise.

  2. Setting Up the Automation: I structured my automation using a condition block with OR logic. This allowed me to combine both conditions without conflicts. Here’s a simplified version of what my setup looked like:

yaml
condition:
or:
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
above: ‘0’
- condition: sun
after: sunrise

  1. Testing and Tweaking: After setting it up, I tested it multiple times to ensure both conditions worked independently and together. It was a relief when the blinds finally opened exactly when I wanted them to!

This experience taught me the importance of clearly defining conditions and testing each part of the automation separately before combining them. If you’re struggling with similar logic, I highly recommend breaking down your conditions and testing each one step by step. :rocket:

If anyone has tips or alternative approaches for handling OR and AND conditions, I’d love to hear them! Let’s keep learning and improving our smart home setups together! :hugs: