Push button with status?

Hi

I created comand line configuration to restart my raspberry pi:

reboot.yaml

  • platform: command_line
    switches:
    cl_reboot_rpi3_room_parents:
    command_on: ‘ssh -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa [email protected] sudo reboot’
    command_off: “ssh -i /config/.ssh/id_rsa [email protected] sudo reboot”

and ping binary sensor to check fi pi is connected:

ping_pi.yaml

  • platform: ping
    host: 192.168.0.51
    name: rpi3

And both is working good.

Now I wanna to combine this to push button.

When button is pressed rpi reboot and when ha lost connectivity with rpi the button turn red and when is back online button is turn back to green.

Can this be done with HA? How?

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.

Thanks for that. Can you show my on some example?

Thx in advance

You can find them on the components doc pages, but I can also show how I use it. Here’s what i have to control my TV:

- platform: command_line
    switches:
       tv:
          command_on: "/home/usuario/scripts/tv.sh on"
          command_off: "/home/usuario/scripts/tv.sh off"
          command_state: "/home/usuario/scripts/tv.sh status" 

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”

If you opt for the template switch, then:

tv:
  value_template: "{{ is_state('binary_sensor.tv', 'on') }}"
  turn_on:
    service: shell_command.tv_power
  turn_off:
    service: shell_command.tv_power

The binary_sensor.tv is just like your rpi3. Shell_command file has:

tv_power: "/home/usuario/scripts/tv.sh on"

Thanks for that. This helped me a lot.

Can you also share tv.sh script or explain how you get status of your ir tv?

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.

I also have lg tv? Where can I find lgremote utility?

Thanks. I will try that.:sunglasses:

template_switch_rpi3_room_parents.yaml (796 Bytes)

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.

How can I compare two states at onec, I try like this but not working:
template_switch_rpi3_room_parents.yaml (916 Bytes)

I made a mistake I start template with elif :grinning: