Raspberry Pi ePaper Sonos Controller

This flow turns a Raspberry Pi with a 2.7" Waveshare ePaper HAT into a basic Sonos controller that displays current track info and allows skipping tracks and play/pause.

Requires this font for the button images.

[{"id":"8ed28c0d.5fd","type":"tab","label":"Sonos Controller","disabled":false,"info":""},{"id":"b9f88a4.ad11678","type":"sonos-currenttrack","z":"8ed28c0d.5fd","playnode":"8d9f6ea5.1318d","name":"What's Playing","x":300,"y":40,"wires":[["e7a12920.42ba18"]]},{"id":"b92172d.b6c429","type":"inject","z":"8ed28c0d.5fd","name":"","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":false,"x":110,"y":40,"wires":[["b9f88a4.ad11678"]]},{"id":"a3ded94b.b92b38","type":"debug","z":"8ed28c0d.5fd","name":"","active":false,"console":"false","complete":"false","x":1050,"y":40,"wires":[]},{"id":"f4f14c26.74c23","type":"rbe","z":"8ed28c0d.5fd","name":"","func":"rbe","gap":"","start":"","inout":"out","x":690,"y":40,"wires":[["3afffebd.223de2"]]},{"id":"e7a12920.42ba18","type":"change","z":"8ed28c0d.5fd","name":"Remove Position","rules":[{"t":"delete","p":"payload.position","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":40,"wires":[["f4f14c26.74c23"]]},{"id":"3afffebd.223de2","type":"python3-function","z":"8ed28c0d.5fd","name":"Update ePaper","func":"import os\nos.chdir(\"/home/pi/epaper/python/\")\nimport epd2in7b\nimport Image\nimport ImageFont\nimport ImageDraw\nimport json\n#import imagedata\n\npload = msg['payload']\n#displaytext = json.loads(msg['payload'])\nCOLORED = 1\nUNCOLORED = 0\n\nepd = epd2in7b.EPD()\nepd.init()\nframe_black = [0] * (epd.width * epd.height / 8)\nframe_red = [0] * (epd.width * epd.height / 8)\nepd.draw_filled_rectangle(frame_red, 0, 40, epd.width -1, 0, COLORED);\n##epd.draw_filled_rectangle(frame_black, 10, epd.height - 11, 10, epd.width - 11, COLORED);\nfonta = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 26)\nfontb = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 12)\nfontc = ImageFont.truetype('/home/pi/epaper/python/BTNSWTCH.TTF',34)\nepd.draw_string_at(frame_red, 4, 5, \"SONOS\", fonta, UNCOLORED)\nepd.draw_string_at(frame_red, 4, 50, \"TITLE:\", fontb, COLORED)\nepd.draw_string_at(frame_red, 4, 80, \"ALBULM:\", fontb, COLORED)\nepd.draw_string_at(frame_red, 4, 110, \"ARTIST:\", fontb, COLORED)\n\nepd.draw_string_at(frame_black, 4, 90, pload['album'], fontb, COLORED)\nepd.draw_string_at(frame_black, 4, 60, pload['title'], fontb, COLORED)\nepd.draw_string_at(frame_black, 4, 120, pload['artist'], fontb, COLORED)\n\nepd.draw_string_at(frame_red, 10,epd.height - 35,\"cbaf\",fontc, COLORED)\n\nepd.display_frame(frame_black, frame_red)\n#node.error(\"Error msg\", msg)\nreturn msg","outputs":1,"x":860,"y":40,"wires":[["a3ded94b.b92b38"]]},{"id":"6c0d18d2.4566b8","type":"rpi-gpio in","z":"8ed28c0d.5fd","name":"Key 1","pin":"29","intype":"up","debounce":"25","read":true,"x":110,"y":140,"wires":[["99168e1f.7b61d"]]},{"id":"4f8b604f.f8eae","type":"rpi-gpio in","z":"8ed28c0d.5fd","name":"Key 2","pin":"31","intype":"up","debounce":"25","read":true,"x":110,"y":200,"wires":[["5b948de0.4b5a64"]]},{"id":"58720bc8.3a34c4","type":"rpi-gpio in","z":"8ed28c0d.5fd","name":"Key 3","pin":"33","intype":"up","debounce":"25","read":true,"x":110,"y":260,"wires":[["23891ad2.364936"]]},{"id":"b03254ae.68d598","type":"rpi-gpio in","z":"8ed28c0d.5fd","name":"Key 4","pin":"35","intype":"up","debounce":"25","read":true,"x":110,"y":320,"wires":[["9040b019.87197"]]},{"id":"99168e1f.7b61d","type":"sonos-control","z":"8ed28c0d.5fd","playnode":"8d9f6ea5.1318d","name":"Back","mode":"","track":"previous","volume":"","volume_value":"","x":250,"y":140,"wires":[]},{"id":"5b948de0.4b5a64","type":"sonos-control","z":"8ed28c0d.5fd","playnode":"8d9f6ea5.1318d","name":"Next","mode":"","track":"next","volume":"","volume_value":"","x":250,"y":200,"wires":[]},{"id":"9040b019.87197","type":"sonos-control","z":"8ed28c0d.5fd","playnode":"8d9f6ea5.1318d","name":"Pause","mode":"pause","track":"","volume":"","volume_value":"","x":250,"y":320,"wires":[]},{"id":"23891ad2.364936","type":"sonos-control","z":"8ed28c0d.5fd","playnode":"8d9f6ea5.1318d","name":"Play","mode":"play","track":"","volume":"","volume_value":"","x":250,"y":260,"wires":[]},{"id":"669384dd.a1365c","type":"comment","z":"8ed28c0d.5fd","name":"Basic ePaper Sonos Controller","info":"This is a basic Sonos controller for a single \nspeaker or group which uses a Raspberry Pi and a\n[Waveshare 2.7\" ePaper HAT](http://amzn.eu/1vpdEQn).\n\nCode for the ePaper hat is in /home/pi/epaper/.\n\nYou'll also need [this font](http://all-free-download.com/font/download/buttons_and_switches_font_8465.htm).\n","x":620,"y":140,"wires":[]},{"id":"8d9f6ea5.1318d","type":"sonos-config","z":"","name":"Dining Room","ipaddress":"192.168.0.152","port":""}]
stuartmunn

Flow Info

created 2 weeks, 1 day ago

Node Types

Core
  • change (x1)
  • comment (x1)
  • debug (x1)
  • inject (x1)
  • rpi-gpio in (x4)
Other

Tags

  • Sonos
  • RaspberryPi
  • ePaper
  • Waveshare
  • Controller
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option