Switch off by not_home

Hello
I like to switch off (switch.dual_nano_switch_5), if nobody is at home. In this case it is not working. If i do the device tracker apart it is working well for both. If i delete the condition it working also.

  • alias: Licht uit doen Tafellamp
    trigger:
    • platform: time
      at: ‘23:13:00’
      condition:
      • condition: template
        value_template: “{{ is_state(‘device_tracker.iphone_13’, ‘not_home’) and (‘device_tracker.iphone’, ‘not_home’) }}”
        action:
    • service: homeassistant.turn_off
      target:
      entity_id: switch.dual_nano_switch_5
    • service: notify.HomeAutomation
      data:
      title: Licht uit
      message: “De tafellamp gaat uit.”

Hi,

You can add for example the following to your configuration yaml, it will creat a group

# Example configuration.yaml entry
group:
  mobiele_toestellen:
    name: "Mobiele toestellen"
    entities:
      - device_tracker.iphone_13
      - device_tracker.iphone

Check the below readme because the above code is a old style group code > maybe the domain part is interesting

Use state of zone.home = 0

1 Like

Thanks, Woempiej i will give it a change. On the other side why is not working?

I have done these with the same result.

It is difficult to tell you what is wrong because you have not formatted your post correctly.

There are at least 2 major issues that you need to address.

First, your automation is set up to only trigger at 23:13. If you want it to fire when everyone has left the home, you need to make that a trigger too, not just a condition.

Community Guide about triggers and one about conditions.

Second, your template is not properly constructed. The second part is missing the function is_state. If you have other Zones set up, using not_home as the desired state may not work the way you want it to. It would be better to check if either of them were home, then negate that. That way other non-Home zones would be treated the same as not_home.

alias: Licht uit doen Tafellamp
trigger:
  - alias: Trigger at a specific time
    platform: time
    at: "23:13:00"
  - alias:  Trigger when both phone trackers leave Home
    platform: template
    value_template: |
      {{ not (is_state('device_tracker.iphone_13', 'home') or 
      is_state('device_tracker.iphone', 'home')) }}
condition:
  - alias: Check that neither phone tracker is home
    condition: template
    value_template: |
      {{ not (is_state('device_tracker.iphone_13', 'home') or 
      is_state('device_tracker.iphone', 'home')) }}
action:
  - service: homeassistant.turn_off
    target:
      entity_id: switch.dual_nano_switch_5
  - service: notify.homeautomation
    data:
      title: Licht uit
      message: "De tafellamp gaat uit."
1 Like

Thanks for the good explanation i go further in this way.

Hi @kotick

Please use the below option when posting a code;
afbeelding

Thanks @woempiej :grimacing: