You have two options: 1) use command_state + value template from the command_line switch component OR 2) put the ssh command on a script, change your command_line switch to a template_switch and use the ping binary sensor as the value_template.
This script calls the IR blaster to send the on/off IR code. If called with the status options it pings the tv and exits with 0 or 1 if the tv is on or off. You could also just change the command_state to “fping -r 3 tv_ip”
I get the TV status by just pinging it! If it reply then it’s on :-). The funny thing about this LG tv is that i can control it with a command line utility called lgremote, but I cant turn it on with something like wakeup-on-lan so I have to use infrared.
Now I put template together and is working but now I try to add different icon when rpi is in reboot mode and when is offline. But in my template both mode (offline/reboot) have icon alert-outline.