Presence simulation

Hello!
I tried to integrate Presence simulation according thsi video: https://www.youtube.com/watch?v=OTQu3BMr3EU.
From 5 minutes on he explanis about the trigger IDs.
The problem is that my version looks different.
Can somebody help?
That came out for me but does not work:

alias: Presence simulation on/off
description: ""
triggers:
  - trigger: state
    entity_id:
      - zone.home
    to:
      - "0"
    attribute: persons
    id: Everybody left
  - trigger: numeric_state
    entity_id:
      - zone.home
    above: 0
    id: Somebody at home
    attribute: persons
    enabled: true
conditions: []
actions:
  - if: []
    then:
      - action: switch.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: switch.presence_simulation
    else:
      - action: switch.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: switch.presence_simulation
mode: single

There’s an integration that does this:

That is done and used.
But the detection of presence is not working.

I don’t think you need the “persons” attribute. zone.home has a value equal to the number of tracked devices detected. If nobody’s in, it’s 0 - that’s all you need.

remove both lines with the persons attribute. This should not be there because persons is a list of person entity ids and not the number of persons in the zone. You need to t3st for the state alone.

Edit: Jack beat me to it :grinning:

1 Like

Ok. Thanks.
On works.
But if a person arrives it remains on.

That is because the if has no conditions. It will always do the top part.

Why not just use two automations? The triggers for coming and leaving are different, the actions are different. Why test the same thing twice just to put it inside one automation and make things so complex that you no longer understand why it does not work?

alias: Presence simulation on
description: ""
triggers:
  - trigger: state
    entity_id: zone.home
    to: "0"
conditions: []
actions:
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: switch.presence_simulation
mode: single
alias: Presence simulation off
description: ""
triggers:
  - trigger: numeric_state
    entity_id: zone.home
    above: 0
conditions: []
actions:
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.presence_simulation
mode: single

That works:

alias: Presence simulation on/off
description: ""
triggers:
  - trigger: state
    entity_id:
      - zone.home
    to:
      - "0"
    id: Everybody left
  - trigger: numeric_state
    entity_id:
      - zone.home
    above: 0
    id: Somebody at home
    enabled: true
conditions: []
actions:
  - if:
      - condition: trigger
        id:
          - Everybody left
    then:
      - action: switch.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: switch.presence_simulation
    else:
      - action: switch.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: switch.presence_simulation
mode: single

I edited in the two automation version above.

Note that triggers are about a change, not about what already is. So the right name for the trigger would be: First person arrives rather than Somebody at home.

P.s. If you just want to create a sensor that turns on when everyone is away and off when someone is home, you can also create a template helper for a binary sensor. The state template would be:

{{ is_state('zone.home', '0') }}

Thank you, I understand that.

From the video quoted above, I gathered that trigger IDs can be used across the entire platform.

Is that not the case?

Or where would I find them?

Every trigger can have an ID. You can test for them later. If you split the automation, you do not really need any id.

Did you see the suggestion for a template helper I put in later?

Yes I will try later.

I created a switch, which shows the opposite…?

type: entities
entities:
  - entity: binary_sensor.anwesenheit_brenden
title: Anwesenheit Brenden
show_header_toggle: false
state_color: true

Yes, your presence simulation turned on when people left (at least the last yaml you showed) so the template was written as a absence sensor. put not before is_state to reverse it and mke it a presence sensor:

{{ not is_state('zone.home','0') }}

You named it after one person? The template is for any person, so if you are a single person household it a correct name, but it might be confusing if there are more people. If you want the state of one specific person from the household you should test for the state of that person, not the zone.

First a big thank you.
I am still a newby. So this is very helpful.

No I created it for the household.

Why is it per person showing at home and when absent unknown? Can this be adjussted?

type: entity
entity: person.lukas_metzler
icon: ""
name:
  type: entity
state_color: true

A state of a person is either a name of a zone that the person is in, or away. Unknown should only be if there is no value known.It is not changeable, other than making more zones. Avoid making overlapping zones though, especially with home.

If what? There’s no if in there… Put something in [] if you are doing it manually.

I suggest however doing this in the UI editor, then looking at the edit-as-YAML to see what actually is happening, and it will be clear how you can do this.

The video is outdated. If it was causing you problems (I assume it;'s the one in the Docs) then click the link at the bottom of the Docs web page and explain that the format is legacy anf you cannot follow it, maybe it will finally go away.