-
Notifications
You must be signed in to change notification settings - Fork 61
Add StateVal conversion helpers and availability checks #769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add StateVal conversion helpers and availability checks #769
Conversation
|
This is awesome! Thanks for the PR. |
|
Found a regression affecting state_active and as_*; working on a fix. |
|
Very nice! |
|
@dmamelin will this work on @state_trigger( # boiler boost mode if the water is too cold
f"{BOTTOM_TEMP}.as_float(default={MINIMUM_TEMP}) < {MINIMUM_TEMP} and {BOTTOM_TEMP}.old.as_float(default={MINIMUM_TEMP}) >= {MINIMUM_TEMP} and {BOTTOM_TEMP}.as_float(default={MINIMUM_TEMP}) > 0",
watch=[BOTTOM_TEMP],
state_hold_false=60,
)Thank you! |
|
@ALERTua Yes, of course. BOTTOM_TEMP = "sensor.heatingpump_watboxtemset"
MINIMUM_TEMP = 42
@state_trigger(f""
f"{BOTTOM_TEMP}.as_float(default={MINIMUM_TEMP}) < {MINIMUM_TEMP} and "
f"{BOTTOM_TEMP}.old.as_float(default={MINIMUM_TEMP}) >= {MINIMUM_TEMP} and "
f"{BOTTOM_TEMP}.as_float(default={MINIMUM_TEMP}) > 0")
def test(**kwargs):
log.info(f"{kwargs}")
|
|
alas, if the 2025-12-13 10:01:16.016 ERROR (MainThread) [custom_components.pyscript.file.autovents.func_laundry_auto_fan_on] Exception in <file.autovents.func_laundry_auto_fan_on @state_trigger()> line 1:
any([sensor.laundry_temperature_latest.as_float(default=0) >= 30, sensor.laundry_humidity_latest.as_float(default=0) >= 48, sensor.alert_server_cpu_temperature.as_float(default=0) >= 80, sensor.mini_cpu_temperature.as_float(default=0) >= 80])
^
AttributeError: 'NoneType' object has no attribute 'as_float'
def float_(obj, default=None):
try:
return float(obj)
except:
if default is not None:
return default
return -666.0 |
|
@ALERTua Yes, this is an architectural issue. I have a few ideas, but I’m currently busy with another large PR. |
StateVal Helpers
input_number.brightness.as_int(default=0)orsensor.timestamp.as_datetime()just work - no more manualint(...)/float(...)juggling or wrapping those casts in try/except.unavailable/unknown.Example (for illustration only):