Dynamic template_icon Command line Sensor

Hello,

I have troubles with a dynamic template_icon. It cost my many ours but i can’t get it right.
I have connect my LG hombot to Ha. I would like to have a dynamic icon from the battery value.
This is the state from HA:

I would like to for example: mdi:battery when the battery is 100%.
mdi:battery-10 by 10%, mdi:battery-20 by 20 battery, etc.

I can’t get i right, i have no icon, or the default icon. Can someone help me?
This is the code fo now to try, but this is not working now: What do i wrong?

   - platform: command_line
    command: "curl http://192.168.2.19:6260/status.txt | awk 'NR==2' | awk -F'=' '{print $2}' | awk -F'\"' '{print $2}'"
    name: HomBot_Battery
    unit_of_measurement: "%"
    icon_template: "{% if is_state('sensor.hombot_battery', '100') %}mdi:battery{% else %}mdi:battery-unknown{% endif 
    %}"

Use its state for a new template sensor with the icon_template processing .

To expand on patkap…
The command_line sensor does not implement icon_template.
So to do what you want to do, create a new template sensor like this:

   - platform: template
     value_template: {{state.sensor.hombot_battery.state}}
     name: HomBot_Battery_Display
     unit_of_measurement: "%"
     icon_template: "{% if is_state('sensor.hombot_battery', '100') %}mdi:battery{% else %}mdi:battery-unknown{% endif  %}"
1 Like

aaah that is it, no icon_template on command_line. Strange, no error.
Thanks for the information @patkap @treno , in the evening i will try to fix it. I let you know.