I’m trying to calculate remaining kms, based on the received battery level from EVNotify, based on the assumption of 33kWh and an average of 11.9kWh/100km.
Can anyone help me figuring out the correct way to do the formulas? I’m getting “value undefined” errors.
States are strings. You need to convert them to numbers before doing math. Also you are missing the quotes inside states(). Also way too many unneeded parentheses. You probably want an availability template too. And you can have more than one sensor in the platform dictionary:
- platform: template
sensors:
evnotify_remaining_kwh:
friendly_name: "Evnotify Remaining kWh" # you can uses spaces and capital letters here to make this look nice
value_template: "{{ states('sensor.evnotify_SOC_battery_level')|float(0)*100/33 }}"
availability_template: "{{ states('sensor.evnotify_SOC_battery_level')|float('none') != 'none' }}"
icon_template: "{{'mdi:battery-50'}}" # you can change this icon with the state if you like
evnotify_remaining_kms:
friendly_name: "Evnotify Remaining kms" # you can uses spaces and capital letters here to make this look nice
value_template: "{{ states('sensor.evnotify_remaining_kwh')|float(0)*100/11.9 }}"
availability_template: "{{ states('sensor.evnotify_remaining_kwh')|float('none') != 'none' }}"
icon_template: "{{'mdi:counter'}}"