Wastenotification (Help Needed)

Just starting with appdaemon, the reason is the translate my yaml codes to appdaemon because I have to learn python also for my work. So what’s the most fun learning process for automating your home while you’re learning python and need some help

My first automation will be a notification when the waste must be placed at the street, and a day in front on 19:00 I would like to recieve a notification on my phone.

This is the start of my code and with the time i’ve got some issues:


import appdaemon.appapi as appapi
import datetime, timedelta, time

# Notifications when waste container can be placed at the street.

class Wastenotifications(appapi.AppDaemon):

  def initialize(self):
    # set time for 19:00.
    time = datetime.time(19, 00, 0)
    # listen for state change of the sensors.
    self.listen_state(self.morgen, "sensor.waste_next_green", new="morgen")
    self.listen_state(self.morgen, "sensor.waste_next_grey", new="morgen")
    self.listen_state(self.morgen, "sensor.waste_next_paper", new="morgen")
    self.listen_state(self.morgen, "sensor.waste_next_packages", new="morgen")

    
  def morgen (self, entity, attribute, old, new, kwargs):
    if self.time()
      self.

your approach is wrong.
you are listening to the change from your sensors, but that would only trigger once as it is set to “morgen” (probably at 0:00 )
so what you want to do is a
run_daily at 19:00 and then a check with get_state to see if your sensors have the value “morgen”

i have something like that also.
it generates a spoken message every hour untill an input_boolean is flipped to off.

Great thanks for your help !

But listen in the following scripts looks like is not working, or is this command not possible? :slight_smile:

import appdaemon.appapi as appapi
import datetime

class MotionLights(appapi.AppDaemon):
  def initialize(self):
    # Create a time object for 7pm
    time = datetime.time(18, 15, 0)
    # Schedule a daily callback that will call run_daily() at 7pm every night
    self.run_daily(self.run_daily_callback, time)
    self.listen_state(self.morgen, "input_boolean.test", new = "on")
   

  def run_daily_callback(self, kwargs):
   # listen for state change of the sensors.
    self.listen_state(self.morgen, "sensor.waste_next_green", old = "Morgen", new = "Morgen")
    self.listen_state(self.morgen, "sensor.waste_next_grey", new = "Morgen")

listen is to listen to changes.
and you want to know the state from that moment, so you need get_state.

i advice you to read the docs 2 or 3 times, esspecially the API
http://appdaemon.readthedocs.io/en/latest/APIREFERENCE.html

my tutorials probably coyld also give you some insight.

Thank you for your support!

Slowly there is more a code and some parts are also working :smiley:

Some things I got some issues with is the time based function and when I use the test case for the input boolean then it stops in the daily callback.


import appdaemon.appapi as appapi
import datetime

# Recieve a notification Daily on 19:00 when the container me be placed at the street

class Wastenotifications(appapi.AppDaemon):
	#Create a list of waste sensors
    def initialize(self):
        self.waste_entities = ['sensor.waste_next_green', 'sensor.waste_next_grey', 
                              'sensor.waste_next_packages', 'sensor.waste_next_paper']
    #Create a library
        self.waste_library = {}
		
    # Create a time object for 19:00
        time = datetime.time(9, 41, 30)
		
    # Schedule a daily callback that will call run_daily()
        self.run_daily(self.run_daily_callback, time)

    # Test Input Boolean for testing the script		
        self.listen_state(self.run_daily_callback, "input_boolean.test", new = "on")		
		
        for Morgen in self.waste_entities:
            self.listen_state(self.run_daily_callback, entity=Morgen)

    def run_daily_callback(self, entity, attribute, new, time, kwargs):
        self.log("Run Daily Callback")

       if new == 'Morgen':
	        self.waste_library[entity] = self.run_in(self.notifier, 
                                                          seconds=0, 
                                                          entity_name=entity)

    def notifier(self, kwargs):
        self.log("Notifier")
        friendly_name = self.get_state(kwargs['entity_name'], attribute='friendly_name')

        title = "Afvalinzameling"
        message = "De {} word morgen opgehaald.".format(friendly_name)                                               
																	  
        self.call_service('notify/ios_iphone_****', title=title, message=message)  	
1 Like

thats because you try to use the same callback for 2 types of things.
listen state needs a callback with 5 arguments, and a time based callback (run_daily) needs just 2 arguments.
so if you try to use the input boolean to call the listen_state type callback you get an error saying that you have to little arguments.

but you really dont want the listen_state at all.

import appdaemon.appapi as appapi
import datetime

# Recieve a notification Daily on 19:00 when the container me be placed at the street

class Wastenotifications(appapi.AppDaemon):
	#Create a list of waste sensors
    def initialize(self):
        self.waste_entities = ['sensor.waste_next_green', 'sensor.waste_next_grey', 
                              'sensor.waste_next_packages', 'sensor.waste_next_paper']
    #Create a library
        self.waste_library = {}
		
    # Create a time object for 19:00
        time = datetime.time(9, 41, 30)
		
    # Schedule a daily callback that will call run_daily()
        self.run_daily(self.run_daily_callback, time)

    def run_daily_callback(self, kwargs):
        self.log("Run Daily Callback")

        for Morgen in self.waste_entities:
          if self.get_state(Morgen) == 'Morgen':
	        self.notifier(Morgen)

    def notifier(self, entity):
        self.log("Notifier")
        friendly_name = self.get_state(entity, attribute='friendly_name')

        title = "Afvalinzameling"
        message = "De {} word morgen opgehaald.".format(friendly_name)                                               
																	  
        self.call_service('notify/ios_iphone_****', title=title, message=message)  	

Ah perfect ! Great really appreciate your help!

Now I’m looking for how to split the friendly_name so another thing to dig in for today :slight_smile:

1 Like

remember,

  • take small steps
  • make sure you catch all errors
  • check them after every change
  • try to interprete and learn from the errors.
1 Like