AppDaemon Q&A

thats why i would put those data in the config file.

then it would look something like:

[Heating office]
module = heating_schedule
class = HeatingSchedule
radiotor = climate.danfoss_z_thermostat_014g0013_heating_1_2
amount_of_changes = 2
change1 = wd,17,13,23
change2 = wd,14,14,21

[Heating kitchen]
module = heating_schedule
class = HeatingSchedule
radiotor = climate.danfoss_z_thermostat_014g0013_heating_1_6
amount_of_changes = 2
change1 = we,12,00,23
change2 = wd,18,00,20

and with every change it automaticly reinitializes

Ah, I see.
I thought about something like that too at first, but I didn’t like that there is no “elegant” way of dealing with potentially varying number of changes.
The change1, change2… variables are one way to do this.
You probably have a loop in your app that then goes from 1 to “amount_of_changes” and processes the change variable.
But then you have to deal with cases where you delete changes from inside that range.
Or you start renumbering all the changeXs…

It would be cool if appdaemon would support something like

[app]
...
foo = 1
foo = 2
foo = 3

and you would get a list foo = [ '1', '2', '3' ] to use inside your app.

Sebastian

i think you could also do it like this:

changes = we:12:00:23, wd:18:00:20

and then first split on “,” and after that on “:”

then you dont need numbering at all.

Hey guys! Every time I reload a module I get:

2016-10-22 19:45:59.019179 WARNING ------------------------------------------------------------
2016-10-22 19:45:59.023683 WARNING ------------------------------------------------------------
2016-10-22 19:45:59.024374 WARNING Unexpected error during loading of Sunset:
2016-10-22 19:45:59.025084 WARNING ------------------------------------------------------------
2016-10-22 19:45:59.026431 WARNING Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 685, in readApp
    init_object(name, class_name, module_name, config[name])
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 466, in init_object
    module = __import__(module_name)
ValueError: source code string cannot contain null bytes

Even more errors, one for each script I have:

2016-10-22 21:00:24.441554 WARNING ------------------------------------------------------------
2016-10-22 21:00:24.443329 INFO Loading Module: /home/hass/.homeassistant/apps/sunset.py
2016-10-22 21:00:24.446778 WARNING ------------------------------------------------------------
2016-10-22 21:00:24.447760 WARNING Unexpected error during loading of sunset.py:
2016-10-22 21:00:24.448704 WARNING ------------------------------------------------------------
2016-10-22 21:00:24.451255 WARNING Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 675, in readApp
    conf.modules[module_name] = importlib.import_module(module_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 661, in exec_module
  File "<frozen importlib._bootstrap_external>", line 767, in get_code
  File "<frozen importlib._bootstrap_external>", line 727, in source_to_code
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ValueError: source code string cannot contain null bytes

I can’t quite figure out what’s wrong, any hints? :slight_smile:

Hmm, it would seem like my AFP-connection via netatalk created .appledouble files matching each file, and that created the mess… A shame I can’t use AFP, then :frowning:

I am trying to turn on and input_boolean Turn_on for input_boolean type

I tried to use

self.turn_on("input_boolean.etrv_329_diagnostic_mc_below") 

but nothing happened, so I tried

self.call_service("input_boolean.turn_on", entity_id = "input_boolean.etrv_329_diagnostic_mc_below")

and that comes up with the error

  File "/home/graham/lib/python3.5/site-packages/appdaemon/appdaemon.py", line 424, in worker
    function(entity, attr, old_state, new_state, ha.sanitize_state_kwargs(args["kwargs"]))
  File "/home/homeassistant/.homeassistant/apps/etrv_diagnostics.py", line 44, in new_diagnostics
    self.call_service("input_boolean.turn_on", entity_id = "input_boolean.etrv_329_diagnostic_mc_below")
  File "/home/graham/lib/python3.5/site-packages/appdaemon/appapi.py", line 248, in call_service
    self._check_service(service)
  File "/home/graham/lib/python3.5/site-packages/appdaemon/appapi.py", line 34, in _check_service
    raise ValueError("Invalid Service Name: {}".format(service))
ValueError: Invalid Service Name: input_boolean.turn_on

My service tab says that turn_on is a valid service for an input_boolean, so is it just not implemented in appDaemon?

I can change the state with set_state, so I have the names ok.

Not sure why self.turn_on() isn’t working but for a service name you need a / not a . so it should be:

self.call_service("input_boolean/turn_on", entity_id = "input_boolean.etrv_329_diagnostic_mc_below")

are you sure that the line with self.turn_on gets activated?
i turn on and off inputbooleans all the time like that.

2 possible problems:

  1. typo in the name
  2. an error before the line

Here is my code

        if obj["Motor current below expectation"]:
            self.log("Turning on {}".format(self.mc_below))
            self.set_state(self.mc_below, state = "on")
            #self.call_service("input_boolean/turn_on", entity_id = self.mc_below)
        else:
            self.log("Turning off {}".format(self.mc_below))
            self.set_state(self.mc_below, state = "off")
            #self.call_service("input_boolean/turn_off", entity_id = self.mc_below)

Using self.state works fine, so self.mc_below has the correct entity_id, but the call_service does not change the state.
The output log is

2016-11-09 14:12:43.201203 INFO lounge_etrv_diagnostics: Turning on input_boolean.etrv_329_diagnostic_mc_below
2016-11-09 14:13:02.253100 INFO lounge_etrv_diagnostics: Turning off input_boolean.etrv_329_diagnostic_mc_below

There is an error in the API docs. The first line of the call_service examples read

self.call_service("light.turn_on", entity_id = "light/office_lamp", color_name = "red")

Apparently the ‘.’ and ‘/’ need to be reversed.

I’ve done some more experimenting. I can use call_service on other input_booleans, so there is something special about this one.

is the input boolean depending on a entity that wont change?

I managed to make it work when I removed the capital letters from the name of the input_boolean in configuration.yaml. I’m new to HA, so I’m not sure if this is a bug or capital letters are not allowed.

1 Like

im not new anymore but im still not sure about that :wink:

i never found anything about it in the documentation, but i learned the hard way not to use capitals.
and since then i even avoid numbers (had a problem with that somewhere to) and anything else except normal characters, if i can off course.

I don’t believe it’s ever been explicitly stated but I’ve never seen any examples of entities with caps so I have always considered it was the rule.

What would be the simplest way with appdaemon to save and restore the state of a set of lights? I want to save the current state of the lights when I trigger a specific scene and then restore it later. Any help would be appreciated!

You can use get_state() to grab the state info you are interested in and store it in a class variable. Then later on, you can use turn_on() to set the states back the way they were.

Thanks! I am very inexperienced in Python. Do you have a simple example of how the code would look?

I’m toying with this myself right now.

My current playground:

  def initialize(self):
    self.previous_state = 0
    self.listen_state(self.change, self.args["appdaemon_trigger"])
    self.listen_state(self.reset, self.args["appdaemon_boolean"])
    self.log("AppDaemon test initialized!")
  
  def change(self, entity, attribute, old, new, kwargs):
    self.previous_state = self.get_state("light.rgb_lamp_1", "brightness")
    self.turn_on("light.rgb_lamp_1", brightness = 30)

  def reset(self, entity, attribute, old, new, kwargs):
    self.turn_on("light.rgb_lamp_1", brightness = self.previous_state)

Is that in any sort of a functioning state currently? If so, do you have any more details about how it is configured within HASS?