You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I have a script to fade_in led light and the pyscript works well, but I'd like to get the value of minutes from an in put number. I tried this {{ states('input_number.durata_fadein') | int(0) }} in template and the result is correct, a number, but in home assistant log I obtain this error: Exception in <file.fade_light.fade_light> line 9: transition_secs = minutes * 60 ^ TypeError: unsupported operand type(s) for *: 'dict' and 'int'.
This is the pyscript that I use:
def hasnt_met_target():
current = get_brightness()
should = False
if light_diff > 0: # it's going up
should = current < ending_brightness
else: # it's going down
should = current > ending_brightness
log.debug(f"current={current} ending_brightness={ending_brightness} light_diff={light_diff} should={should}")
return should
log.debug(f"running: entity_id={entity_id} light_diff={light_diff} ending_brightness={ending_brightness} delay_per_tick={delay_per_tick}")
expected_brightness = starting_brightness
while hasnt_met_target():
current_brightness = get_brightness()
log.debug(f"current_brightness={current_brightness} expected_brightness={expected_brightness}")
if abs(current_brightness - expected_brightness) > 4:
log.debug(f"Expected brightness didn't match current brightness ex:{expected_brightness} cu:{current_brightness}")
break
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I have a script to fade_in led light and the pyscript works well, but I'd like to get the value of minutes from an in put number. I tried this {{ states('input_number.durata_fadein') | int(0) }} in template and the result is correct, a number, but in home assistant log I obtain this error: Exception in <file.fade_light.fade_light> line 9: transition_secs = minutes * 60 ^ TypeError: unsupported operand type(s) for *: 'dict' and 'int'.
This is the pyscript that I use:
`@service
def fade_light(entity_id=None, ending_brightness=None, minutes=1, notify_after=None):
light_state = state.get(entity_id)
if state.getattr(entity_id) is None:
log.error(f"No entity found for {entity_id}")
return
transition_secs = minutes * 60
def get_brightness():
nonlocal entity_id
attrs = state.getattr(entity_id)
return attrs.get("brightness", 0)
if ending_brightness is None:
log.error(f"No ending_brightness found for {ending_brightness}")
return
task.unique(f"fade_light|{entity_id}")
starting_brightness = get_brightness()
light_diff = ending_brightness - starting_brightness
if light_diff == 0:
log.info(f"light is faded to same brightness it started with")
return
target_tick_count = light_diff / 2
delay_per_tick = max((abs(transition_secs / target_tick_count), 1))
tick_count = transition_secs / delay_per_tick
change_per_tick = light_diff / tick_count
ending_brightness = ending_brightness
def hasnt_met_target():
current = get_brightness()
log.debug(f"running: entity_id={entity_id} light_diff={light_diff} ending_brightness={ending_brightness} delay_per_tick={delay_per_tick}")
expected_brightness = starting_brightness
while hasnt_met_target():
current_brightness = get_brightness()
log.debug(f"current_brightness={current_brightness} expected_brightness={expected_brightness}")
if abs(current_brightness - expected_brightness) > 4:
log.debug(f"Expected brightness didn't match current brightness ex:{expected_brightness} cu:{current_brightness}")
break
if notify_after is not None:
brightness = get_brightness()
pct = int(brightness*100/255)
attrs2 = state.getattr(entity_id)
name = attrs2.get('friendly_name', entity_id)
message = f"{pct}% {name} Fade Complete"
service.call("notify", f"mobile_app_{notify_after}", message=message)`
Can anybody help me?
thanks
Beta Was this translation helpful? Give feedback.
All reactions