Hi all,
this thread here reminded me posting my trash calendar solution for openHAB.
Back in the OH1.x days I wrote a simple shell script the get trash dates into openHAB from plain text files.
The original version is published at the German forum.
I just updated it to OH2 and the Exec2-Binding what makes it a little bit easier in my opinion.
1. Text files
Just put all your dates of one kind of trash into a text file, e.g. trash_yellow.txt
(yellow means the German “Gelber Sack” recycling system). You can use multiple files for different kinds of trash.
2018-01-11
2018-01-25
2018-02-08
2018-02-22
2018-03-08
2018-03-22
2. Shell script
Place following script and the created plain text files in your conf
folder. I created a subfolder called shellscripts
for this and use a manual OH installation. If you use apt installation you have to adjust the path for trash_file
in the script.
trash.sh
#!/bin/bash
#Current date
datum=$(date +%s)
#1st argument defines kind of trash
trash_kind=$1
#use respective trash text file
trash_file="/opt/openhab/openhab2/conf/shellscripts/trash_$trash_kind.txt"
#loop searching the text file to find the first date > today
#time read from text file is always 00:00:00h -> #86399sec = 23:59:59h to include current day
while read datum_line
do
datum_line_sec=$(date -d $datum_line +%s)
let datum_diff=$datum-$datum_line_sec
if [ $datum_diff -lt 86399 ]
then
echo $datum_line
exit 0
fi
done < $trash_file
echo "Error"
exit 1;
3. openHAB
As mentioned I use the Exec2 binding to get the data into openHAB. Again check if the path to the script matches your installation or adjust it.
*.things
Thing exec:command:trash "Muellabfuhr" [ command="/opt/openhab/openhab2/conf/shellscripts/trash.sh %2$s", interval=0, autorun=true ]
*.items
// items for exec-binding
String iTrashRaw "Script Ergebnis [%s]" { channel="exec:command:trash:output" }
String iTrashRaw_Trigger "Trigger für Mülltermin [%s]" { channel="exec:command:trash:input" }
Number iTrashRaw_Result "Script Rückgabewert [%d]" { channel="exec:command:trash:exit" }
// items for rule
DateTime iTrashBrown "Restmüll [%1$td.%1$tm.%1$tY]"
DateTime iTrashYellow "Gelbe Tüte [%1$td.%1$tm.%1$tY]"
Switch vTrashRead "Mülltermine aktualisieren"
*.rules
rule "Mülltermine"
when
Item vTrashRead changed to ON
then
iTrashRaw_Trigger.sendCommand("brown")
Thread::sleep(5000)
if (iTrashRaw_Result.state == 0) {
iTrashBrown.sendCommand(new DateTimeType(iTrashRaw.state.toString+"T00:00:00"))
}
Thread::sleep(1000)
iTrashRaw_Trigger.sendCommand("yellow")
Thread::sleep(5000)
if (iTrashRaw_Result.state == 0) {
iTrashYellow.sendCommand(new DateTimeType(iTrashRaw.state.toString+"T00:00:00"))
}
vTrashRead.postUpdate(OFF)
end
After doing this you get a DateTimeItem
for each kind of trash representing the date for the next trash disposal of this kind. Now you can show these items on your Sitemap, HabPanel, process them in further rules or whatever.
If you find this useful, just give it a like
If you have any questions, please ask…
Cheers
Sebastian