Location: all users leave zone or first user enters zone?

I might be missing something obvious here - I’m very clear how to handle actions based on specific devices leaving, but is there any way to do first/last users?
Most of my actions I want are “everyone out” ot “someone is home”

Thanks

If you dont care how is last to leave or first to arrive then I would use the zone.home numerical state as a trigger like the following.

First persons comes home trigger:

trigger:
  - platform: numeric_state
    entity_id: zone.home
    above: '0'

OR Last Persons just left:

trigger:
  - platform: numeric_state
    entity_id: zone.home
    below: '1'

You can ofcourse use the numerical state of the zone.home as a condition as well:

condition:
  - condition: numeric_state
    entity_id: zone.home
    above: '0'

HTH

2 Likes

In my opinion the group method is better.

  family:
    name: Family
    entities:
      - person.petra
      - person.andreash
      - input_boolean.guests

Now I can toggle the boolean to make someone home without this being a person or tracker.
This makes it easier to condition actions from happening when guests are at your house. It’s easy to forget when you “just going down to the store to get some milk” and all lights go off and alarm is armed as you walk out.

1 Like

Thanks both.
I knew it would be something simple that I’d missed!

I’ll have a think which makes most sense!

Wanted to follow up on this - with a couple of questions/thoughts

  • Firstly, where do you set up the group in the UI? Presumably you created the boolean as a helper?
  • Secondly, thinking about actual usage, do you have a method of setting the guest mode programmatically? I like the idea, but I just know I’ll forget to set the mode in that context…!

