How to combine my "on" & "off" automations?

Hi there,

I do have a Siemens LOGO for automating some of my terrariums.
This LOGO is turning on and off some lights - based on an astrological clock, which means, that it does use the astrological sun set / sun rise to trigger the lights.

Right now, I do have some other terrariums that are not yet fully automated - and I am using some zigbee plugs to turn them on / off… the trigger is currently the binary sensor of the light of one of my automated terrariums.

Meaning: I read the state of the Light from my logo with Modbus - and if the state is ON - the plugs on the other terrariums will be turned on, and when the light is OFF, another automation will switch the lights off again.

alias: Schalte Terrarien Arbeitszimmer EIN
description: ""
trigger:
  - platform: state
    entity_id:
      - light.tageslicht_t1
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition: []
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id:
        - switch.terrarium_1_switch
        - switch.terrarium_2_switch
        - switch.terrarium_3_switch
mode: single

alias: Schalte Terrarien Arbeitszimmer AUS
description: ""
trigger:
  - platform: state
    entity_id:
      - light.tageslicht_t1
    to: "off"
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id:
        - switch.terrarium_1_switch
        - switch.terrarium_2_switch
        - switch.terrarium_3_switch
mode: single

I am pretty sure that there is a nicer way of doing this - and I would like to use either the SUN integration of HomeAssistant (but I observed that this might not use the exact same times as the LOGO does)
OR - I would like to use the timestamps my Siemens LOGO does - to trigger these plugs.

Here are the current time stamps my LOGO does provide:

Sunrise: 2023-03-01T05:54:00+00:00
Sunset: 2023-03-01T16:45:00+00:00

And here are the information my SUN integration does show:

next_dawn: 2023-03-02T05:33:01.406763+00:00
next_dusk: 2023-03-01T17:39:12.527562+00:00
next_midnight: 2023-03-01T23:36:27+00:00
next_noon: 2023-03-01T11:36:44+00:00
next_rising: 2023-03-02T06:05:11.840102+00:00
next_setting: 2023-03-01T17:06:55.194533+00:00
  1. You can see that there’s a difference between these information, probably caused by using “astrological”, “nautic” or “public” - and also probably based on the defined location (which is “Berlin” for the AstroClock of the LOGO, as far as I can remember, but we are further down in the south in reality)…

  2. How can I change my Automation to use these sunrise / sunset timestamps? If possible combined in just one automation…

Thanks a lot :slight_smile:

Combining the existing automations, with random ID added so you can use the automation trace tool.

alias: Schalte Terrarien Arbeitszimmer
description: ""
id: f0c5f440-ee68-48a0-b0ff-6a2c5198f125
trigger:
  - platform: state
    entity_id: light.tageslicht_t1
    to:
     - "on"
     - "off"
action:
  - service: switch.turn_{{ trigger.to_state.state }}
    target:
      entity_id:
        - switch.terrarium_1_switch
        - switch.terrarium_2_switch
        - switch.terrarium_3_switch

Version using the sun:

alias: Schalte Terrarien Arbeitszimmer
description: ""
id: 4fe092b5-d496-4a2b-b730-dac128ac448c
trigger:
  - platform: state
    entity_id: sun.sun
    to: above_horizon
    id: off
  - platform: state
    entity_id: sun.sun
    to: below_horizon
    id: on
action:
  - service: switch.turn_{{ trigger.id }}
    target:
      entity_id:
        - switch.terrarium_1_switch
        - switch.terrarium_2_switch
        - switch.terrarium_3_switch
2 Likes