From 8bbc04a2bea91863259e49ae059277cd05fe3845 Mon Sep 17 00:00:00 2001 From: ollo Date: Sat, 8 Dec 2018 18:20:14 +0100 Subject: [PATCH] OpenHAB integration described --- board/LEDatmega.pro | 2 +- board/LEDatmega.sch | 56 ++++++++++++++++++++-------------------- openhab2/Readme.md | 13 ++++++++++ openhab2/sideboard.items | 5 ++++ openhab2/sideboard.rules | 37 ++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 openhab2/Readme.md create mode 100644 openhab2/sideboard.items create mode 100644 openhab2/sideboard.rules diff --git a/board/LEDatmega.pro b/board/LEDatmega.pro index bc99d2f..d7a9f2f 100644 --- a/board/LEDatmega.pro +++ b/board/LEDatmega.pro @@ -1,4 +1,4 @@ -update=Sa 08 Dez 2018 02:33:55 CET +update=Date version=1 last_client=kicad [pcbnew] diff --git a/board/LEDatmega.sch b/board/LEDatmega.sch index f3d8374..08f1e9d 100644 --- a/board/LEDatmega.sch +++ b/board/LEDatmega.sch @@ -30,10 +30,10 @@ Wire Wire Line Wire Wire Line 6650 3250 8450 3250 $Comp -L power:GND #PWR07 +L power:GND #PWR? U 1 1 5BB8DC36 P 5650 4350 -F 0 "#PWR07" H 5650 4100 50 0001 C CNN +F 0 "#PWR?" H 5650 4100 50 0001 C CNN F 1 "GND" H 5650 4200 50 0000 C CNN F 2 "" H 5650 4350 50 0001 C CNN F 3 "" H 5650 4350 50 0001 C CNN @@ -41,10 +41,10 @@ F 3 "" H 5650 4350 50 0001 C CNN 1 0 0 -1 $EndComp $Comp -L power:GND #PWR08 +L power:GND #PWR? U 1 1 5BB8DDB6 P 8450 3350 -F 0 "#PWR08" H 8450 3100 50 0001 C CNN +F 0 "#PWR?" H 8450 3100 50 0001 C CNN F 1 "GND" H 8450 3200 50 0000 C CNN F 2 "" H 8450 3350 50 0001 C CNN F 3 "" H 8450 3350 50 0001 C CNN @@ -54,10 +54,10 @@ $EndComp Wire Wire Line 6650 2050 6950 2050 $Comp -L power:+5V #PWR06 +L power:+5V #PWR? U 1 1 5BB8DB94 P 5650 1350 -F 0 "#PWR06" H 5650 1200 50 0001 C CNN +F 0 "#PWR?" H 5650 1200 50 0001 C CNN F 1 "+5V" H 5665 1523 50 0000 C CNN F 2 "" H 5650 1350 50 0001 C CNN F 3 "" H 5650 1350 50 0001 C CNN @@ -80,10 +80,10 @@ F 3 "~" H 4350 1750 50 0001 C CNN 0 -1 -1 0 $EndComp $Comp -L power:+5V #PWR04 +L power:+5V #PWR? U 1 1 5BB8FA10 P 4100 1750 -F 0 "#PWR04" H 4100 1600 50 0001 C CNN +F 0 "#PWR?" H 4100 1600 50 0001 C CNN F 1 "+5V" V 4115 1878 50 0000 L CNN F 2 "" H 4100 1750 50 0001 C CNN F 3 "" H 4100 1750 50 0001 C CNN @@ -102,10 +102,10 @@ Connection ~ 4150 1750 Wire Wire Line 4150 1750 4200 1750 $Comp -L power:GND #PWR05 +L power:GND #PWR? U 1 1 5BB9016E P 4250 2150 -F 0 "#PWR05" H 4250 1900 50 0001 C CNN +F 0 "#PWR?" H 4250 1900 50 0001 C CNN F 1 "GND" H 4250 2000 50 0000 C CNN F 2 "" H 4250 2150 50 0001 C CNN F 3 "" H 4250 2150 50 0001 C CNN @@ -136,10 +136,10 @@ RESET Text GLabel 3550 4900 2 50 Input ~ 0 MOSI $Comp -L power:GND #PWR03 +L power:GND #PWR? U 1 1 5BB90910 P 3800 5000 -F 0 "#PWR03" H 3800 4750 50 0001 C CNN +F 0 "#PWR?" H 3800 4750 50 0001 C CNN F 1 "GND" H 3800 4850 50 0000 C CNN F 2 "" H 3800 5000 50 0001 C CNN F 3 "" H 3800 5000 50 0001 C CNN @@ -168,10 +168,10 @@ Wire Wire Line Wire Wire Line 6950 1950 6950 2050 $Comp -L power:+5V #PWR09 +L power:+5V #PWR? U 1 1 5C083FE3 P 9450 1350 -F 0 "#PWR09" H 9450 1200 50 0001 C CNN +F 0 "#PWR?" H 9450 1200 50 0001 C CNN F 1 "+5V" H 9465 1523 50 0000 C CNN F 2 "" H 9450 1350 50 0001 C CNN F 3 "" H 9450 1350 50 0001 C CNN @@ -192,10 +192,10 @@ F 3 "~" H 8800 1350 50 0001 C CNN 1 0 0 -1 $EndComp $Comp -L power:GND #PWR010 +L power:GND #PWR? U 1 1 5C0846B5 P 9450 1450 -F 0 "#PWR010" H 9450 1200 50 0001 C CNN +F 0 "#PWR?" H 9450 1200 50 0001 C CNN F 1 "GND" H 9450 1300 50 0000 C CNN F 2 "" H 9450 1450 50 0001 C CNN F 3 "" H 9450 1450 50 0001 C CNN @@ -222,10 +222,10 @@ LED (WS2812)\n Text GLabel 2950 3200 0 50 Input ~ 0 LED $Comp -L power:GND #PWR02 +L power:GND #PWR? U 1 1 5C084D38 P 2600 3300 -F 0 "#PWR02" H 2600 3050 50 0001 C CNN +F 0 "#PWR?" H 2600 3050 50 0001 C CNN F 1 "GND" H 2600 3150 50 0000 C CNN F 2 "" H 2600 3300 50 0001 C CNN F 3 "" H 2600 3300 50 0001 C CNN @@ -233,10 +233,10 @@ F 3 "" H 2600 3300 50 0001 C CNN 1 0 0 -1 $EndComp $Comp -L power:+5V #PWR01 +L power:+5V #PWR? U 1 1 5C084D61 P 2600 3100 -F 0 "#PWR01" H 2600 2950 50 0001 C CNN +F 0 "#PWR?" H 2600 2950 50 0001 C CNN F 1 "+5V" V 2615 3228 50 0000 L CNN F 2 "" H 2600 3100 50 0001 C CNN F 3 "" H 2600 3100 50 0001 C CNN @@ -261,10 +261,10 @@ F 3 "~" H 7350 3550 50 0001 C CNN -1 0 0 1 $EndComp $Comp -L power:GND #PWR011 +L power:GND #PWR? U 1 1 5C0AAD46 P 6900 3850 -F 0 "#PWR011" H 6900 3600 50 0001 C CNN +F 0 "#PWR?" H 6900 3600 50 0001 C CNN F 1 "GND" H 6900 3700 50 0000 C CNN F 2 "" H 6900 3850 50 0001 C CNN F 3 "" H 6900 3850 50 0001 C CNN @@ -286,10 +286,10 @@ Connection ~ 6900 3550 Wire Wire Line 6900 3550 7150 3550 $Comp -L power:+5V #PWR012 +L power:+5V #PWR? U 1 1 5C0ABFA6 P 7150 3450 -F 0 "#PWR012" H 7150 3300 50 0001 C CNN +F 0 "#PWR?" H 7150 3300 50 0001 C CNN F 1 "+5V" H 7165 3623 50 0000 C CNN F 2 "" H 7150 3450 50 0001 C CNN F 3 "" H 7150 3450 50 0001 C CNN @@ -299,10 +299,10 @@ $EndComp Text Notes 8750 900 0 50 ~ 0 Power $Comp -L power:+5V #PWR013 +L power:+5V #PWR? U 1 1 5C0AD119 P 10700 1350 -F 0 "#PWR013" H 10700 1200 50 0001 C CNN +F 0 "#PWR?" H 10700 1200 50 0001 C CNN F 1 "+5V" H 10715 1523 50 0000 C CNN F 2 "" H 10700 1350 50 0001 C CNN F 3 "" H 10700 1350 50 0001 C CNN @@ -321,10 +321,10 @@ F 3 "~" H 10050 1350 50 0001 C CNN 1 0 0 -1 $EndComp $Comp -L power:GND #PWR014 +L power:GND #PWR? U 1 1 5C0AD125 P 10700 1450 -F 0 "#PWR014" H 10700 1200 50 0001 C CNN +F 0 "#PWR?" H 10700 1200 50 0001 C CNN F 1 "GND" H 10700 1300 50 0000 C CNN F 2 "" H 10700 1450 50 0001 C CNN F 3 "" H 10700 1450 50 0001 C CNN diff --git a/openhab2/Readme.md b/openhab2/Readme.md new file mode 100644 index 0000000..28bc45e --- /dev/null +++ b/openhab2/Readme.md @@ -0,0 +1,13 @@ +# OpenHAB +Some OpenHAB 2 examples + +## Requirements +* OpenHAB2 +* Serial Binding + +## Configuration + +On a raspberry, give the *openhab* user access to the serial interfaces: +```bash +sudo usermod -a -G dialout openhab +``` diff --git a/openhab2/sideboard.items b/openhab2/sideboard.items new file mode 100644 index 0000000..b2b6500 --- /dev/null +++ b/openhab2/sideboard.items @@ -0,0 +1,5 @@ +// Install the Serial Binding (https://www.openhab.org/addons/bindings/serial1/) + +// Sideboard +Color sideboardLed "Sideboard" (LivingRoom) { serial="/dev/ttyUSB0@9600,ON(ollpem\n),OFF(ollpec\n)" } +String sideboardLedRaw { serial="/dev/ttyUSB0@9600" } diff --git a/openhab2/sideboard.rules b/openhab2/sideboard.rules new file mode 100644 index 0000000..d3671a7 --- /dev/null +++ b/openhab2/sideboard.rules @@ -0,0 +1,37 @@ +// Some necessary color convertion +rule "Set RGB LEDs from Color item using ColorPicker" + when + Item sideboardLed received command + then + if (receivedCommand instanceof HSBType) + { + val red = receivedCommand.red * 2.55 + val green = receivedCommand.green * 2.55 + val blue = receivedCommand.blue * 2.55 + + logInfo("Sideboard", "R" + red + " G" + green + " B" + blue) + val ledRawCmd = String::format("ollpea%X%X%X\n", red.intValue(), green.intValue(), blue.intValue()); + //logInfo("SideboardDebug", ledRawCmd) + sideboardLedRaw.sendCommand(ledRawCmd) + } +end + +// Magic, when using kodi +rule "Kode stop, light on" +when + Item Kodi_Stop changed from OFF to ON +then + sendCommand(sideboardLed, HSBType::BLUE) +end +rule "Kode start, light off" +when + Item Kodi_Stop changed from ON to OFF +then + sendCommand(sideboardLed, OFF) +end +rule "No Kodi online, no LED" +when + Item Kodi_Online changed from ON to OFF +then + sendCommand(sideboardLed, OFF) +end