well I’m finally back to this idea after a long period.
I however seem to have a problem with figuring out how to count the new sensor up or down.
I got two sensors at the door.
motion sensor A and B
if Motion sensor A triggers then B triggers I want it to count the Kitchen sensor one up.
if motion sensor B triggers then A triggers then I want it to count the kitchen sensor one down. how is this possible ?
and I want both sensors to reset their status once they counted the kitchen sensor up or down.
so I can have multiple people go through right after each other without the sensors not picking them up.
this is where I’m At ATM but I don’t feel confident that it would work:
import appdaemon.plugins.hass.hassapi as hass
class KitchenCount(hass.Hass):
def initialize(self):
self.log("Method initialize was called in the class KitchenCount")
self.EntrySensorFirst = False
self.ExitSensorFirst = False
#self.persons = 0
#belov I can make a sensor and set the initial state This allows me to use the sensors state to determine the lights state
self.set_state("sensor.people_in_kitchen", state = 0, attributes = {"friendly_name": "kitchen people counter"})
trigger = self.args["sensor"][0]
trigger2 = self.args["sensor"][1]
self.listen_state(self.EnterKtichen,trigger,new="on")
self.listen_state(self.ExitKtichen,trigger2,new="on")
def EnterKtichen(self, entity, attribute, old,new, kwargs):
self.log("Method EnterKtichen was called in the class KitchenCount")
if self.ExitSensorFirst == False:
self.log("EntrySensorFirst was first in the class KitchenCount")
self.EntrySensorFirst = True
else:
self.log("1 Person Exiting Kitchen")
kitchen_count = self.get_state("sensor.people_in_kitchen")
self.log("kitchen_count is :" + kitchen_count)
new_kitchen_count = ktichen_count -1
self.log("new_kitchen_count is :" + new_kitchen_count)
self.set_state("sensor.people_in_kitchen", state = new_kitchen_count)
def ExitKtichen(self, entity, attribute, old,new, kwargs):
self.log("Method ExitKtichen was called in the class KitchenCount")
if self.EntrySensorFirst == False:
self.log("ExitSensorFirst was first in the class KitchenCount")
self.ExitSensorFirst = True
else:
self.log("1 Person Entering Kitchen")
kitchen_count = self.get_state("sensor.people_in_kitchen")
self.log("kitchen_count is :" + kitchen_count)
new_kitchen_count = ktichen_count +1
self.log("new_kitchen_count is :" + new_kitchen_count)
self.set_state("sensor.people_in_kitchen", state = new_kitchen_count)