I’ve got a sensor that counts the number of people who are home.
people_at_home:
entity_id:
- person.john_doe
- person.jane_doe
- person.fred_doe
friendly_name: "How many people are at home?"
value_template: >-
{{ states.person | selectattr('state', 'eq', 'home') | list | count | int }}
Now I would like to trigger a sensor if the number increases only (no decrease). I’m happy for this sensor to be as simple as True/False.
Do you really want a [binary_]sensor that is true if the value of sensor.people_at_home increases? Or are you just thinking of using that to trigger an automation?
FWIW, I also have a sensor that indicates the number of people that are home, and I use it directly in two automations, one that changes my “home mode” input_select to Away:
- alias: Home Mode - Leaving
trigger:
platform: numeric_state
entity_id: sensor.n_people_home
below: 1
condition:
condition: state
entity_id: input_select.home_mode
state: Home
action:
service: input_select.select_option
entity_id: input_select.home_mode
data:
option: Away
and another that changes it to Home:
- alias: Home Mode - Arriving
trigger:
platform: state
entity_id: sensor.n_people_home
condition:
condition: template
value_template: >
{{ trigger.to_state.state|int > trigger.from_state.state|int }}
action:
service: input_select.select_option
entity_id: input_select.home_mode
data:
option: Home
BTW, the reason for the condition in the first automation is that input_select.home_mode has more options than Home & Away, and I only want to change it to Away if it is currently Home.