#Automation – Turn Off All Lights at Sunset / When Charging + Medito App Open

1 messages · Page 1 of 1 (latest)

rose flax
#

Hi everyone! I built a Home Assistant automation that turns off all my lights either at 21:00 or when my phone starts charging after 20:30 while the Medito app is open. Here is my current YAML — does this look correct, or is there anything I should improve?

alias: Sun set off  Medito + Laden
triggers:
  - at: "21:00:00"
    trigger: time
  - entity_id: binary_sensor.ptp_n49_is_charging
    to: "on"
    trigger: state
conditions:
  - condition: time
    after: "20:30:00"
  - condition: or
    conditions:
      - condition: time
        after: "20:59:00"
      - condition: and
        conditions:
          - condition: state
            entity_id: binary_sensor.ptp_n49_is_charging
            state: "on"
          - condition: state
            entity_id: sensor.ptp_n49_last_used_app
            state: io.medito.android
actions:
  - target:
      entity_id:
        - light.rgbic_strip_lights
        - light.fernbedienung
        - light.govee_light_2
        - light.govee_light
        - light.0x0c4314fffe35d502
        - light.0x0c4314fffe8828b6
        - light.0x588e81fffee59a4f
        - light.0x847127fffe0ca00e
        - light.0x847127fffe8d9027
        - light.dachboden
        - light.0x84fd27fffe933d84
    action: light.turn_off
    data: {}
mode: single

Any feedback or suggestions welcome! 🙏

proper harbor
#

You can simplify it a bit by adding trigger IDs and then using those in the action in a choose block

#

it will avoid the need to do things like this:

      - condition: time
        after: "20:59:00"
rose flax
#

But i think it does not really work either way

#

And why would it be easier with these IDs?

eternal kelp
#

With something as simple as this it doesn't really matter. When you get more complex having predefined trigger IDs makes it much simpler.

#

Here is how I would do it (quite similar to yours) with a trigger ID thrown in for luck. Also I put mym lights in a light group for simplicity.

alias: Sun set off – Medito + Laden
mode: single
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.ptp_n49_is_charging
    id: Charging
    to:
      - "on"
conditions: []
actions:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: and
                conditions:
                  - condition: trigger
                    id:
                      - Charging
                  - condition: time
                    after: "20:30:00"
              - condition: time
                after: "21:00:00"
        sequence:
          - action: light.turn_off
            target:
              entity_id: light.all_lights_group```
cyan steeple
#

Only the first condition is not necessary. And you can just check for ``after: "21:00:00" instead of "20:59:00".

With a light group of a label you could make the action a bit simpler.

rose flax
#

btw if i copy that it doesn't do anything

description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.ptp_n49_is_charging
    id: Charging
    to:
      - "on"
conditions: []
actions:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: and
                conditions:
                  - condition: trigger
                    id:
                      - Charging
                  - condition: time
                    after: "20:30:00"
              - condition: time
                after: "21:00:00"
        sequence:
          - action: light.turn_off
            target:
              label_id: lampe
            data: {}
mode: single````
cyan steeple
#

Now you are missing the 21:00 trigger and the meteo app requirment

Think most simple form would be:

alias: Sun set off  Medito + Laden
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.ptp_n49_is_charging
    id: Charging
    to:
      - "on"
  - trigger: time
    at: "21:00:00"
    id: Time
conditions:
  - condition: or
    conditions:
      - condition: trigger
        id:
          - Time
      - condition: and
        conditions:
          - condition: time
            after: "20:30:00"
          - condition: state
            entity_id: sensor.ptp_n49_last_used_app
            state: io.medito.android
actions:
  - action: light.turn_off
    target:
      label_id: lampe
    data: {}
mode: single