Create manual variable at_home

Hello,

I use ping to detect if the mobiles are at home or not. I would like to create a manual variable to collect if there are people at home or not so that this variable is the one I use in my automations.

That is to create an automation that detects if there are people at home or not by changing at_home from true to false. And having this way already the data of if there are people at home or not… use it as a trigger in new automations, for example if at_home is true turn on the heating.
Can this be done?

You can use the “zone.home” for that. It’s state shows how many people are at home.
0 = no people at home

template:
  - trigger: 
      - platform: state
        entity_id: zone.home
    binary_sensor:
      - name: People At Home
        state_class: occupancy
        state: "{{ states('zone.home')|int(0) > 0 }}"
        unique_id: occupancy-a015da77-b429-420d-94aa-8505064ab8a7

If you don’t use zone.home - since you mention you use ping, then you can do the same with:

state: >
  {{ is_state('binary_sensor.mobile1','on') or is_state('binary_sensor.mobile2','on') or is_state('binary_sensor.mobile3','on') }}

etc

Hello reading the manual

I think this is what I need, but I don’t know how to force the status to change its value to match the number of people who are at home via ping. For example as a service it does not appear to me when making an automation.

Thanks

Does anyone know how to change this value manually? What code or procedure should I follow to create an automatism to change this value?