Hi, I am working on a raspberry pi that will only interract as the front end to home assistant (the HA server is on a different computer). I am printing a whole case for the screen, keyboard, and pi. It is a WIP, but this is what I have so far:
You can see some key with 1,2,3,4,5 on the left side of the monitor. Those are just cherry mx keys. I want to do something special with them, but I am not sure how.
I can easily wire them into the pi, and then when they are pressed, call a bash script. The bash script can do a lot of things, like call an API in HA backend to turn on a specific light, of set a specific scene.
I could wire them into the pi and do something on the system level like adjust volume or blank the screen, or poweroff
I am using i3wm, so I could also control the windows. Things like showing a particular application would be possible.
I could instead wire them to an arduino pro micro and use it as an HID device that would act like a regular keyboard to push keystrokes (ctrl+alt+1, etc.) on the pi an do all of the above.
I could attach them to an esp and use esphome to connect the buttons to automations in home asistant.
I am currently launching the front end using chromium in kiosk mode. I will do that at startup and I hope to not have to close or open it. What I would like to be able to do is have a few or maybe all 5 of these buttons go to specific pages in the front end. Is that possible? If I set up a view with nothing but camera images, can I press ‘3’ and have it quickly change to that view in lovelace? What about opening the model/dialog for a specific entity?
I would also like to be able to do that with less frequent tasks on the tiny keyboard (which is a void30). A specific key combo might send Ctrl+Alt+s to the Pi. Is there a way to make the front end handle those keys and do specific tasks or change to a specific entity or view?
I think the right answer to this is to use something like this:
The python module home-assistant-api to take button presses, and send some events in Home assistant.
Install browser-mod to give me the hooks needed to control a browser.
Make automations to do things like navigate to a different page in the browser running on this machine, or turn on a litght, or arm the alarm or whatever.
If someone sees a problem with this, let me know, otherwise, I will post the project with all the details when I get it working. I should have some cables coming in on Monday to make it a lot cleaner and some time on Wednesday to wrap it up.
from gpiozero import Button
from signal import pause
from os import system
from os import environ
environ['HASS_SERVER']="http://homeassistant:8123"
environ['HASS_TOKEN']="redacted"
pins = [19, 26, 21, 20, 16]
buttons = [Button(pin, bounce_time=0.05) for pin in pins]
def button_callback(button):
if button.pin.number not in pins:
# How did we get here?
return
swich_number = pins.index(button.pin.number)
print("Pressed Button {}".format(swich_number))
system("hass-cli service call automation.trigger --arguments entity_id=automation.deskpi_button_{}".format(swich_number))
for button in buttons:
button.when_pressed = button_callback
pause()
It runs in user space (not as root, or sudo) and I have it starting at boot. In HA, I have automations called deskpi_button_0, etc. and I can do what I want with them. Thanks for reading. I hope this helps someone.
That looks like it grabs the keyboard events from a keyboard attached to the machine running HA. In this case, I have an odroid running HA somewhere else in the house. This pi is just a fancy way to view and interact with the front end. It doesn’t run HA on this pi.