I have a command line switch which works fine, but I want to use a specific icon.
My attempt to use a icon_template seems to do nothing; help appreciated…
Does your template work within the template editor at the developer tools of HA?
I have no experience with the specific switch config, but perhaps you could monitor the switch.battery_connect states somehow to see what the actual states are in the different situations.
You need a command_state in order to use value_template and icon_template. It will be a command that’s executed based on the polling frequency that queries the power supply.
If you don’t care about that and you just want to assume the command went through, then all you need is
The only way you can have an icon_template is if you have a way to query the state. If there’s a command that returns a string that tells you if the battery is on or off, then you can use that as command_state then build a value_template and icon_template based on the state.
command_on is the command that’s sent to turn on the battery
command_off is the command that’s sent to turn off the battery
If those commands don’t make sense, then use different commands. You’re in control
Thanks everybody.
Here is the solution to my problem
The command on/off sends instructions
The command_state reads the value
The value_template extracts true
The icon_template changes the icon
switch:
- platform: command_line
switches:
# Switch to disconnect battery
# On (0) normal
# Off (1) battery disconnected
battery_connect:
command_on: /bin/bash -c "echo 0 >> /sys/class/power_supply/bq24190-charger/f_batfet_disable"
command_off: /bin/bash -c "echo 1 >> /sys/class/power_supply/bq24190-charger/f_batfet_disable"
command_state: /bin/bash -c "cat /sys/class/power_supply/bq24190-charger/f_batfet_disable"
value_template: '{{ value == "0" }}'
icon_template: >
{% if value == "0" %} mdi:electric-switch-closed
{% else %} mdi:electric-switch
{% endif %}