The code below will turn off all lights and switches rather than the one specified in the apps.yaml. Hoping someone could assist with changing it so it will only turn off the entities listed in apps.yaml.
First, this line is not needed, as the closetlightcontrol will only be called if the new state is “on” for 5 seconds (duration=5).
if new == "on":
The code you wrote will turn off “switch.zooz_zen21_switch_v2_0_switch” if it has been in the state “on” for 5 seconds. This will not affect any other light, could it be that you have other automations that do something when this switch is turned off?
If you could tell me what you exactly want to do, I can help you to write the code. Do you just want the light to go off after 10 minutes?
I am trying to create an app that will turn off any switches or lights that are listed in the entities list of the apps.yaml after 10 minutes. I will use these mostly for closets but also for the laundry room as my kids often leave these on.
Also I just turned off all of my automation’s and reloaded automation’s and tested and it’s turning off the following entities: light.jasco_products_14294_in_wall_smart_dimmer_level, switch.lamp and switch.zooz_zen21_switch_v2_0_switch. I haven’t tested with any other items but I would imaging it would turn off other as well. This baffles me as I don’t run node red or anything else that could be causing this to happen. I even changed the entity in the apps.yaml to switch.lamp and it seems to affect all switches and lights.
Here is the updated code I tested with
import appdaemon.plugins.hass.hassapi as hass
# Closet Timer
class tenminutelighttimer(hass.Hass):
def initialize(self):
for switch in self.args["entities"]:
self.listen_state(self.closetlightcontrol, new="on",
duration=5) # wait for 10 min
def closetlightcontrol(self, entity, attribute, old, new, kwargs):
self.turn_off(entity)
self.log("""Line: __line__, function: __function__,
Message: Closet Light Turned off""")
Thanks a bunch. This resolved the issue. I can’t believe I missed this. I am very new to appdaemon and I’m hoping to use it to start learning python. Thanks again!