NFC Tag Action based on user

NFC Tags are a great way to trigger automation. Let’s say you arrive home, swipe your phone on an NFC Tag and some lights turn on and music starts playing. It’s amazing until your significant other says another playlist will be a better option. Or upon arriving some other scene, with different devices ou different setting should start instead.
Home Assistant allows us to get the id of the user (phone) that scanned the NFC tag so we can use that to trigger different actions.

Let’s say we have 2 NFC tags. One in the garage and another in the shared office. When leaving the house, we enter the garage and both use the same NFC tag to open the garage door. It doesn’t really matter who’s using the tag as we both want the same result out of that particular NFC Tag.

Garage Tag flow
tag_id node

Our garage tag is the one with the id ending in 13d5 so when we receive that id in Home Assistant with a ‘tag_scanned’ event it will leave the ‘tag_id’ node in output 2 which leads to a call service node that tells Home Assistant to open the garage door.

While entering the office, however, we both use the same tag but we can id the user and trigger a different set of actions based on it.

If tag_id ending in 43e0 is scanned, the flow will run through output 1 of the tag_id node into another switch node that will check for the user that made the scan.

Node-RED flow:

[{“id”:”856cce8e.29502″,”type”:”tab”,”label”:”NFC”,”disabled”:false,”info”:””},{“id”:”81417a0f.c1eca8″,”type”:”server-events”,”z”:”856cce8e.29502″,”name”:””,”server”:””,”version”:1,”event_type”:”tag_scanned”,”exposeToHomeAssistant”:false,”haConfig”:[{“property”:”name”,”value”:””},{“property”:”icon”,”value”:””}],”waitForRunning”:true,”outputProperties”:[{“property”:”payload”,”propertyType”:”msg”,”value”:””,”valueType”:”eventData”},{“property”:”topic”,”propertyType”:”msg”,”value”:”$outputData(\”eventData\”).event_type”,”valueType”:”jsonata”},{“property”:”event_type”,”propertyType”:”msg”,”value”:”$outputData(\”eventData\”).event_type”,”valueType”:”jsonata”}],”x”:160,”y”:120,”wires”:[[“5d97e256.fc40cc”]]},{“id”:”5d97e256.fc40cc”,”type”:”switch”,”z”:”856cce8e.29502″,”name”:”tag_id”,”property”:”payload.event.tag_id”,”propertyType”:”msg”,”rules”:[{“t”:”eq”,”v”:”94ab8c0f-0b0c-43e0″,”vt”:”str”},{“t”:”eq”,”v”:”969b-36c9fa2113d5″,”vt”:”str”}],”checkall”:”true”,”repair”:false,”outputs”:2,”x”:330,”y”:120,”wires”:[[“9470bdd7.ef287”],[“296f7190.a033de”]]},{“id”:”9470bdd7.ef287″,”type”:”switch”,”z”:”856cce8e.29502″,”name”:”user”,”property”:”payload.context.user_id”,”propertyType”:”msg”,”rules”:[{“t”:”eq”,”v”:”ae0fsdsaf26aca4d”,”vt”:”str”},{“t”:”eq”,”v”:”fasdfdsfafadsadsfa”,”vt”:”str”}],”checkall”:”true”,”repair”:false,”outputs”:2,”x”:470,”y”:120,”wires”:[[“b9521be1.7e6088”],[“805ae37.651822”]]},{“id”:”b9521be1.7e6088″,”type”:”api-call-service”,”z”:”856cce8e.29502″,”name”:”Turn On John’s Light”,”server”:””,”version”:3,”debugenabled”:false,”service_domain”:””,”service”:””,”entityId”:””,”data”:””,”dataType”:”jsonata”,”mergecontext”:””,”mustacheAltTags”:false,”outputProperties”:[],”queue”:”none”,”x”:680,”y”:100,”wires”:[[“4d768992.771978”]]},{“id”:”805ae37.651822″,”type”:”api-call-service”,”z”:”856cce8e.29502″,”name”:”Turn On Jane’s Light”,”server”:””,”version”:3,”debugenabled”:false,”service_domain”:””,”service”:””,”entityId”:””,”data”:””,”dataType”:”jsonata”,”mergecontext”:””,”mustacheAltTags”:false,”outputProperties”:[],”queue”:”none”,”x”:680,”y”:140,”wires”:[[“afb82923.e98ef8”]]},{“id”:”afb82923.e98ef8″,”type”:”api-call-service”,”z”:”856cce8e.29502″,”name”:”Play TV”,”server”:””,”version”:3,”debugenabled”:false,”service_domain”:””,”service”:””,”entityId”:””,”data”:””,”dataType”:”jsonata”,”mergecontext”:””,”mustacheAltTags”:false,”outputProperties”:[],”queue”:”none”,”x”:860,”y”:140,”wires”:[[]]},{“id”:”4d768992.771978″,”type”:”api-call-service”,”z”:”856cce8e.29502″,”name”:”Play Spotify”,”server”:””,”version”:3,”debugenabled”:false,”service_domain”:””,”service”:””,”entityId”:””,”data”:””,”dataType”:”jsonata”,”mergecontext”:””,”mustacheAltTags”:false,”outputProperties”:[],”queue”:”none”,”x”:870,”y”:100,”wires”:[[]]},{“id”:”296f7190.a033de”,”type”:”api-call-service”,”z”:”856cce8e.29502″,”name”:”Open Garage Door”,”server”:””,”version”:3,”debugenabled”:false,”service_domain”:””,”service”:””,”entityId”:””,”data”:””,”dataType”:”jsonata”,”mergecontext”:””,”mustacheAltTags”:false,”outputProperties”:[],”queue”:”none”,”x”:670,”y”:200,”wires”:[[]]}]

