AppDaemon Q&A

i think there is an small bug in run_minutely:

2016-08-31 01:59:21,807 WARNING Unexpected error:
2016-08-31 01:59:21,807 WARNING ------------------------------------------------------------
2016-08-31 01:59:21,807 WARNING Traceback (most recent call last):
  File "c:\python34\lib\site-packages\appdaemon\appdaemon.py", line 362, in worker
    function()
  File "C:\Users\rene\AppData\Roaming\.homeassistant\apps\objectcontrole.py", line 19, in initialize
    self.run_minutely(self.object_controle_minutely, time)
  File "c:\python34\lib\site-packages\appdaemon\appapi.py", line 322, in run_minutely
    event = event.replace(minute = event.minute + 1)
ValueError: minute must be in 0..59

2016-08-31 01:59:21,807 WARNING ------------------------------------------------------------

May well be true - how did you call it?

  def initialize(self):
    self.listen_state(self.object_controle, self.args["object_type"])
    if self.args["time_gone_by"] == "true" or self.args["time_gone_by"] == "True":
      time = datetime.time(0, 0, 0)
      self.run_minutely(self.object_controle_minutely, time)

but it seems like it only happens when i start the app at ?:59 new.
and i seem to have another randomly occuring error that is bugging me, so if you dont see a problem in your code there may be something else happening here.

From the API documentation, the following line should be correct for retrieving a dictionary of the state data for all of my binary sensors:

state = self.get_state(“binary_sensor”)

However, I am getting this error in the log:

2016-08-30 23:59:46,037 WARNING Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 364, in worker
    function(args["kwargs"])
  File "/home/hass/.homeassistant/appdaemon/conf/apps/alarm/check_home_secure_on_arming_alarm.py", line 17, in check_house_state
    state = self.get_state("binary_sensor")
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/appapi.py", line 87, in get_state
    self._check_entity(entity_id)
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/appapi.py", line 22, in _check_entity
    raise ValueError("{}: Invalid entity ID: {}".format(self.name, entity))
ValueError: check_home_secure_on_arming_alarm: Invalid entity ID: binary_sensor

OK, I’ll try and take a look at both of these today.

Ok, just pushed a bugfix release to address both issues:

2 Likes

Wow, that was fast! :grinning: Just can’t thank you enough!!!

1 Like

More importantly, does it work?

oke, so you found something :slight_smile:
i will update later, when i have the time.

Yep, it was a wrong assumption on my part about how the Python date libraries work - I changed the technique I was using to add 1 minute to the base time to fix it.

1 Like

Oh, I’m sorry, I should have mentioned if it actually fixed my problem lol Yes, it worked perfectly. Today alone I was able to replace 12 automations with only 4 appdaemon Apps!!

1 Like

Excellent! Glad to hear it is working it for you :slight_smile:

Oh, btw, I forgot to mention this. The appdaemon API Docs say to use the following format for calling a service:

self.call_service(“light.turn_on”, entity_id = “light.office_lamp”, color_name = “red”)
self.call_service(“notify.notify”, title = “Hello”, message = “Hello World”)

However, dot notation does not work for calling services, rather forward slash notation has to be used

self.call_service(“light/turn_on”, entity_id = “light.office_lamp”, color_name = “red”)
self.call_service(“notify/notify”, title = “Hello”, message = “Hello World”)

If I use dot notation, appdaemon will throw an error.

All of my apps are using forward slash notation, but I don’t know why I would have done that in the first place since the docs say otherwise.

I’m not sure if you wanted it as “service.servicename” or as “service/servicename”, however, the slash notation is in all my apps and works fine, but the API documentation still says to use dot notation, which does not work.

in yaml it is dotted, but in the frontend with slash
i guess thats what made andrew go the wrong way at first and he forgot to change the API.

Correct - I changed it from “.” to “/” before I released v1.0, and I thought I had fixed the docs but I guess not :slight_smile: Thanks for spotting that, I’ll fix it.

1 Like

Andrew, you are more genius than you think!

you know what i was trying to accomplish.
and i had it working

i made 2 apps.
1 to listen to minutes or to state change.
1 for general functions, which saved the times in different files that could be compared.
i made an commandlinesensor for all the objects i wanted to checkup on.
and after all the little bugs i had (some difficult to find) removed, i was satisfied.
it worked and finally without strange updates.

then i thought: havent i seen somthing about creating battery sensors automaticly?
i looked that up and started trying to make a custom component.
that would make it easier then creating lots of commandline sensors, dont you think?
i made something like the hello_state and i tried to update that component with your set_state (you know the problems i had with input_slider and template sensor)
and it works like charm.
so that gave me confidence to go on.
but i struggled.
i took a look at how template sensors are setup and tried to simplefy that.
i didnt get it working.
and suddenly there it was:

you dont need any sensor in the YAML!!
your set_state creates 1 and you can give it any name and platform you like and update it anyway you want.
off course you can set attributes to!

off course it is to bad from all my work, which i now can flush down the drain.

all you need is some code like this:

import appdaemon.appapi as appapi
import datetime

class objectcontrole(appapi.AppDaemon):

  def initialize(self):
    self.listen_state(self.object_controle, "input_boolean")
      
  def object_controle(self, entity, attribute, old, new, kwargs):
    update_time = datetime.datetime.now().strftime("%H:%M:%S")
    self.set_state("controle_" + entity, state = update_time) 

off course i can use small part from my work to save the time and compare it, so i can see time gone by.
but for now i’m starting to downsize again, because off you! :wink:

That’s really cool, but I give the credit to Home Assistant for being so open and extensible :wink:

That’s a really neat discovery you made!

I am unable to use set_state on non existent entities. When I try to set_state on an entity that does not exist in Home Assistant, I get the following error:

2016-09-01 19:38:03,700 WARNING set_state: Entity battery_level.media_room_window not found in Home Assistant

** UPDATE **
Nevermind, not an issue… it gives a warning, but it still allows it to go through, so thats not a problem :smiley: Thanks!!!

now you say that i see the warnings also.
and they keep on coming, even though the object is created, so the warning should dissapear.

it can be that the object misses a part which lets it be there, but not really be there.

maybe we could examine the set_state to see if it can made a bit better.
atrributes are not set in this case.

I’ll look into this -

Based on how AppDaemon is working I would expect the warnings to stop after up to 10 minutes or so -0 can you confirm if that is the case? Either way I’ll look at a fix so that it warns you the first time but not after that.