Hello there,
I want my home assistant to start an automation as soon as the battery limit is reached.
ValueError: Template error: int got invalid input ‘unknown’ when rendering template ‘{{ states(‘sensor.opel_combo_battery’) | int = states(‘sensor.opel_combo_battery_charging_limit’) | int }}’ but no default was specified
My sensor seems to read unknown, although when I check it gives me a value
Your second example with the >= looks ok but this one probably needs two equals to be a comparison operator ( == ) instead of the single one you have. A single = is an assignment operator, not comparison.
Also, I usually do int(0) instead of just int, to provide a 0 as a default value in the case of an error.
It will trigger when the battery charge meets or exceeds the charging limit. Both values are converted to integers. If either value cannot be converted to an integer, a default value of zero is used.
The error message above is the output of the template thing in the developer tools. I guess the missing ‘>’ in ‘>=’ is a result of the markdown, as it does appear as ‘>=’ in the error message on my end. Sorry about that.
The developer tools- states gives me the following output,
so it should be 46 or whatever percentage is there. The sensor also has been available all the time in the timeline.
@blacky your line is identical to mine on my end, and it gives the same error message in developer tools - templates.
@123 I’d love to use the numeric state trigger, but that can only be set to a entity value and above instead of above and equal to as far as I’m aware. So I’d have to make another sensor that always detracts 1 from the battery limit and then set above that as trigger value, that seems really convoluted though.
Thank you all for your suggestions. Maybe I’m still reading the output of the states wrong?
I just found the solution, the hint with the states developer tool helped.
The problem was the charging limit sensor, as that had two states (on, 80). number.opel(…)limit gave me the correct result instead of sensor.opel(…)limit.
Technically, sensor never existed, the entities were always called number.opel_combo_battery_limit and switch.opel_combo_battery_charging_limit
For completeness sake, my new template and the output of the states tool for the battery charging limit sensor:
{{ states(‘sensor.opel_combo_battery’) | int >= states(‘number.opel_combo_battery_charging_limit’) | int }}