Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


peejayw

1913 posts

Uber Geek
+1 received by user: 123


#295186 10-Mar-2022 21:39
Send private message

I am trying to set up a simple automation in HA, not Node Red. Automation is to turn a light on when a door opens but only when it's dark.
I thought that using a condition of sun, after sunset, before sunrise would achieve this but it does not work. I did read that below horizon is a better way to go but I couldnt see this option in any of the parameters.




 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


Create new topic
Chippo
129 posts

Master Geek
+1 received by user: 52

Trusted

  #2884581 10-Mar-2022 22:03
Send private message

You can use a state condition for the sun, below horizon.

 

There might also be a blueprint for this, but I threw a slightly more advanced version together for you. It'll turn a light on to 80% when the door is opened (Fading up over 2 seconds).

 

Then turn the light back off 5 minutes after the door is closed. Fading down over 20 seconds.

 

alias: Light - On with Door
description: ''
mode: restart
trigger:
  - platform: state
    entity_id: binary_sensor.door_living_room_1
    from: 'off'
    to: 'on'
condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
action:
  - service: light.turn_on
    data:
      brightness_pct: 80
      transition: 2
    target:
      entity_id: light.living_room_lamps
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.door_living_room_1
        from: 'on'
        to: 'off'
        for:
          hours: 0
          minutes: 5
          seconds: 0
  - service: light.turn_off
    data:
      transition: 20
    target:
      entity_id: light.living_room_lamps

 

 

 

 





I work for a global Data Protection Software company - But my opinions are my own.




catdog
107 posts

Master Geek
+1 received by user: 17


  #2884586 10-Mar-2022 22:19
Send private message

I made the same mistake the first time I tried creating a sun condition. The documentation actually covers this scenario as it's caused by way before/after are handled from/to midnight:

https://www.home-assistant.io/docs/scripts/conditions/#sun-condition

Note that if only before key is used, the condition will be true from midnight until sunrise/sunset. If only after key is used, the condition will be true from sunset/sunrise until midnight. Therefore, to cover time between sunset and sunrise one need to use after: sunset and before: sunrise as 2 separate conditions and combine them using or.

peejayw

1913 posts

Uber Geek
+1 received by user: 123


  #2884627 11-Mar-2022 07:08
Send private message

Thanks guys, all working now.





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


Create new topic








Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.