@handcoding I am trying this fader script for the first time and I’m getting the following in my logs when I try to run it:
2024-11-11 08:15:26.727 INFO (MainThread) [homeassistant.components.automation.living_room_wake_up] Living room wake up: Running automation actions
2024-11-11 08:15:26.727 INFO (MainThread) [homeassistant.components.automation.living_room_wake_up] Living room wake up: Executing step call service
2024-11-11 08:15:26.728 INFO (MainThread) [homeassistant.components.script.ashley_s_light_fader] Ashley’s Light Fader: Running script sequence
2024-11-11 08:15:26.728 INFO (MainThread) [homeassistant.components.script.ashley_s_light_fader] Ashley’s Light Fader: Executing step setting variables
2024-11-11 08:15:26.738 INFO (MainThread) [homeassistant.components.script.ashley_s_light_fader] Ashley’s Light Fader: Executing step setting variables
2024-11-11 08:15:26.741 INFO (MainThread) [homeassistant.components.script.ashley_s_light_fader] Ashley’s Light Fader: If at step 5: Running script sequence
2024-11-11 08:15:26.741 INFO (MainThread) [homeassistant.components.script.ashley_s_light_fader] Ashley’s Light Fader: If at step 5: Executing step call service
2024-11-11 08:15:26.919 INFO (MainThread) [homeassistant.components.script.ashley_s_light_fader] Ashley’s Light Fader: Executing step setting variables
2024-11-11 08:15:26.925 ERROR (MainThread) [homeassistant.components.script.ashley_s_light_fader] Ashley’s Light Fader: Error executing script. Error rendering template for variables at pos 6: ZeroDivisionError: float division by zero
2024-11-11 08:15:26.929 ERROR (MainThread) [homeassistant.components.automation.living_room_wake_up] Living room wake up: Error executing script. Error rendering template for call_service at pos 1: ZeroDivisionError: float division by zero
2024-11-11 08:15:26.933 ERROR (MainThread) [homeassistant.components.automation.living_room_wake_up] Error while executing automation automation.living_room_wake_up: ZeroDivisionError: float division by zero
I’m using v2.0 of the script and the target entity is a group of Philips Hue bulbs integrated via the Hue Hub.
Any ideas on what I should try to resolve or troubleshoot the issue?
Thanks!
I’d like to run this automation script each day at dusk (which I know how to do) and set it to run until 23:00 (so the duration is obviously dynamic, depending on time of year). I’ve figured out how to calculate hours, minutes and seconds, but it seems I can’t use these in transitionTime (it won’t work):
action: script.ashley_s_light_fader
data:
lampBrightnessScale: zeroToOneHundred
easingTypeInput: linear
endBrightnessPercent: 0
endBrightnessEntityScale: zeroToOneHundred
autoCancelThreshold: 10
shouldStopIfTheLampIsTurnedOffDuringTheFade: true
shouldResetTheStopEntityToOffAtStart: false
shouldInvertTheValueOfTheStopEntity: false
minimumStepDelayInMilliseconds: 100
shouldTryToUseNativeLampTransitionsToo: false
isDebugMode: true
transitionTime:
hours: {{ ((now().replace(hour=23, minute=0, second=0, microsecond=0) - now()).total_seconds() // 3600) | int if now().hour < 23 else 0 }}
minutes: {{ (((now().replace(hour=23, minute=0, second=0, microsecond=0) - now()).total_seconds() % 3600) // 60) | int if now().hour < 23 else 0 }}
seconds: {{ ((now().replace(hour=23, minute=0, second=0, microsecond=0) - now()).total_seconds() % 60) | int if now().hour < 23 else 0 }}
light: light.shelly_dimmer2_26_1_2
Hi, @Thomas39!
Going by your screenshots, it looks like you might be trying to run the script directly from its script page?
In this case, Ashley’s Light Fader is meant to be run from another automation or from another script. So for example, you might try these steps:
- Create a new blank automation by going to Settings → Automations & scenes → Create Automation.
- From there, under the Then Do section, choose Add Action.
- Then, within the Search action box, if you search for “Ashley”, the script should come up.
At that point, you should be able to apply the settings of your choosing.
(And if you might get stuck anywhere along the way, please feel free to reply here, and we’ll be happy to help you out!)
@2xaronl Out of curiosity, do things run any better if you target the bulbs individually? Or—as another potential idea—do things run any better if you were to instead group those bulbs through Home Assistant and then target them that way?
(Part of why I ask is because I’m not sure how well Hue-hub-based groups might work with Home Assistant.)
@vision2003 For reasons that seemingly make sense only to Home Assistant’s dev team, if you’re using a single-line template, you have to wrap that in quote marks, such as along these lines:
action: script.ashley_s_light_fader
data:
lampBrightnessScale: zeroToOneHundred
easingTypeInput: linear
endBrightnessPercent: 0
endBrightnessEntityScale: zeroToOneHundred
autoCancelThreshold: 10
shouldStopIfTheLampIsTurnedOffDuringTheFade: true
shouldResetTheStopEntityToOffAtStart: false
shouldInvertTheValueOfTheStopEntity: false
minimumStepDelayInMilliseconds: 100
shouldTryToUseNativeLampTransitionsToo: false
isDebugMode: true
transitionTime:
hours: "{{ ((now().replace(hour=23, minute=0, second=0, microsecond=0) - now()).total_seconds() // 3600) | int if now().hour < 23 else 0 }}"
minutes: "{{ (((now().replace(hour=23, minute=0, second=0, microsecond=0) - now()).total_seconds() % 3600) // 60) | int if now().hour < 23 else 0 }}"
seconds: "{{ ((now().replace(hour=23, minute=0, second=0, microsecond=0) - now()).total_seconds() % 60) | int if now().hour < 23 else 0 }}"
light: light.shelly_dimmer2_26_1_2
Perhaps give that a go?
(And if by any chance that doesn’t solve things, feel free to reply here, and I’ll be happy to help you look into other ideas.)
Working perfectly, thank you!
Ah—wonderful news! Happy to help!
Hi Ashley, I’m having dramas with the transition, it’s just not being smooth enough. Had a read through this forum, played around with the min delay settings etc, but it just doesn’t look smooth, no matter if it’s 2 seconds or 25 seconds, it all looks too ‘choppy’. When I use the automation where I just set the brightness property (or turn on off the light) the default transition on the light just works great, however not when I want to work with the transition durations using your script.
The following log is for 2second linear transition (as that looks probably the best considering the options), to 50% brightness, with 50ms delay (min)
2024-11-19 08:56:54.401 WARNING (MainThread) [homeassistant.components.system_log.external] linear easing type with 50 ms delay. remainingTimeInMilliseconds = 1850, and absoluteBrightnessSpan = 50
2024-11-19 08:56:54.402 WARNING (MainThread) [homeassistant.components.system_log.external] startBrightness = 0, endBrightness = 50, and processingDelayInMilliseconds = 144
2024-11-19 08:56:54.711 WARNING (MainThread) [homeassistant.components.system_log.external] Set Dining Lights All to 4 brightness. (Linear brightness would have been 4.) Delay is 50 ms. Elapsed time is 0.46 seconds. (endBrightness is 50.)
2024-11-19 08:56:54.914 WARNING (MainThread) [homeassistant.components.system_log.external] Set Dining Lights All to 13 brightness. (Linear brightness would have been 13.) Delay is 50 ms. Elapsed time is 0.67 seconds. (endBrightness is 50.)
2024-11-19 08:56:55.116 WARNING (MainThread) [homeassistant.components.system_log.external] Set Dining Lights All to 18 brightness. (Linear brightness would have been 18.) Delay is 50 ms. Elapsed time is 0.87 seconds. (endBrightness is 50.)
2024-11-19 08:56:55.318 WARNING (MainThread) [homeassistant.components.system_log.external] Set Dining Lights All to 23 brightness. (Linear brightness would have been 23.) Delay is 50 ms. Elapsed time is 1.07 seconds. (endBrightness is 50.)
...
...
...
2024-11-19 08:56:56.240 WARNING (MainThread) [homeassistant.components.system_log.external] Set Dining Lights All to 38 brightness. (Linear brightness would have been 38.) Delay is 50 ms. Elapsed time is 1.99 seconds. (endBrightness is 50.)
2024-11-19 08:56:56.449 WARNING (MainThread) [homeassistant.components.system_log.external] Set Dining Lights All to 50 brightness. Elapsed time is 2.2 seconds.
Any thoughts on how to make this work? Is that because the lights have their own transition predefined? I’m a bit lost, so thanks for any pointers
Hi Ashley,
I have recreated the script and now the call action is able to turn on the light, but it just wont fade. I linked the E27 bulbs to be switched on by TPlink Wifi Smart Plug. These are just normal non smart bulbs. No matter how long I set the fade in duration, it won’t happen. The bulbs just turn on and off as it is, no fading. Am I missing something ?
If I understand what’s going on, you’re trying to use Ashley’s Light Fader on a smart plug. If so, that’s likely your issue.
Even if your bulbs support dimming by a traditional dimming switch, your smart plug won’t (think of the issues it could cause if you tried to dim your computer!).
Therefore, if you have HA set up to report your smart plugs as light entities (which I assume you must in order to select them in Ashley’s Light Fader), they will not have a brightness setting, only on/off.
You can check this by clicking on Developer Tools in the sidebar, then going to the “states” tab. In the “Filter entities” field, enter the entity ID of one of your lights. You will see something like this:
In this photo, light.hallway_front
is a Philips Hue bulb, and you can see that its supported_color_modes
attribute is set to color_temp
.
According to the documentation, this means that: “The light can be dimmed and its color temperature is present in the state”.
Looking, however, at the light.living_room_lamp
, which is a TP-Link Tapo smart plug with a standard floor lamp plugged into it - it only supports the onoff
colour state.
Referring back to the same documentation, this means that: “The light can be turned on or off. This mode must be the only supported mode if supported by the light.”
If your lamp’s bulb supports dimming, it might be worth looking into a smart dimmer of some kind that you could wire into it, if you’re comfortable with that.
If your bulb does not support dimming, it might be worth looking into a smart bulb.
I hope this helps!
First and foremost, brilliant piece of work. Fell down the rabbit hole first looking for a way to increase the brightness of an already powered on light. It’s built in… “increase brightness.” Perfect, now I’m looking for the clean transition and came across your work. I apologize if this was already answered. I have under cabinet lighting. I’m looking to increase the brightness by + x% when motion is detected. Let’s say it’s late evening and it’s 5%. When motion is detected it adds the x% say 10% to now it’s at 15%. Nice clean bump in light until motion stops. I created a number helper but it doesn’t like the + or - functions. Did I miss something? Any workarounds?
Again really appreciate the work.
Thanks!
Thanks for awesome script!
Is it possible to add also start fade limit, or achieve it some other way?
I have Ikea light bulbs, and problem is when I want for example in the morning gradually add brightness when switched on, it takes quite a long time when light goes on after switched on when the fade time is for example 5min.
What a magnificent script… Thanks for all your efforts - it seems so easy to use and I’ve been looking for something like this that works for some time now…
One or two questions:
1, Can one run several instances of this script in the same Automation to control different light dimmer units? I have three sets of light dimmers (The small box try dimmers that lave the light external to this device - outside house down lights) that don’t seem to work with ‘Light Transitions’. I did try but in the end I had to use three Automations and I’m still not sure if all three are working in parallel. Can’t see why not though.
2, Can the Script, after a period, start to dime the lights down to a set level and then one can eventually turn the lights off with just the usual Lights off Automation.
Comment: I really like the way you try explain the features - no gobbledegook programmers language…
BTW: I seem to live in a house that’s been built out of a pile of Faraday boxes!!!
Again thanks for putting this together and apogees if the questions are a little stupid…
Thanks for great script
When toggling multiple lights, then say selecting 2 or more lights I get the error 'Error: TypeError: unhashable type: ‘list’.
They are two separate lights in two different room. I have even tried to remove the fade but still get the same result.
I have alternative automation using parallel, and that works fine. Just cant seem to get multiple lights to work in any way
Thanks in anticipation
I love this script although i have one issue. I have a automation that toggles on and off my lights with a click of a button. Ive noticed that this script does not account if you are using a toggle on/off. It accounts only for if you are turning on in a utomation or turning off but not doing both in one. How can i make it a toggle? I want to be able to fade in and fade out when toggling my lights on and off
Thanks for the great script!
I was already desperate and tried to implement a linear decrease/increase in light brightness through cycles.
But I’m probably stupid (although my mom says that’s not true:)), I still haven’t figured out how to make the light increase or decrease.
I turned on the script as indicated - fed it to the lamp, it started increasing the brightness, super!
But what if I want the opposite effect?
I have no doubt that there is a checkbox somewhere, but I’m being stupid, sorry.
Awesome script Ashley! Thanks for that
I configured some actions that trigger many instances of your script in parallel, in order to control different lights simultaneously. Basically what I’m trying to reach is to control all my IKEA Trådfri lights smoothly, I’m doing my best to “not use” the light switches no matter the season or weather condition
It’s working pretty good, except for the color temperature, which is not changing. Do you think it’s because of my light models?
Summary:
- IKEA Trådfri lights + Gateway
- Brightness: 0-100% - works pretty good
- Brightness: 0-255 - lights blink when the script trigger, instead of dimming, so I skipped
- Color temperature - My setup is limited from 2000K to 4000K, but it doesn’t work.
Any ideas why?