nhl-led-scoreboard
nhl-led-scoreboard copied to clipboard
Implemented initial MQTT functionality
Hey there, as discussed previously, I ditched the webhook in favor of MQTT, so it should be far easier for you to add further MQTT integrations as you see fit. Some notes:
- I'm assuming the user may not have an "mqtt" section in their configuration at all, and about half of my logic involves validation in the event they misconfigured, although I did add a full example in the config.json.sample. The goal (no pun intended) is that if they miss something or if their MQTT server can't connect, it will not error out the app.
- I added two events: if a preferred team scores, and if a non-preferred team scores. For me personally, if my team scores my Sonos speakers will play the song they play in the arena, and if the other team scores I play the trombone losing noise from The Price is Right. You can add additional events as you see fit (start of game, end of period, end of game, etc)
- When a message goes through a MQTT topic, it sends the scoreboard information as a payload. Although I personally don't use it, others might. I set up the structure as
{ "scoreboard": { ... } }so you can add additional information without it being a breaking change to anybody who relies on the structure. - I opted to connect to the MQTT server on each event rather than build a stateful connection in a persistent class like Scoreboard. There's a slight performance hit, but given that the nature of the board can't really update more than 30 seconds at a time anyway, it isn't the bottleneck and we gain the simplicity that comes with a stateless system. If you change it to something stateful, it would be invisible to the user and not a breaking change.
Let me know if you have any questions on this one. Thank you!
Would this work with Alex speaker or the Google Home Speaker?
I wouldn't mind giving this a go.
Would this work with Alex speaker or the Google Home Speaker?
I wouldn't mind giving this a go.
I've never tried it, but it looks possible! This is something I found. Subscribe to a broker/topic that the scoreboard publishes to, and have it chirp when your team scores (or perhaps use profanity if the other team does!) https://github.com/oblogic7/alexa-tts-mqtt
Thanks !!! I will check it out sometime this week. I know some will be happy to have that option.
I decided to go with the other MQTT pull request instead.