diff --git a/esphome/config_validation.py b/esphome/config_validation.py index fa2a14dbd6..1319786841 100644 --- a/esphome/config_validation.py +++ b/esphome/config_validation.py @@ -838,9 +838,16 @@ def percentage(value): def possibly_negative_percentage(value): - has_percent_sign = isinstance(value, str) and value.endswith('%') - if has_percent_sign: - value = float(value[:-1].rstrip()) / 100.0 + has_percent_sign = False + if isinstance(value, str): + try: + if value.endswith('%'): + has_percent_sign = False + value = float(value[:-1].rstrip()) / 100.0 + else: + value = float(value) + except ValueError: + raise Invalid("invalid number") if value > 1: msg = "Percentage must not be higher than 100%." if not has_percent_sign: diff --git a/tests/test3.yaml b/tests/test3.yaml index 53bbdf023c..dded01fb67 100644 --- a/tests/test3.yaml +++ b/tests/test3.yaml @@ -14,6 +14,8 @@ esphome: substitutions: devicename: test3 devicecomment: test3 device + min_sub: "0.03" + max_sub: "12.0%" api: port: 8000 @@ -769,6 +771,8 @@ servo: id: my_servo output: out restore: true + min_level: $min_sub + max_level: $max_sub ttp229_lsf: