Appdaemon error setting input_boolean state

The following lines of code are generating an error and I’m not sure why.

        self.log("component {} - input_boolean level={}".format(component,level),"INFO")
        self.set_state(component,state=level)                 # set ha value for input boolean

Here is the appdaemon.log output related to the error

2017-01-17 15:23:21.532100 INFO printermonitor: component input_boolean.ofhp1tonerlow - input_boolean level=0
2017-01-17 15:23:21.558866 WARNING Logged an error to /home/hass/appdaemon/appdaemon.err

Here are the lines from the appdaemon.err file related to the error.

2017-01-17 15:23:21.557585 WARNING Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/", line 422, in worker
  File "/home/hass/code/appdaemon/", line 19, in initialize
  File "/home/hass/code/appdaemon/", line 96, in check_printers
    self.set_state(component,state=level)                 # set ha value for input boolean
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/", line 177, in set_state
  File "/usr/local/lib/python3.4/dist-packages/requests/", line 893, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:8123/api/states/input_boolean.ofhp1tonerlow

If I enter in the HTTP url in the browser, I get back the information on the appropriate component. So I’m a little confused.

Couple of things that may be at issue:

  1. An input boolean can only be “on” or “off”, not “0”.

  2. If you actually want to toggle it you need to call a service to do so, not set its state, e.g.


However, looking at your code I am not sure exactly what you are trying to do here - looks like you are working with custom attributes - either way, you probably can’t set the state to “0”.

Ahhh, ok
I’ll give that a try. I’m using it as a flag to show if a printer is low on toner or not. The return from the SNMP query is a 0 or a 1 and I was just passing it, thinking it was like a true or false kind of thing.

Yep that worked.