Skip to content

Instantly share code, notes, and snippets.

View benjaminrau's full-sized avatar

Benjamin Rau benjaminrau

View GitHub Profile
@benjaminrau
benjaminrau / Readme.md
Last active January 21, 2024 00:25
Home Assistant (HASS) with Homekit, Television Volume Control and Fire TV Stick connected to Sony Bravia
View Readme.md

Home Assistant (HASS) with Homekit, Television Volume Control and Fire TV Stick connected to Sony Bravia

Basically it integrates and older Sony Bravia TV with Fire TV Stick on HDMI via Home Assistant in Apple Homekit with Siri Voice Control for Volume, Mute and Turning TV on and off.

Features of my setup

  • Voice control for television on, off, mute, set volume, play, pause
  • Control for television on, off, mute, set volume and input (which app to start) in Home app
  • Turn on TV light scene when TV starts playing
  • iOS Remote Widget inputs are forwarded to media player & Android TV

Used Integrations

@benjaminrau
benjaminrau / InvalidateTokenEventListener.php
Last active May 19, 2021 19:57
Mechanism to invalidate JWT for specific User in Symfony with Lexik JWT Bundle
View InvalidateTokenEventListener.php
<?php
namespace Emma\UserBundle\EventListener;
use Doctrine\ORM\EntityManagerInterface;
use Emma\UserBundle\Entity\User;
use FOS\UserBundle\Event\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\HttpFoundation\JsonResponse;
@benjaminrau
benjaminrau / ItemJsonNormalizer.php
Last active December 13, 2019 20:44
Allow to have different serialization groups for root resource and embedded relations
View ItemJsonNormalizer.php
<?php
namespace Emma\AppBundle\Serializer;
use ApiPlatform\Core\Util\ClassInfoTrait;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
@benjaminrau
benjaminrau / outdatedBrowser.js
Last active February 7, 2019 08:55
Outdated Browser - minified to return just boolean
View outdatedBrowser.js
/**
* Outdated Browser
* Version: 1.1.2 - 2015
* author: Burocratik
* website: http://www.burocratik.com
*/
var isOutdatedBrowser = function(lowerThan) {
//assign css3 property or js property to IE browser version
if (lowerThan == 'IE8' || lowerThan == 'borderSpacing') {
View EntityEventSubscriber.php
<?php
namespace Emma\AppBundle\EventSubscriber;
use ApiPlatform\Core\EventListener\EventPriorities;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Emma\AppBundle\AppBundleEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
@benjaminrau
benjaminrau / AllowedTags.php
Last active July 30, 2018 18:03
XSS Protection - will remove all html tags onFlush (before they are persisted) from fields which are ORM type text or string, with option to define allowed html tags by annotation
View AllowedTags.php
<?php
namespace AppBundle\Annotation\Xss;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* @Annotation
* @Target({"PROPERTY"})
*/
@benjaminrau
benjaminrau / Emma_MediaBundle_EventListener_SerializeListener.php
Last active June 7, 2021 07:53
File Upload (JSON) and store with Sonata Media Bundle (based on ApiPlatform 2.0, Symfony 3.1)
View Emma_MediaBundle_EventListener_SerializeListener.php
<?php
namespace Emma\MediaBundle\EventListener;
use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface;
use Emma\MediaBundle\Entity\MediaElement;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\Serializer\SerializerInterface;
@benjaminrau
benjaminrau / lowBatteryShutdown.py
Created April 6, 2016 15:34
Onion Omega with Adafruit Power Board 500 mA, shutting down the onion when battery is now or power disconnected
View lowBatteryShutdown.py
import sys, os, datetime
from gpiohelper import GPIOHelper
helper = GPIOHelper()
vInPin = 12
lowBatteryPin = 8
pinToCheck = vInPin;
durationOfNotOKInMinutesBeforeShutdown = 1
@benjaminrau
benjaminrau / main.js
Created March 18, 2016 23:22
Read gps device with nodejs under openwrt and cp2102 ttl to usb converter
View main.js
var nmea = require('nmea');
var trycatch = require('trycatch');
function watchGps() {
var spawn = require('child_process').spawn;
var child = spawn("python", [tempDir + "readGpsDevice.py"]);
child.stdout.on('data', function (buffer) {
trycatch(function() {
var gpsOut = nmea.parse(buffer.toString());
@benjaminrau
benjaminrau / Form.html
Last active January 25, 2016 16:25
HTML5 LocalStorage used to fill form
View Form.html
<script>
$(document).ready(function() {
function initFormStorage(registrationFormId) {
console.log('Initializing storage for form#' + registrationFormId);
/*
* when a form field changes store it's value in local storage
*/
$("#" + registrationFormId + " input[type=text], #" + registrationFormId + " select, #" + registrationFormId + " textarea").change(function() {
$this = $(this);
console.log('Update value for ' + $this.attr("name") + 'to ' + $this.val());