Entity brightness attribute returning "NoneType"

Hey everyone,

I am trying to run a script in appdaemon and I am hung up on an issue I came across. I am pulling the “brightness” attribute from a Jasco in wall smart dimmer (zwave) and trying to compare it to a known value. The issue I have is that the returned value from self.get_state is returning as a nonetype rather than a str, float, or int. Does anyone know why this is happening or how to solve it?

brightness_compare = self.get_state("light.switchlight_livingroom", attribute = "brightness")
if brightness_compare > new_level:
    self.log("brightness is: %s", brightness_compare)

What I get in the logs is:

2021-10-26 11:12:53.875306 WARNING Error: ------------------------------------------------------------
2021-10-26 11:16:17.127142 WARNING flash: ------------------------------------------------------------
2021-10-26 11:16:17.128545 WARNING flash: Unexpected error in worker for App flash:
2021-10-26 11:16:17.129546 WARNING flash: Worker Ags: {'id': 'e2ffc5157292466eba75ea449e117268', 'name': 'flash', 'objectid': 'b699a959799641ecad0ad489be6129a0', 'type': 'state', 'function': <bound method FlashLight.flash of <flash.FlashLight object at 0x7f95314760>>, 'attribute': 'state', 'entity': 'input_boolean.start', 'new_state': 'on', 'old_state': 'off', 'pin_app': True, 'pin_thread': 1, 'kwargs': {'new': 'on', '__thread_id': 'thread-1'}}
2021-10-26 11:16:17.130969 WARNING flash: ------------------------------------------------------------
2021-10-26 11:16:17.136444 WARNING flash: Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/appdaemon/threading.py", line 903, in worker
    funcref(
  File "/config/appdaemon/apps/flash.py", line 35, in flash
    if brightness_compare > new_level:
TypeError: '>' not supported between instances of 'NoneType' and 'float'

I apologize if this is a silly question I am still fairly new to HA and python.

Thanks,

-Dave

Put the log statement before the comparison, then you can see what the value is.
For me it looks like it doesn’t get a value at all. Is the light turned on? If the light is turned off, there’s no brightness attribute, then your function will return None. Also ensure that the entity_id is correct.

Anyway, is there a reason to use AppDaemon instead of the built-in HA automations? I’ve been a hravy user of AppDarmon as well in the past, but moved over everything to built-in automations as they are powerful enough.

Thanks for such a quick reply!

If I take the compare statement out and run it then the log prints out 255 which makes sense since the light is at 100% brightness.

The reason I am doing this in appdaemon is because I am making a light dim slowly over the course of an hour or longer and I have it take inputs from two sliders on my dashboard (one gives it a starting brightness and one gives it a duration) I was able to get the dimming to work wonderfully now I am just trying to build in an escape that stops the script if someone were to hit the switch on the wall or on the dashboard.

Ok, what about new_level is it defined correctly?

What’s the result of:

self.log(type(brightness_compare))
self.log(type(new_level))

ok so I did some more digging based on the type command you put in your previous reponse and found out that I have not been seeing what I thought I was seeing. for some reason if I use this:

self.call_service("light/turn_on", entity_id = "light.switchlight_livingroom", brightness = new_level)

Then the light will turn on or if it is already on it will adjust to whatever the new_level argument is. However if I check:


states = self.get_state("light.switchlight_livingroom")
self.log(states)

I get the following which tells me that “brightness” is not actually an attribute:

2021-10-26 14:19:22.851656 INFO flash: {'entity_id': 'light.switchlight_livingroom', 'state': 'off', 'attributes': {'supported_color_modes': ['brightness'], 'friendly_name': 'switch.light_livingroom', 'supported_features': 32}, 'last_changed': '2021-10-26T18:19:22.795904+00:00'

What is confusing me now is how I am able to use brightness in the original self.call_service if it is not an attribute within the entity. I know I may have just created more questions than answers but does this help at all and is there a way I can use the supported_color-modes to reference the brightness level at a given time? Running self.get_state("light.switchlight_livingroom", attribute = "supported_color_modes" returns ['brightness']

As I told you in the beginning, if a light is off it doesn’t have an attribute brightness, so if you try to get state of the brightness it will return nothing. You can also see this in Home Assistant under Developer Tools → States, when the light is off, you don’t see brightness, color temp etc.

However, you are still able to turn the light on with a brightness specified.

Yeah you were right from the get go. Turns out I was writing the log before my self.call_service command and I just missed it in the code so I saw the light turning on in real life but it did not register that it was happening after I wrote the log and by extension was trying to pull the brightness attribute before it was on. flipping the two lines appears to have solved the problem. Thank you so much for all of your help on this!