Toggle Switch OFF/ON at Sunrise and Sunset

Hi all,

I have some basic automations built around sunrise/sunset already (ie, outdoor lights on 2 hours after sunset and off 3 hours before sunrise, aquarium automations, etc) but I am trying to automate a chicken coop door. The motor I am using opens and closes the door on a power interruption … so if I want to open the door in the morning, I have to toggle the receptacle outlet OFF and then ON. Same thing for closing it at night. I know this is simple but my brain is not working. Anyone have a neat solution as to how I can implement this in the form of an automation?

Just add a call service off, then delay, then call service on.

1 Like

Exactly what @Hellis81 said:

action:
- service: switch.turn_off
  entity_id: switch.chicken
- delay: '00:00:05'
- service: switch.turn_on
  entity_id: switch.chicken
1 Like

Thank you! It would have been hard work typing that from the phone :slight_smile:

  - alias: "Chicken Coop Door Open at Sunrise"
    trigger:
      - platform: sun
        event: sunrise
        offset: "-00:00:05"
    action:
      - service: homeassistant.turn_off
        data:
          entity_id:
            - switch.30753800d8f15bafee2e
      - service: homeassistant.turn_on
        data:
          entity_id:
            - switch.30753800d8f15bafee2e 

Thanks. This is what I have so far … where would I add the second offset?

Edit: OOPS. Didn’t see your reply. Thanks.

Is the formatting correct on this? Ashamed but I am still a bit of a newbie.

  - alias: "Chicken Coop Door Open at Sunrise"
    trigger:
      - platform: sun
        event: sunrise
    action:
      - service: switch.turn_off
        data:
          entity_id:
            - switch.30753800d8f15bafee2e
      - delay: '00:00:05'
      - service: switch.turn_on
        data:
          entity_id:
            - switch.30753800d8f15bafee2e

It looks correct.
Just try it and see. You only need to reload the automations then execute it to see if it works.

Works. Thanks for your help. Just wasn’t sure how to format the “delay”

1 Like

The actions are basically scripts, and that’s well documented here.

Thanks. Still learning.

Hey really interested in the motor setup you have for opening and closing the door. Can you share the details?

Thanks

Certainly. I ran power to my coop and I am just using an Add-A-Motor Chicken Coop Door attached to a cheap wifi plug. I use z-wave in my home but the coop is too far from the home to extend my z-wave network … ran a router out there and I have solid wifi signal now. Also paired a ChickenGuard Self Locking Coop Door and with the above automation my door opens at sunrise and closes an hour after sunset. Lastly, just for redundancy, I added a Xiaomi hub and a magnetic binary sensor to tell me if the door is open or closed. It’s all been dead reliable so far (about 4 months in operation).

1 Like

Hi, can I use this to change the background image on the sun state above and under horizon ?

many thanks. just looking for ideas for some cupboards in the house