I am now seeing an error in my home assistant log:
Any insight would be appreciated. Thanks!
core-ssh:/config# tail home-assistant.log
exec(compiled.code, restricted_globals, local)
File "light_fader.py", line 14, in <module>
ZeroDivisionError: division by zero
2019-12-10 23:32:31 ERROR (SyncWorker_19) [homeassistant.components.python_script.light_fader.py] Error executing script: division by zero
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 195, in execute
exec(compiled.code, restricted_globals, local)
File "light_fader.py", line 14, in <module>
ZeroDivisionError: division by zero
Wild guess: start pct = end pct? Would explain the “divide by zero”
I am fighting this error with a simple call service try. I use Milights, simple python scripts and all else works though.
Error executing script: 'int' object is not subscriptable
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 195, in execute
exec(compiled.code, restricted_globals, local)
File "light_fader.py", line 12, in <module>
File "/usr/local/lib/python3.7/site-packages/RestrictedPython/Eval.py", line 35, in default_guarded_getitem
return ob[index]
TypeError: 'int' object is not subscriptable
Another day of trying, I dont really get it to work, but at least I have a new error :-X
Some more infos:
Normal transitions work fine in HA
I built an esp8266_milight_hub and integrated the bulbs via MQTT Autodiscovery. Transitions sthould also work regarding the documentation, but as “non-integer values are supported”, I wonder if this could be the cause of the error.
Without further coding skills I would guess that the scripts wants an int but gets an float… or sth. like this.
I will try a manual MQTT setup later, but maybe you guys may have a clue whats wrong here.
Thanks
Kelvin
Error executing script: 'NoneType' object has no attribute 'lower'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 195, in execute
exec(compiled.code, restricted_globals, local)
File "light_fader.py", line 3, in <module>
File "/usr/src/homeassistant/homeassistant/core.py", line 887, in get
return self._states.get(entity_id.lower())
AttributeError: 'NoneType' object has no attribute 'lower'
Thank you to Frank and Finny for creating the python code. My house is about 90% Lutron Caseta, and this has been a huge help in creating easy to manage transitions.
Glad you found it useful. Kudos to Finny Samuel for the original post that gave inspiration to the structure of the routine (Light Fader - Quick and Dirty ).
could you change this script to use it for volume fading on a media player? It is a feature i have been looking for for a long time. Tried some things but did not get it working. I was thinking about swapping all the light services and attributes for music_player services and attributes.
I expect that you could, and the concept would be the same, but the values that you set in each iteration would be specific to whatever scale fits the device you are controlling (i.e. 1 - 255 works for lights, but it will be something else for your TV or receiver.)
If I wanted to create a sensor that would state when the given entity is transitioning (so I can change the display of a button when it’s in progress). How would I go about doing that?
I’m assuming you know how to make the button change, based on some sensor value, so you just need some ideas for the sensor. You can use the template binary sensor , which will change from on to off based on the state of other entities. The only entity I can think of for this situation, is one you create, like an input boolean. (Might be something simpler, but nothing occurs at the moment).
So the idea I have is to base the template sensor on the state of the input boolean. When you start the transition, call the input_boolean.turn_on service to set the boolean to true/on, which in turn sets the sensor to on. That gives you an indication that the transition has begun.
Assuming that you want the display of the button to change back something else when the transition is done, I think you would have to create an automation that kicks in when one of the entities reaches the end state. For example if the transition ends at a certain brightness, have that state value be a trigger to run the input_boolean.turn_off service and reset the input boolean, thereby changing the sensor, and your button.
Of course, if you can base your button display on the state of the input boolean, then the sensor is redundant … but you did ask about a sensor.
Hi All
I’ve noticed that I am no longer able to run this light fader python script (after a recent home assistant update?). Has anyone had similar issues recently?
It still works for me, although the first time I ran it the response was delayed.
I haven’t had time to debug yet, but I did just post a way to achieve pretty much the same effect, entirely in YAML. Won’t work so well for quick transitions, less then 15 seconds, but seems to work fine for slower transitions. YAML Light Fader for light entities that don’t support “transition”
Hi, can you make it so it calculates how much steps_pct is has to do instead of the default 1.
Like maybe have it calculate based on transition time and remaining pct? Like if I want to have it go from 1 to 100 in 15sec that it will calculate that is has to take steps of 6.67 now I have to have a minimum of 100seconds transition for 1-100 to work. If I do less than 100seconds for a 1-100 transition it will not go to 100pct but stop before it reaches 100.
Hi. The script is just an example I have shared so others can do with it what they will. You could certainly make changes along the lines of what you suggested, although you might have to do some rounding on those percent changes.
I have never worked with python before but it didn’t look that hard to understand. I’ve added a data get into the step_pct and added the option to rgb_color , color_temp to be able to change the colors/white.
I have a lutron system in my house as well. I tried your automation and your python script, but the brightness never changes to more then 5% when i use it with a lutron light. it works with hue lights though, any ideas on what the issue could be?
Possibly because the Lutron integration doesn’t like receiving a stream of commands?
All that this python_script does (and the other version you tried in the other thread), is send a stream of light.turn_on commands containing increasing values of brightness. The number of commands, the time between each command and the amount of each brightness increase is calculated by the script.
You can manually simulate it using Developer Tools > Services. Call the light.turn_on service for a Lutron light using a brightness value of 125. Immediately call the same service with a value of 130. Increment and repeat as fast as you can (on the order of 1-5 seconds between service calls). That’s what the script does. By doing this manually, you will quickly discover if the Lutron integration supports this kind of operation.
Thanks for this script… it’s a great idea that fills a great need. I am struggling to get this to work, and am finding that it sets the starting brightness correctly, but stays there. I am new to Python but don’t see any flaws in the code. I’ve tried this with several devices, particularly Z-wave dimmer switches. My goal is to be able to (say) fade a light from 20% to 100% over about an hour, and vice versa. So far my testing has been shorter durations (e.g. 30-60 seconds) if that makes a difference.