Switch that activates a console command - how do I detect when completed?

I have, in preparation to halloween, created a switch that runs a bash script on my magicmirror.
The script takes some time to complete.
How do I go about checking when it’s done?

The plan is

  1. lights go out
  2. script runs
  3. lights turn on again.

For now I’ve just set in a delay, but it would be better to know when the script completes.
The command line doesn’t return until it’s done.

The switch is defined like this:

  - platform: command_line
    switches:
      ghost_in_mirror:
        command_on: "ssh -i /config/ssh_keys/badspejl.sshkey -o StrictHostKeyChecking=no [email protected] sudo /home/pi/randomfile.sh"

At the end of randomfile.sh add a command that returns an event to homeassistant…

… Then your automation action will read:

Lights off
Activate shell command
Wait for event received from the script
Lights on

2 Likes

Works perfectly! Thankyou.

1 Like

I just need to figure out how to get this done in node-red.
My problem is that I want to return the lights to their previous state, ie. if they were off, they remain off etc.
and if they were on, they should return to the brightness they were at.
I’ve done some subflows to handle this, but they work with the msg, and the event node doesn’t receive a message, it is a start node.

I think I can do it with an event state, so I set it ON when it’s running and OFF when it’s done, and then I just wait for the transition to OFF

I can’t help with node red, but in homeassistant you can use the scene.create service to save the state of the lights, then apply the scene at the end to return them to the saved state.

1 Like

Yup, that was the way. So the switch I’ve created to run the command, get’s a state of “on” when it’s running, and then “off” when it’s done.

@anon43302295, that is what I did in node-red, but with the switch turning on and off, it solved it, I’ll just wait for it to go off…

1 Like