MagicMirror trigger with PIR Sensor from HA

For those of you have taken on the DIY project MagicMirror and have tried to use a PIR sensor with a raspberry pi you might notice that when WiFi is active your sensor is constantly in a high state due to RF interference. A solution to fix is to either shield the PIR sensor with anti static bag or move the sensor about 10-15 or so feet away.

Neither of these where a suitable option for me plus i already have a PIR sensor working by MQTT and HA anyways. To combine the two, I simply just used shell_command and installed the following

sudo apt-get install sshpass

This will allow you to login To SSH Server and Provide SSH Password Using A Shell Script… Next you need to creating a shell_command in your config like so:

sshpass -p ssh pi@ bash -s < /home/homeassistant/.homeassistant/


sshpass -p ssh pi@ bash -s < /home/homeassistant/.homeassistant/

You can find the monitor_on and monitor_off script from here:

Tip:Before any of this will work you need to run the command once manually to accept the SSH Key. To do this you need to be in the HA virtualenv as HA user when venv is activated, Other wise none of this will work.

Or use a PIR sensor that doesn’t go high when there is interference: ebay.

same comment, this is (almost) what I did, but still using the same type of PIR.

do you have a sketch on the pinout to the raspberry?

The PIR is actually connected to a different Pi, that talks to my Home Assistant instance on a separate server. I have a Pi Zero connected to a TV running magic mirror that’s always on, but the TV is connected to a LightWaveRF remote controlled socket. When PIR is ON on the Pi, it sends the status to HA via API, HA turns the socket on via rfxtrx.
the PIR is powered via +5V and GND on the Pi, data pin connected to any GPIO…

@Andrew_Lozoya thanks for this but sshpass doesn’t work for me at all. I haven’t configured it with my HA as I am just trying it out i.e. trying to send some command from my NUC to my raspberry pi but nothing happens. i.e. I dont see anything.

I tried the following:

sshpass -p 'mypassword' ssh [email protected] 'df -h'

I expect df -h to show of my raspberry pi on my NUC where I am running the sshpass command from but nothing happens.

Can you please help?


Using sshpass with the password in clear is a disaster waiting to happen and should be totally avoided!!!

With that warning :grin:, save the script to be run that includes the df command on the target machine (for example in /home):

#! /bin/bash 

sshpass -p "mypassword" ssh -tt [email protected] 'echo "mypassword" | sudo -S -s /bin/bash -c "sh /home/"'

Have the user on the NUC connect at least once to the Rpi in order to add/update the keys.

For the record: there are monitoring platforms (snmp, glances) that are much easier to use and more secure.

@Petrica I have made it to work without the password by generating ssh keys etc and it works when I just run this command in the command line:

ssh [email protected] vcgencmd display_power 0

However when I use it with the command line switch on HA. It doesnt work and throws an error saying:
ERROR (SyncWorker_7) [homeassistant.components.switch.command_line] Command failed: ssh [email protected] vcgencmd display_power 0

Any help please?


Try saving the command as a script on the Rpi and call the script from NUC. I recall having problems reliably turning HDMI signal off and back on with the Rpi and a computer monitor.

After thinking things over I switched to a 28" TV (controlled by IR remote) as it opens additional options (by the use of multiple HDMI ports and speakers).

I have two NodeMCU with OpenMQTT (I think I could’ve gone with only one but at that time there were some issues with the sketch I was using) that take care of most of the “smart” parts:

  • IR blaster, to send commands (discrete on/off, volume adjustment, brightness, source selection) to the TV;
  • PIR sensor;
  • LDR connected to the ADC pin;
  • DHT22, to know everything is under control;
  • Relay, for controlling a 12V led strip.
1 Like