Node-RED controlled Hyperion

Due to the high CPU usage of Hyperion when processing the usb capture unit, I only use it for sources that don’t allow for screen capture within the android box using the Android Grabber app. As I needed a way to change it automatically, I created a flow in Node-RED that checks which app is playing and selects the correct source for Hyperion. It also stops and starts Hyperion based on playing/idle status of the media.

Hyperion Flow

The above picture shows the entire flow, which I’m now going to explain in detail.

The first node is a HomeAssistant ‘state node’, which allows me to get the status of my Nvidia Shield. That info goes to a ‘switch node’ that creates a different output for each status.

If the status is other than ‘playing’, Hyperion turns off after 30 seconds (defined in the green timer). If it’s playing, and depending on the time condition, it starts the WLED and Hyperion.

At this stage, it will check the source app and if it’s Plex or Youtube it deactivates the usb capture and will use the info from the Android Grabber app. If it’s using an app like Netflix it will turn the USB capture on.

Here’s the complete flow:

[{"id":"1a80ca9e.94dd45","type":"tab","label":"hyperion","disabled":false,"info":""},{"id":"48849958.8ab3a8","type":"server-state-changed","z":"1a80ca9e.94dd45","name":"Shield Sala Status","server":"","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"media_player.living_room_nvidia_shield","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":160,"wires":[["34cb201b.bfdfa"]]},{"id":"9f0a9c7b.2c255","type":"api-call-service","z":"1a80ca9e.94dd45","name":"wld-pwr-off","server":"","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.smart_plug_mss310_main_channel_2","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":120,"wires":[["23916314.5bb69c"]]},{"id":"a028c2a3.98cbd","type":"api-call-service","z":"1a80ca9e.94dd45","name":"wld-pwr-on","server":"","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.smart_plug_mss310_main_channel_2","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":570,"y":200,"wires":[["7ee75f85.cda98"]]},{"id":"cff7cba0.808048","type":"api-call-service","z":"1a80ca9e.94dd45","name":"hyperion-on","server":"","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"light.wled_tv","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":200,"wires":[["27fc772c.b1d998"]]},{"id":"7ee75f85.cda98","type":"delay","z":"1a80ca9e.94dd45","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":740,"y":200,"wires":[["cff7cba0.808048"]]},{"id":"34cb201b.bfdfa","type":"switch","z":"1a80ca9e.94dd45","name":"status","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"paused","vt":"str"},{"t":"eq","v":"idle","vt":"str"},{"t":"eq","v":"off","vt":"str"},{"t":"eq","v":"running","vt":"str"},{"t":"eq","v":"playing","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":350,"y":140,"wires":[["65ea9253.3b7f3c"],["65ea9253.3b7f3c"],["9f0a9c7b.2c255"],["9f0a9c7b.2c255"],["d015ba3.16baf48","173a3680.8d2c5a"]]},{"id":"65ea9253.3b7f3c","type":"stoptimer","z":"1a80ca9e.94dd45","duration":"30","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":590,"y":120,"wires":[["9f0a9c7b.2c255"],[]]},{"id":"d015ba3.16baf48","type":"change","z":"1a80ca9e.94dd45","name":"Stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":160,"wires":[["65ea9253.3b7f3c"]]},{"id":"27fc772c.b1d998","type":"switch","z":"1a80ca9e.94dd45","name":"Source","property":"data.old_state.attributes.app_name","propertyType":"msg","rules":[{"t":"eq","v":"YouTube","vt":"str"},{"t":"eq","v":"Plex","vt":"str"},{"t":"eq","v":"Netflix","vt":"str"},{"t":"eq","v":"Disney+","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":360,"y":300,"wires":[["23916314.5bb69c"],["23916314.5bb69c"],["26b1b683.7fe9da"],["26b1b683.7fe9da"]]},{"id":"26b1b683.7fe9da","type":"api-call-service","z":"1a80ca9e.94dd45","name":"hyperion VL4","server":"","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.wled_tv","data":"{\"effect\":\"V4L\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":580,"y":300,"wires":[[]]},{"id":"23916314.5bb69c","type":"api-call-service","z":"1a80ca9e.94dd45","name":"hyperion APP","server":"","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.wled_tv","data":"{\"effect\":\"GRABBER\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":580,"y":260,"wires":[[]]},{"id":"173a3680.8d2c5a","type":"time-range-switch","z":"1a80ca9e.94dd45","name":"","lat":"","lon":"","startTime":"12:00","endTime":"08:00","startOffset":0,"endOffset":0,"x":380,"y":220,"wires":[["a028c2a3.98cbd"],[]]}]

PlexServer, Promox, Intel 640

Intel® Iris® Plus Graphics 640 GPU passthrough with proxmox and Debian 11 virtual machine

It’s more of a Sybill Trelawney’s art than it is a science. These work on my setup:

################################################instalar drivers

apt-get install i965-va-driver
apt-get install vainfo

################################################testar os mesmos

ls -l /dev/dri

total 0
drwxr-xr-x 2 root root 80 Jan 8 12:20 by-path
crw-rw—- 1 root video 226, 0 Jan 8 12:20 card0
crw-rw—- 1 root render 226, 128 Jan 8 12:20 renderD128

################################################tornar o HW disponivel para ser passado

nano /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT=”quiet intel_iommu=on iommu=pt video=efifb:off”
ctrl+x
update-grub
reboot
nano /etc/modprobe.d/blacklist.conf
blacklist radeon
blacklist nouveau
blacklist nvidia
blacklist snd_hda_intel
blacklist snd_hda_codec_hdmi
blacklist i915
ctrl+x
lspci -v
root@proxmox:~# lspci
00:02.0 VGA compatible controller: Intel Corporation Device 4c8a (rev 04)
lspci -n -s 00:02 <-Depende do endereço do comando anterior (lspci) 00:02.0 0300: 8086:4c8a (rev 04) nano /etc/modprobe.d/vfio.conf options vfio-pci ids=8086:4c8a -> vem do comando de cima root@proxmox:~# lspci -n -s 00:02 ——>00:02.0 0300: 8086:4c8a (rev 04)
ctrl+x
echo “options vfio_iommu_type1 allow_unsafe_interrupts=1” > /etc/modprobe.d/iommu_unsafe_interrupts.conf
echo “options kvm ignore_msrs=1” > /etc/modprobe.d/kvm.conf
update-initramfs -u
pvecm updatecerts –force
reboot

add to /etc/modules

vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd

################################################tornar o HW disponivel para a VM

nano /etc/pve/qemu-server/300.conf <—-O teu id de vm

if your processor > broadewell then, (upt mode)

agent: 1
args: -device vfio-pci,host=00:02.0,addr=0x18,x-vga=on,x-igd-opregion=on

arrancar com a vm instalar novamente os drives, dentro da vm
apt-get install i965-va-driver