#Turn back on the lights within 5 minutes if someone returns to the area

1 messages · Page 1 of 1 (latest)

willow path
#

I want to create an script which will remember for each area in my apartment current lights that are on/off (current scene) and if motion detector detects that nobody in a room, turn off lights.
When someone enters in that room within less than 5 minutes setup lights as was

Is it doable? Im looking for some clean solution for templating maybe area and for each area to get all the lights entities and states, and put it into service scene.create, and the trigger would be motion detection -> cleared

tawdry dirge
tawdry dirge
# willow path I want to create an script which will remember for each area in my apartment cur...

heres a quick example i mocked up
obviously the entity names will be different on your setup etc... but gives you an example flow to look at

description: ""
mode: single
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.everything_presence_one_046990_occupancy
    from: "on"
    to: "off"
conditions: []
actions:
  - action: scene.create
    metadata: {}
    data:
      scene_id: remembered_state
      entities: switch.mini1pmg3_garagelight_switch_0
  - wait_for_trigger:
      - trigger: state
        entity_id:
          - binary_sensor.everything_presence_one_046990_occupancy
        from: "off"
        to: "on"
    timeout:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - if:
      - condition: state
        entity_id: binary_sensor.everything_presence_one_046990_occupancy
        state: "on"
    then:
      - action: scene.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: scene.remembered_state
willow path
#

Ok and how to do it with multiple areas, script can be overlapping with different motion senzora

tawdry dirge
#

if so then just make an automation for like the above for each room. just name the remembered state scene differently

willow path
#

Maybe I can put everything into one place

#

And use different triggers?

tawdry dirge
# willow path And use different triggers?

for this particular thing I would suggest multiple automations.
the reason for this is because its an automation that runs for a while you really want the protection of the mode type stopping multiple running at the same time in case something goes wrong.
if you have multiple running then you will have to change the mode type to allow multiple instances of the automation to be running at the same time.
in theory yes it should be fine but i think it would be safer and less likely to have issues if it were separate automations.

willow path
#

https://pastebin.com/jFrh7ZMV

First I want to create a script like this, which I will use multiple times, for multiple rooms.
But Im having an issue with this script, when I add fields, it throwa an error:
Message malformed: Entity {% if motion_sensors is string %} {{ motion_sensors }} {% else %} {{ motion_sensors | list }} {% endif %} is neither a valid entity ID nor a valid UUID for dictionary value @ data['entity_id']
@tawdry dirge

tawdry dirge
willow path
#
alias: Preserve Lights
description: Universal automation that preserves lights for any room when motion goes off
triggers:
  - trigger: state
    entity_id: binary_sensor.athom_office_presence_occupancy
    from: "on"
    to: "off"
    id: office
conditions: []
actions:
  - data:
      scene_id: office_lights_preserved
      snapshot_entities:
        - light.office_all_lights
    action: scene.create
  - wait_for_trigger:
      - trigger: state
        entity_id: binary_sensor.athom_office_presence_occupancy
        from: "off"
        to: "on"
    timeout:
      minutes: 5
    continue_on_timeout: false
  - condition: state
    entity_id: binary_sensor.athom_office_presence_occupancy
    state: "on"
  - action: scene.turn_on
    data:
      entity_id: scene.office_lights_preserved
mode: parallel
max: 10

This is my updated script

#

now I want to do it for livingroom, bathroom etc. Thinking to create a custom utility script which will be called multiple times fore different areas, to create scene

willow path
#

still doesn't work lol

candid eagle
#

You used the automation (not script) above? Two things i notice, you don't turn off the lights. And you use light.office_all_lights which is I guess a light group? That group will not contain the setting for each light.

willow path
willow path
#

apparently not