added todos
added an image to the readme
readme: add a word on the i2c setup on the pn board
This repo contains needed code to make a launcher for SomaFM using
You need to connect the PN532 pins to the ESP board:
You can choose other pins than D1 and D2. Just adapt somalauncher.yaml
Make sure you set the PN532 to use I2C bus, using the dip switches on the board.
That's mostly it.
This build assumes home assistant has one switch per SomaFM station. For
instance, in config/switch.yaml
, add:
- platform: command_line
switches:
radiopi_soma_groovesalad:
friendly_name: Radio Groove Salad
command_on: "curl radiopi.local:5000/soma/groovesalad"
command_off: "curl radiopi.local:5000/stop"
This switch launches a curl to a raspberrypi that has a very small Flask server to handle basic rest calls, then run the stations using mpv.
It is avaible in the server
folder.
At that point, you should be able to start and stop the radio using curl
.
First edit esphome/somalauncher.yaml
. In the binary_sensor
section, you need
to edit:
switch_id
: the HA switch ID without the switch.
prefixstation
: The name of the stationuid
: to match the card you want to associate with the station.You probably don't know in advance the UID of the cards, so just flash it with random values for now. You'll be able to tap your cards later on to get their UID.
You also need to create a secret.yaml
file containing your Wifi credentials
(simply copy esphome/secrets.default.yaml
to esphome/secrets.yaml
and edit
it):
wifi_ssid: MySSID
wifi_psk: my super passphrase
In the file radio.yaml
, you can see the things to do to turn on and turn off
the stations. In my code, I start the station, and also select the Music item on
my receiver. You will need to adapt the sequence of actions here to your liking
and your setup.
You need to install the esphome toolchain. There are ways to do this directly from Home Assistant, but it was janky when I tried it, and I prefer to use the cli tools anyways.
Now flash the firmware onto the ESP board. You should use an USB connection as it's been more reliable and faster than wifi in my experience:
$ esphome run somalauncher.yaml
It compiles, flashes and starts the program on the board, then will print the output logs.
You can now tap your cards, check the output logs for the card UID and update the
somalauncher.yaml
file.
Once all cards have been set in the yaml file, compile and uplaod it again:
$ esphome upload somalauncher.yaml
Then go to Home Assistant, Settings, Devices & Services to onboard your ESP8266 that should be availble now.
The enclosure is provided in the freecad
folder, where you have the CAD files
as well as STL files that should be ready for 3D printing.
The enclosure is basic and there is no holder for the esp board. I just plug the USB cord and it maintains it in place. The PN532 board can be fit in the two pins, and maintained in place with o-rings.
I don't like CAD. It took me 3 F'ing days to build that simple box, and I got pissed, so I decided it was good enough. If you're better than me at this game, feel free to improve the design :)
Enjoy!