Welcome to Incremental Social! Learn more about this project here!
Check out lemmyverse to find more communities to join from here!

CondorWonder ,

This is a great case for templates. Templates are Home Assistant's way of doing dynamic actions or data.

When: whatever triggers you need for the lights - can be multiple triggers or one trigger with every light/switch listed, with a For clause. The list is "OR"ed so do however you want. You could use a group but then all devices would be changed together - which doesn't sound like is what you want.

And if: Whatever conditions you want, time, day of week, etc.

Then do: The action is where it gets interesting
add an action to execute "Generic turn off", select any device (we'll change that in a moment). The reason for the "Generic turn off" is that it works with devices in any domain (light or switch).
Then drop into the YAML view and chcange the entity_id value to this template: '{{ trigger.from_state.entity_id }}'. The trigger is a variable that's available inside the automation and can be used instead of specifying a static value somewhere. https://www.home-assistant.io/docs/automation/trigger/ for details on triggers.

Here's the complete automation, you could create a new empty automation, then copy and paste this in place and just change the trigger and conditions as you want.

alias: Action - Turn off lights 15min after turned on during day
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.porch_light
    for:
      hours: 0
      minutes: 15
      seconds: 0
    enabled: true
    to: "on"
    from: "off"
condition:
  - condition: sun
    after: sunrise
    after_offset: "30"
  - condition: time
    after: "01:00:00"
    before: "23:00:00"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
action:
  - service: homeassistant.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: "{{ trigger.from_state.entity_id }}"
mode: queued
max: 10

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • homeassistant@lemmy.world
  • incremental_games
  • meta
  • All magazines