#Turning lights off when phones plug in

1 messages · Page 1 of 1 (latest)

bitter ingot
#

Hello everyone,

I'm watching and reading a bunch of tutorials on value templates and still in a bit of a rut.

I'm trying to make it so that the lights will turn off when person 1's phone is plugged in, but the lights stay on if person 2 is home. If both people are home, the lights shut off when both phones are plugged in.

This is what I have so far - admittedly assisted by ChatGPT. I'm a bit lost on where to go from here making conditions with the variables (i.e., person1_home) set by the template

  - condition: template
    value_template: >
      {% set person1_home = is_state('person.person1', 'home') %}
      {% set person2_home = is_state('person.person2', 'home') %}
      {% set phone1_charging = is_state('sensor.phonecharging1', 'charging') %}
      {% set phone2_charging = is_state('sensor.phonecharging2', 'charging') %}```

Any help would be appreciated! Cheers
mint gyro
#

I would just do it as "are the number of charging phones equal to the number of people home"

Number of charging phones: ['sensor.phonecharging1', 'sensor.phonecharging2'] | select('is_state', 'charging') | list | count

Number of people home is just states('zone.home') | int

As a bonus, this will trigger the automation and turn your lights off when noone is home

pine field
#

I tried a similar set up and ran into a problem with it. The iOS companion app will not report that the device is charging if the battery is fully charged. In my case, my partner went to bed and put their phone on the charger by the time I went to bed and I put my phone on my charger , their phone was done charging. so although we were both home, not all phones were charging so the condition wasn’t met and my lights stayed on. I still haven’t figured out a good way to solve this

hybrid heath
#

The battery state entity provided by the companion app should change from Charging to Full so as long as your automation logic includes both it shouldn’t be a problem

mint gyro
#

(for which the logic would be something like: ['sensor.phonecharging1', 'sensor.phonecharging2'] | map('states') | select('in', ['charging', 'full']) | list | count)