Hi
I’m a little fustrated atm as I’ve been trying to use a group I call kitchen_motion to trigger my automation in AppDaemon.
but it doesn’t report any errors nor does it work.
Here is how I’m using it:
class light_on_motion(hass.Hass):
def initialize(self):
self.log("Method initialize was called in the class light_on_motion")
self.default_light_level_threshold = float(20)
self.yeelight_specialcase = self.args["yeelight_specialcase"][0]
self.get_up_time = "08:00:00"
self.luxsensor = self.args["lux_sensor"][0]
self.bedtime = "20:00:00"
self.lights = self.args["lights"]
self.handles =[]
trigger = self.args["sensors"]
self.listen_state(self.AutoLightOnMotion,trigger,new="on")
here is where I’m giving the group in my Apps.yaml
The state of a group is “off” unless all members of the group are “on”, so all your motion sensors need to be “on” at the same time to trigger listen_event.
It is because you’re essentially passing in [“kitchen_motion”] as the entity ID to the listen_state() which is not a valid entity ID. So the callback never fires.
maybe a noob question but if I can’t do it this way then what would I give the listen_state() to make sure it triggers when any of the sensors detect activity?
You have to give it the full entity name. In your case it might be “group.kitchen_motion”. The listen_state() method is supposed to accept strings and lists but please understand the behavior of that. If you pass in a list of entities to listen_state(). It will run the same callback when the state changes for any of the entities that are in the list. You’re currently passing in a single item list.
You can create a template binary sensor to active your app like so
- platform: template
sensors:
people_home:
device_class: occupancy
value_template: >-
{{ is_state('person.travis', 'home')
or is_state('person.conrad', 'home')
or is_state('person.victoria', 'home')
}}
OR
you can listen to each sensor directly with a for loop like so
for sensor in sensors:
self.listen_state(self.change_detected, sensor)
def change_detected(self, entity_id:str, attribute, old: str, new: str, kwargs = None) -> None:
"""Double checks things whenever there is a change"""
name: str = self.friendly_name(entity_id) # gets the name of the entity
self.log(
f"__function__: {entity_id} changed from {old} to {new}", level='DEBUG')
if old != new:
self.log(f"__function__: {name} changed from {old} to {new}")
so if I want it to only run when the group state changes then I’m doing it wrong ?
my requirements could be summed up like this:
scenario Turn on lights
given we have multiple sensors in the group
when any sensors state is changed from inactive to active.
then turn on the lights
scenario turn off lights
given we have multiple sensors in the group
when the sensors state is changed from active to inactive.
And all other sensor state in the group is inactive.
then turn off the lights
It is easiest just to listen to the group entity. That is the reason you create a group in the first place. You can also listen to each individual entity as well. It is totally up to you.
I thought I was listening to the group entity, which didn’t seem to work. Which is why I’m asking for help as I could not find anything in the documentation of appdaemon or home assistant to suggest what I was doing wrong.
According to your YAML, you have specified your sensor as “kitchen_motion” but that is not a valid entity. If it is a group then the entity is going to be “group.kitchen_motion”. That is the main issue right now so I’d work from there.
I ended up updating and make use of the group you can make in the helpers interface.
That solved my issue with not getting access to my groups in Appdaemon. now it seems to work the way I intended.