-Thirdly, unrelated to your comment, I have a personal phone and a work phone - is there any way to set logic so that if one or the other is away then that person is away, that wont simply be overriden when the other device is detected as home? (I guess this could relate to your comment as well if you had a person.guest entity that could be manually set rather than the input_boolean

Thanks!

Yes, I think my helper is too old for UI, but yes that is the current method of doing it.

I don’t think you can set it up in UI currently.
You can only set up same type of groups, so a group mixed with people and booleans is not possible I think.
You need to add it in yaml.

I don’t have anything detecting guests.
But if I remember to set it to on then I have a way to control it.
image

And when I enable it it should have turned green, I need to figure that out. But it gives me the option to set the expected time they leave.
At that time the guest mode is turned off automatically.

image

What you want is really the opposite of a group behaviour of the work phone and the personal.
Personally I only use my own phone as tracker in automations.
I believe persons are harder to set than booleans. I think you need to set a person using the set state or device tracker see, but that is not permanent.
If something changes in the entity it could go back to it’s sensed state.
Booleans do not have anything in the background, they just do what you tell them.

1 Like

Nice - like that (and wife friendly…) - might need to explore that option

Was also thinking could maybe check for phone devices on the wifi or something, but maybe I’m trying to make it too complex!

You could use the phone wifi, but it all depends on what the purpose of the presence detection is. Is it home alarm?
I use wifi sensors for some things but not the home/away, they can drop off and phones can run out of battery, power saving mode and all that…

Oh, i wouldn’t use it for me and the family, but for guests.
Intention eventually will be to use it in conjunction with the alarm, yes, but we’ll likely still set that using keypad and have it as backup.

Ok so you mean a ping sensor or something like that as the guest sensor?
Not good. That will fail, most phones do not respond when the screen is off.

And do really all guests have wifi access?

Ones that I’m going to leave in the house alone will for the most part

Can I ask how you added this card? I’m looking for something similar (actually for an input_number right now), but I can’t see a similar card?

It’s a picture elements card.
So it’s custom. edit, not custom as custom integration, but you customize it how you want.

This card was created before the button entity existed so I had to use input booleans as buttons and the automation it triggers resets the boolean to off again.
I could have used scripts instead but I didn’t think of that.

type: picture-elements
tap_action:
  action: none
hold_action:
  action: none
image: local/frame3.png
style: |
  ha-card {
      box-shadow: none;
  }

elements:
  - entity: input_boolean.guests
    style:
      left: 44%
      top: 37%
      transform: scale(7,8)
    tap_action:
      action: toggle
    type: state-icon
  - entity: sensor.guest_timer
    style:
      left: 49%
      top: 77%
    tap_action:
      action: toggle
    type: state-label
  - entity: input_boolean.hour_minus
    style:
      left: 24%
      top: 70%
      transform: scale(2,2)
    tap_action:
      action: toggle
    type: state-icon
  - entity: input_boolean.hour_plus
    style:
      left: 64%
      top: 69.5%
      transform: scale(2,2)
    tap_action:
      action: toggle
    type: state-icon

1 Like

image

Needs a little work, but that’s got me somewhere… no idea why Input_number with step 1 has a decimal place tho… bit annoying :man_shrugging:

Input number are floats by some reason.
The way around it is to create a template sensor that takes the int of the input number

You’re going to tell me I have to do that in YAML aren’t you? :wink: (and I cannot seem to find where the helpers are stored to edit the YAML)

Yes currently you can’t create sensors in GUI.

sensor:
  - platform: template
    sensors:
      int_number:
        value_template: "{{ states('input_number.number') | int }}"

They aren’t. They are in json format in the hidden folder.
Not sure if they are editable. Just delete and recreate.

1 Like

Sorry, being a little slow here… where do I put this? And where in the code does it define the name?
Thanks

No worries.

In configuration.yaml
Anywhere you want really. You just need to make sure you place it after one “part” is done.
You see this on the indentations.

example:

default_config:
  allowlist_external_dirs: # this is indented to make a "subpart"
    - '/config/www'
# here "part" and "subpart" config is done.

recorder: # here is the next part
  purge_keep_days: 10
cloud: # and another

#and so on...

zha:
  zigpy_config:
    ota:
      ikea_provider: true
      
     
climate:
  - platform: generic_thermostat
    name: Vardagsrum
    heater: group.vardagsrum
    target_sensor: sensor.temperatur_vardagsrum_temperature
    min_temp: 18
    max_temp: 24
    target_temp: 22
    cold_tolerance: 0.5
    hot_tolerance: 0
    initial_hvac_mode: heat
    
  - platform: generic_thermostat
    name: Sovrum
    heater: switch.trv_sovrum_on_off
    target_sensor: sensor.temperatur_sovrum_temperature
    min_temp: 18
    max_temp: 24
    target_temp: 21.5
    cold_tolerance: 0.5
    hot_tolerance: 0
    initial_hvac_mode: heat
    
  - platform: generic_thermostat
    name: David
    heater: switch.trv_david_on_off
    target_sensor: sensor.temperatur_david_temperature
    min_temp: 18
    max_temp: 24
    target_temp: 21.5
    cold_tolerance: 0.5
    hot_tolerance: 0
    initial_hvac_mode: heat
    
  - platform: generic_thermostat
    name: Matilda
    heater: switch.trv_matilda_on_off
    target_sensor: sensor.temperatur_matilda_temperature
    min_temp: 18
    max_temp: 24
    target_temp: 21.5
    cold_tolerance: 0.5
    hot_tolerance: 0
    initial_hvac_mode: heat
    

Anywhere in between the “parts” is fine to place it.
But first do a CTRL + F and search for “sensor:”, if you already have one “sensor:” then it should be placed there like this:

sensor:
  - platform: systemmonitor
    resources:
      - type: memory_use_percent
      - type: memory_free
      - type: processor_use
      - type: processor_temperature

  - platform: template
    sensors:
      int_number: # this is the name of the sensor, so it will be called sensor.int_number
        value_template: "{{ states('input_number.number') | int }}"

Fab thanks. I did actually know most of that, just for some reason assumed the sensor needed to go somewhere else and that the name would be after a : (noob I guess!)
I’ve actually created a few different files outside of config to keep that relatively clean, do might do the same for manually created devices

Out of interest, if I created one in YAML with the same name as something I created in UI, what would happen?