@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