Best way to remotely trigger HASS using RPi Buttons?

I am planning to use a Raspberry Pi Zero with a Papirus eInk display to act as a mini remote dashboard for Home Assistant. The eInk board has 4 custom buttons which I hope to use as triggers to perform various actions within HASS (as seen here https://www.modmypi.com/raspberry-pi/raspberry-pi-zero-board/rpi-zero-breakout-boards/papirus-zero-epaper--eink-screen-phat-for-pi-zero-medium).

The Papirus GitHub page https://github.com/PiSupply/PaPiRus/blob/master/bin/papirus-buttons uses Python to detect when the buttons have been pressed, and I’m wondering what method I could use to send commands to HASS within that python script.

One option is the RESTful API, but it looks like Python Remote API would be a better choice? https://home-assistant.io/developers/python_api/

Unfortunately I’m not that familiar with Python. How do I use the package homeassistant.remote on another Raspberry Pi that doesn’t have HASS installed? Looking at the home-assistant/homeassistant/remote.py code, it looks like a number of other HASS modules are used, so I guess I would need to git clone everything onto the eInk Pi?

If I did that, would I need to copy PaPiRus/bin/papirus-buttons.py into the home assistant folder to be able to refer to the necessary modules?

Hope that makes sense (I’m struggling to get my head around this so apologies if not).

My aim is to toggle switches and turn on/off lights from those buttons via HASS.

Thanks.

Write a script that monitors the papirus button pushes and fires a message over the network to HA using MQTT. I just started with this tonight, and this is the place to start https://home-assistant.io/blog/2015/09/11/different-ways-to-use-mqtt-with-home-assistant/

Never thought of being able to use MQTT, i’ll have a look into that so thanks for the suggestion!

1 Like

Thank you @robmarkcole, I can now trigger HA events using MQTT and Python! I’ve included my testing code below in case it helps others (seeing as this includes authentication details which the link Rob sent doesn’t have)

My MQTT broker from HASS yaml looks like this:

mqtt:
 broker: 192.168.0.1
 port: 1883
 client_id: home-assistant-1
 username: !secret mqtt_user
 password: !secret mqtt_pass 

sensor:
  - platform: mqtt
    name: "My Mood"
    state_topic: "home-assistant/my/mood"

On my RPi with Papirus I can run the publish command with success:
sudo mosquitto_pub -h 192.168.0.1 -u mqttuser -P my_pass -t "home-assistant/my/mood" -m "good"

I can also trigger the sensor via Python. The publish.single command works by itself, but if I comment that out and uncomment the client lines, that also works.

#!/usr/bin/python3
#
import time
import random
import paho.mqtt.client as mqtt
import paho.mqtt.publish as publish
broker = '192.168.0.1'
state_topic = 'home-assistant/my/mood'
# Send a single message to set the mood
auth = {
  'username':"mqttuser",
  'password':"my_pass"
}
publish.single('home-assistant/my/mood', 'good', hostname=broker, auth=auth)
#client = mqtt.Client("ha-client")
#client.username_pw_set("mqttuser", "my_pass")
#client.connect(broker)
#client.publish(state_topic, 'yay')
1 Like