Ssh and Raspberry Pi

I’ve searched the forum and still not quite finding what I want so I’ll put the question to the experts :slight_smile:

I’m running this -> Ambient TV lights
It works rather well by the way :slight_smile: The problem I have is this:

I run them through home assistant to turn on the TV and lights [ambient light system] but I do not want to just push the button and cold turn it off as it runs off a raspberry pi and I don’t want to just turn it off I’d like to have the pi shut down first then turn off the lights.

The question I have is how can I send the ssh command to an ip address login with user ‘pi’ and password 'raspberry ’ then send this command ‘sudo shutdown -h now’?

Any help would be really appreciated, Thank you all!!

if you activate telnet on your raspberry pi you can use this:

and use this instead in the python script

import telnetlib
import time
HOST = ""
telnet = telnetlib.Telnet(HOST)
telnet.write(b"sudo shutdown -h now\n")

im using Home Assistant Supervised, so im not sure if/how its working on other installations but its worth a try, good luck

1 Like

Telnet :astonished:

To answer the OP, try:
ssh pi@ip_address sudo shutdown -h now

Then give the password and the R Pi will shut down.

1 Like

can you automate that so you can run it directly from ha without having to type the password manually?
if so I’m interested too

Have you tried this?

Yes, Google "passwordless ssh", then pick your preferred web site to explain
how it is done.

Essentially, you will need to log into your HA box, generate a pair of keys
(ssh-keygen) and copy the HA public (.pub) key to your destination box. Neither
box (HA nor destination) will need a reboot.

No passwords are involved.

It is actually fairly simple, despite carrying an aura of geeky trickiness.