Automation: Trigger a switch based on presense

Hi,

I’m using ESPresense to track a device within my home.
I want my automation to turn off two switches when the tracked device enter a specific room. When the device leave the room, I want the switches to turn on again. I want this in a single automation (making it in two automations are really easy).

I’ve made an automation that do this, but I don’t find it robust enough using toggle. Was looking into using trigger and using template under a condition, or perhaps if-then-else ?

@tom_l Any ideas? You’re the guru here :slight_smile:

  - alias: 42 - S22U in the Office
    id: S22U in the Office

    trigger:
    - platform: state
      entity_id: sensor.s22ultra
      to: "kontor"

    - platform: state
      entity_id: sensor.s22ultra
      from: "kontor"

    action:
    - service: switch.toggle
      entity_id: switch.kontor_recordings, switch.kontor_snapshots

Turn off when the sensor changes to kontour and turn on when it changes from kontour.

  - alias: 42 - S22U in the Office
    id: S22U in the Office
    trigger:
      - id: 'off'
        platform: state
        entity_id: sensor.s22ultra
        to: 'kontor'
      - id: 'on'
        platform: state
        entity_id: sensor.s22ultra
        from: 'kontor'
    action:
      - service: 'switch.turn_{{ trigger.id }}'
        target:
          entity_id:
            - switch.kontor_recordings
            - switch.kontor_snapshots

Nice one @123 :slight_smile: Thanx !

1 Like