Generating Items Files via Shell Script

Hello Together,
as i have many things and i have realized, that home automation never stands still, it becames quite painful to edit item files by mass when changing items of specific types.
For example: if you want to add Items for a specific Light Bulb and you would have to add this item to 30 things, you know what i mean. The script is individual to bindings, as there are several channels. The Logic of the script is still the same. I completed the Script for Hue and for homematic.
Therefore i created a shell Script (I will polish this by receiving all things from hue api , but next step!).

This script can be easily converted to your needs.
For my needs i decided to use the following naming convention, that is parsed in my script:
Room_Vendor_Type_Count
I.e. LivingRoom_Hue_Color_1

I also created a roomlist.txt that will be read every time the script is executed. Therefore i can add Groups for each rooms and add items for that.

Check it out :wink: This way i have a structured way of bring out items for my things:
roomlist.txt:

LivingRoom
Bath
DiningRoom

/etc/openhab2/scripts/autoCreateItems_Hue.sh

#!/bin/bash
destfile="/home/XXXXX/${1}.items"
# Add all Groups
echo "//This file is automatically generated! Edits will be overwritten" > ${destfile}
echo "//Global Groups" >> ${destfile}
echo "Group:Dimmer:MAX gLichtDimmer \"Dimmer\"" >> ${destfile}
echo "Group:Color:AND(OFF, ON) gLichtColor \"Color\"" >> ${destfile}
echo "Group:String gLichtAlert \"Alarm\"" >> ${destfile}
echo "Group:Switch gLichtEffect \"Effekt\"" >> ${destfile}
echo "Group:Switch:AND(OFF, ON) gLicht \"Licht\"" >> ${destfile}
echo "Group:Switch:AND(OFF, ON) gPower \"Steckdosen An/Aus\"" >> ${destfile}
for h in `cat /etc/openhab2/scripts/roomlist.txt`
do
        echo "" >> ${destfile}
        echo "//${h} Groups" >> ${destfile}
        echo "Group:Dimmer:MAX gLichtDimmer_${h} \"Dimmer ${h}\" (gLichtDimmer)" >> ${destfile}
        echo "Group:Color:AND(OFF, ON) gLichtColor_${h} \"Color ${h}\" (gLichtColor)" >> ${destfile}
        echo "Group:String gLichtAlert_${h} \"Alarm ${h}\" (gLichtAlert)" >> ${destfile}
        echo "Group:Switch gLichtEffect_${h} \"Effekt ${h}\" (gLichtEffect)" >> ${destfile}
        echo "Group:Switch gPower_${h} \"Steckdosen An/Aus ${h}\" (gPower)" >> ${destfile}
done
IFS="]"
j=1
for i in `cat /etc/openhab2/things/${1}.things`
do
        bridge_line=`echo $i | sed '/^[[:space:]]*$/d'| tr -s ' ' |grep -v "{"|grep -v "}" |grep "Bridge"` 
        thing_line=`echo $i | sed '/^[[:space:]]*$/d'| tr -s ' ' |grep -v "{"|grep -v "}" |grep "Thing"` 
        #echo "i:$thing_line"
        if [ $j -eq 1 ] && [ ! -z $bridge_line ]; then
                bridge_id=`echo $bridge_line |cut -d ":" -f3 | cut -d " " -f1`
        fi
        if [ ! -z $thing_line ]; then
                current_type=`echo $thing_line |cut  -d " " -f3`
                current_id=`echo $thing_line |cut  -d " " -f4`
                current_vendor=`echo $thing_line |cut  -d " " -f5 |cut -d "_" -f2`
                current_counter=`echo $thing_line |cut  -d " " -f5 |cut -d "_" -f5`
                current_room=`echo $thing_line |cut  -d " " -f5 | cut -d "\"" -f2 | cut -d "_" -f1`
                current_name=`echo $thing_line |cut  -d " " -f5 | cut -d "\"" -f2`
                current_description=`echo ${current_vendor} ${current_counter}`
#               echo "bridge_id: $bridge_id"
#               echo "current_type: $current_type"
#               echo "current_id: $current_id"
#               echo "current_room: $current_room"
#               echo "current_name: $current_name"
#               echo "current_description: $current_description"
                echo "" >> ${destfile}
                echo "//${current_name}" >> ${destfile}
                case $current_type in
                        0000 )
                                ;;
                        0010 )
                                echo "Switch ${current_name}_Power \"${current_description} An/Aus\" <light> (g${current_room}, gPower_${current_room}) {channel=\"hue:${current_type}:${bridge_id}:${current_id}:switch\"}" >> ${destfile}
                                ;;
                        0100 )
                                echo "Dimmer ${current_name}_Dimmer \"${current_description} Dimmer\" <light> (g${current_room}, gLicht_${current_room}, gLichtDimmer_${current_room}) {channel=\"hue:${current_type}:${bridge_id}:${current_id}:brightness\"}" >> ${destfile}
                                ;;
                        0110 )
                                ;;
                        0200 )
                                ;;
                        0210 )
                                echo "Dimmer ${current_name}_Dimmer \"${current_description} Dimmer\" <light> (g${current_room}, gLicht_${current_room}, gLichtDimmer_${current_room}) {channel=\"hue:${current_type}:${bridge_id}:${current_id}:color\"}" >> ${destfile}
                                echo "Color ${current_name}_Color \"${current_description} Farbe\" <color> (g${current_room}, gLichtColor_${current_room}) {channel=\"hue:${current_type}:${bridge_id}:${current_id}:color\"}" >> ${destfile}
                                echo "String ${current_name}_Alert \"${current_description} Alarm\" <color> (gLichtAlert_${current_room}) {channel=\"hue:${current_type}:${bridge_id}:${current_id}:alert\"}" >> ${destfile}
                                echo "Switch ${current_name}_Effect \"${current_description} Effekt\" <color> (gLichtEffect_${current_room}) {channel=\"hue:${current_type}:${bridge_id}:${current_id}:effect\"}" >> ${destfile}
                                ;;
                        0220 )
                                ;;
                esac
                j=$[j+1]
        fi
done

Run the script with a parameter to things file:
$ /etc/openhab2/scripts/autoCreateItems_Hue.sh hue

My biggest wish for Openhab is, that you can extract items Strings from PaperUI.
Feel free to ask :slight_smile:

Edit: Here you have a homematic script, and a deconz script!

Homematic:

#!/bin/bash
destfile="/etc/openhab2/items/${1}.items"
# Add all Groups
echo "//This file is automatically generated! Edits will be overwritten" > ${destfile}
echo "//Global Groups" >> ${destfile}
echo "Group gTemperatur_Soll \"Zieltemperaturen alle Heizungen\"" >> ${destfile}
echo "Group gTemperatur_Ist \"Temperaturen alle Heizungen\"" >> ${destfile}
echo "Group gTemperatur_Ventil \"Ventilöffnungen alle Heizungen\"" >> ${destfile}
echo "Group gTemperatur_Ventil_Persistence \"Persistenceitem f√ľr Ventil√∂ffnungen\"" >> ${destfile}
echo "Group gTemperatur_Ventil_Counter \"Counter f√ľr Ventil√∂ffnungen\" (gTemperatur_Ventil_Persistence)" >> ${destfile}
echo "Group:Number:SUM gTemperatur_Ventil_Hourly \"Counter f√ľr Ventil√∂ffnungen hourly\" (gTemperatur_Ventil_Persistence)" >> ${destfile}
echo "Group:Number:SUM gTemperatur_Ventil_Daily \"Counter f√ľr Ventil√∂ffnungen daily\" (gTemperatur_Ventil_Persistence)" >> ${destfile}
echo "Group:Number:SUM gTemperatur_Ventil_Weekly \"Counter f√ľr Ventil√∂ffnungen weekly\" (gTemperatur_Ventil_Persistence)" >> ${destfile}
echo "Group:Number:SUM gTemperatur_Ventil_Monthly \"Counter f√ľr Ventil√∂ffnungen monthly\" (gTemperatur_Ventil_Persistence)" >> ${destfile}
echo "Group gHeizung_Manu" >> ${destfile}
echo "Group gHeizung_Auto" >> ${destfile}
echo "Group gStatistic \"Gruppe f√ľr Statistikauswertung\"" >> ${destfile}
echo "Group gStatistic_Hourly" >> ${destfile}
echo "Group gStatistic_Daily" >> ${destfile}
echo "Group gStatistic_Weekly" >> ${destfile}
echo "Group gStatistic_Monthly" >> ${destfile}
echo "Group gSensors" >> ${destfile}
for h in `cat /etc/openhab2/scripts/roomlist.txt`
do
        echo "" >> ${destfile}
        echo "//${h} Groups" >> ${destfile}
done
IFS="]"
j=1
for i in `cat /etc/openhab2/things/${1}.things`
do
        bridge_line=`echo $i | sed '/^[[:space:]]*$/d'| tr -s ' ' |grep -v "{"|grep -v "}" |grep "Bridge"` 
        thing_line=`echo $i | sed '/^[[:space:]]*$/d'| tr -s ' ' |grep -v "{"|grep -v "}" |grep "Thing"` 
        if [ $j -eq 1 ] && [ ! -z $bridge_line ]; then
                bridge_id=`echo $bridge_line |cut -d ":" -f3 | cut -d " " -f1`
        fi
        if [ ! -z $thing_line ]; then
                current_type=`echo $thing_line |cut  -d " " -f3`
                current_id=`echo $thing_line |cut  -d " " -f4`
                current_vendor=`echo $thing_line |cut  -d " " -f5 |cut -d "_" -f2`
                current_counter=`echo $thing_line |cut  -d " " -f5 |cut -d "_" -f5`
                current_room=`echo $thing_line |cut  -d " " -f5 | cut -d "\"" -f2 | cut -d "_" -f1`
                current_name=`echo $thing_line |cut  -d " " -f5 | cut -d "\"" -f2`
                current_description=`echo "${current_vendor} ${current_counter}"`
                if [ "$2" == "debug" ]; then
                        echo "line:$i"
                        echo "bridge_id: $bridge_id"
                        echo "current_type: $current_type"
                        echo "current_id: $current_id"
                        echo "current_room: $current_room"
                        echo "current_name: $current_name"
                        echo "current_description: $current_description"
                fi
                echo "" >> ${destfile}
                echo "//${current_name}" >> ${destfile}
                case $current_type in
                       HM-CC-RT-DN )
                                echo "Number ${current_name}_Empfang  \"${current_room} Heizkörperthermostat Empfang\" (gEmpfang) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:0#SIGNAL_STRENGTH\"}" >> ${destfile}
                                echo "Switch ${current_name}_Batterie \"${current_room} Heizkörperthermostat Batterie\" (gBatterie) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:0#LOWBAT\" }" >> ${destfile}
                                echo "Number ${current_name}_Ventil \"${current_name} Ventil zu [%.1f]% geöffnet\" (gTemperatur_Ventil) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:4#VALVE_STATE\"}" >> ${destfile}
                                echo "Switch ${current_name}_Ventil_AnAus \"${current_name} Ventil An/Aus\"" >> ${destfile}
                                echo "Number ${current_name}_Counter \"Z√§hlt die Sekunden multipliziert mit der √Ėffnung entsprechend der Ventil√∂ffnung\" (gTemperatur_Ventil_Counter,gStatistic)" >> ${destfile}
                                echo "Number ${current_name}_Ventil_Counter_Daily \"Z√§hlt die Sekunden multipliziert mit der √Ėffnung entsprechend der Ventil√∂ffnung\" (gTemperatur_Ventil_Counter_Daily,gStatistic_Daily)" >> ${destfile}
                                echo "Number ${current_name}_Ventil_Counter_Hourly \"Z√§hlt die Sekunden multipliziert mit der √Ėffnung entsprechend der Ventil√∂ffnung\" (gTemperatur_Ventil_Counter_Hourly,gStatistic_Hourly)" >> ${destfile}
                                echo "Number ${current_name}_Ventil_Counter_Weekly \"Z√§hlt die Sekunden multipliziert mit der √Ėffnung entsprechend der Ventil√∂ffnung\" (gTemperatur_Ventil_Counter_Weekly,gStatistic_Weekly)" >> ${destfile}
                                echo "Number ${current_name}_Ventil_Counter_Monthly \"Z√§hlt die Sekunden multipliziert mit der √Ėffnung entsprechend der Ventil√∂ffnung\" (gTemperatur_Ventil_Counter_Monthly,gStatistic_Monthly)" >> ${destfile}
                                ;;
                       HM-TC-IT-WM-W-EU )
                                echo "Number ${current_room}_Temperatur \"Die ${current_room}temperatur betr√§gt [%.1f] ¬įC\" <temperature> (gTemperatur_Ist) [ \"CurrentTemperature\" ] { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:1#TEMPERATURE\" }" >> ${destfile}
                                echo "Number ${current_room}_Temperatur_Soll \"Die ${current_room}temperatur soll [%.1f] ¬įC betragen\" <temperature> (gTemperatur_Soll) [ \"TargetTemperature\" ] { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:2#SET_TEMPERATURE\" }" >> ${des$
                                echo "Number ${current_room}_Luftfeuchtigkeit \"Die ${current_room}luftfeuchtigkeit beträgt [%d]\" (gLuftfeuchte_Ist) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:1#HUMIDITY\" }" >> ${destfile}
                                echo "Switch ${current_name}_Batterie \"${current_room} Wandthermostat Batterie\" (gBatterie) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:0#LOWBAT\" }" >> ${destfile}
                                echo "Number ${current_name}_Empfang \"${current_room} Wandthermostat Empfang\" (gEmpfang) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:0#SIGNAL_STRENGTH\" }" >> ${destfile}
                                echo "String ${current_name}_Modus \"${current_room} Wandthermostat Modus\" (gHeizModus) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:2#CONTROL_MODE\" }" >> ${destfile}
                                echo "Number ${current_name}_Modus_Num" >> ${destfile}
                                echo "Switch ${current_name}_Modus_Auto \"${current_room} Wandthermostat Modus\" (gHeizung_Auto) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:2#AUTO_MODE\" }" >> ${destfile} 
                                echo "Number ${current_name}_Modus_Manu \"${current_room} Wandthermostat Modus\" (gHeizung_Manu) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:2#MANU_MODE\" }" >> ${destfile}
                                echo "Switch ${current_name}_Heizung_AnAus \"${current_room} Wandthermostat heizt\"" >> ${destfile}
                                ;;
                        HM-RC-8 )
                                echo "Number ${current_name}_Empfang  \"${current_room} Fernbedienung Empfang\" (gEmpfang) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:0#SIGNAL_STRENGTH\"}" >> ${destfile}
                                echo "Switch ${current_name}_Batterie \"${current_room} Fernbedienung Batterie\" (gBatterie) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:0#LOWBAT\" }" >> ${destfile}
                                echo "Switch ${current_name}_Short_1 \"${current_room}fernbedienung Taste 1\" { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:1#PRESS_SHORT\" }" >> ${destfile}
                                echo "Switch ${current_name}_Short_2 \"${current_room}fernbedienung Taste 2\" { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:2#PRESS_SHORT\" }" >> ${destfile}
                                echo "Switch ${current_name}_Short_3 \"${current_room}fernbedienung Taste 3\" { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:3#PRESS_SHORT\" }" >> ${destfile}
                                echo "Switch ${current_name}_Short_4 \"${current_room}fernbedienung Taste 4\" { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:4#PRESS_SHORT\" }" >> ${destfile}
                                echo "Switch ${current_name}_Short_5 \"${current_room}fernbedienung Taste 5\" { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:5#PRESS_SHORT\" }" >> ${destfile}
                                echo "Switch ${current_name}_Short_6 \"${current_room}fernbedienung Taste 6\" { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:6#PRESS_SHORT\" }" >> ${destfile}
                                echo "Switch ${current_name}_Short_7 \"${current_room}fernbedienung Taste 7\" { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:7#PRESS_SHORT\" }" >> ${destfile}
                                echo "Switch ${current_name}_Short_8 \"${current_room}fernbedienung Taste 8\" { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:8#PRESS_SHORT\" }" >> ${destfile}
                                ;;
                        HM-LC-Sw1PBU-FM )
                                echo "Switch ${current_name}_Power \"$current_name\" <light> (g${current_room}) [ \"Switchable\" ] { channel= \"homematic:${current_type}:${bridge_id}:${current_id}:1#STATE\" }" >> ${destfile}
                                echo "Number ${current_name}_Empfang  \"${current_room} Schalter Empfang\" (gEmpfang) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:0#SIGNAL_STRENGTH\"}" >> ${destfile}
                                echo "String ${current_name}_HeatingCoolingMode \"${current_name} Heating/Cooling Mode\" [ \"homekit:HeatingCoolingMode\" ]" >> ${destfile}
                                echo "Number ${current_name}_Chart_Period" >> ${destfile}
                                ;;
                        HM-Sen-DB-PCB )
                                echo "Switch ${current_name}_PressShort \"${current_name} Zähler\" (gSensor) { channel= \"homematic:${current_type}:${bridge_id}:${current_id}:1#PRESS_SHORT\" }" >> ${destfile} 
                                echo "Switch ${current_name}_Button \"${current_name} Button\"  { channel= \"homematic:${current_type}:${bridge_id}:${current_id}:1#BUTTON\" }" >> ${destfile}
                                echo "Switch ${current_name}_PressTrigger \"${current_name} Trigger durch Channel\"" >> ${destfile}
                                echo "Switch ${current_name}_Press \"${current_name} Lang Zähler\"  { channel= \"homematic:${current_type}:${bridge_id}:${current_id}:1#PRESS\" }" >> ${destfile}
                                echo "Switch ${current_name}_Batterie \"${current_name} Batterie\" (gBatterien) { channel= \"homematic:${current_type}:${bridge_id}:${current_id}:0#LOWBAT\" }" >> ${destfile}
                                echo "Number ${current_name}_Empfang \"${current_name} Empfang\" (gEmpfang) { channel= \"homematic:${current_type}:${bridge_id}:${current_id}:0#SIGNAL_STRENGTH\" }" >> ${destfile}
                                ;;
                        HM-LC-Sw1-Ba-PCB )
                                echo "Switch ${current_name} \"${current_name}\" [ \"Switchable\" ] { channel= \"homematic:${current_type}:${bridge_id}:${current_id}:1#STATE\" }" >> ${destfile}
                                echo "Switch ${current_name}_OnOff \"${current_name} An/Aus\" [ \"Switchable\" ] { channel= \"homematic:${current_type}:${bridge_id}:${current_id}:1#STATE\" }" >> ${destfile}
                                echo "Number ${current_name}_Empfang \"${current_name} Empfang\" (gEmpfang) { channel= \"homematic:${current_type}:${bridge_id}:${current_id}:0#SIGNAL_STRENGTH\" }" >> ${destfile}
                                echo "Switch ${current_name}_Batterie \"${current_name} Batterie\" (gBatterie) { channel=\"homematic:${current_type}:${bridge_id}:${current_id}:0#LOWBAT\" }" >> ${destfile}
                                echo "Switch ${current_name}_CodePressed \"${current_name} Code gedr√ľckt\"" >> ${destfile}
                                echo "Switch ${current_name}_Oeffner \"${current_name} Oeffner\" [ \"Switchable\" ]" >> ${destfile}
                                ;;
                esac
                j=$[j+1]
        fi
done

deconz

!/bin/bash
destfile="/etc/openhab2/items/${1}.items"
# Add all Groups
echo "//This file is automatically generated! Edits will be overwritten" > ${destfile}
echo "//Global Groups" >> ${destfile}
echo "Group:Switch:AND(OFF, ON) gMotion \"Bewegung\"" >> ${destfile}
echo "Group:Switch:AND(OFF, ON) gContact \"Fenster und T√ľrenkontakte\"" >> ${destfile}
echo "Group:DateTime gLastUpdate \"Letztes Update\"" >> ${destfile}
echo "Group:Number gButtonPressed \"Fernbedienungsbuttons\"" >> ${destfile}
for h in `cat /etc/openhab2/scripts/roomlist.txt`
do
        echo "" >> ${destfile}
        echo "//${h} Groups" >> ${destfile}
        echo "Group:Switch gMotion_${h} \"Bewegung ${h}\" (gMotion)" >> ${destfile}
        echo "Group:DateTime gLastUpdate_${h} \"Letztes Update ${h}\" (gLastUpdate)" >> ${destfile}
        echo "Group:Switch gContact_${h} \"Fenster und T√ľrenkontakte ${h}\" (gContact)" >> ${destfile}
        echo "Group:Number gButtonPressed_${h} \"Fernbedienungsbuttons ${h}\" (gButtonPressed)" >> ${destfile}
done
# Create General Items
IFS="]"
j=1
for i in `cat /etc/openhab2/things/${1}.things`
do
        bridge_line=`echo $i | sed '/^[[:space:]]*$/d'| tr -s ' ' |grep -v "{"|grep -v "}" |grep "Bridge"` 
        thing_line=`echo $i | sed '/^[[:space:]]*$/d'| tr -s ' ' |grep -v "{"|grep -v "}" |grep "Thing"` 
        #echo "i:$thing_line"
        if [ $j -eq 1 ] && [ ! -z $bridge_line ]; then
                bridge_id=`echo $bridge_line |cut -d ":" -f3 | cut -d " " -f1`
        fi
        if [ ! -z $thing_line ]; then
                current_type=`echo $thing_line |cut  -d " " -f3`
                current_id=`echo $thing_line |cut  -d " " -f4`
                current_vendor=`echo $thing_line |cut  -d " " -f5 |cut -d "_" -f2`
                current_counter=`echo $thing_line |cut  -d " " -f5 |cut -d "_" -f5`
                current_room=`echo $thing_line |cut  -d " " -f5 | cut -d "\"" -f2 | cut -d "_" -f1`
                current_name=`echo $thing_line |cut  -d " " -f5 | cut -d "\"" -f2`
                current_description=`echo ${current_vendor} ${current_counter}`
                if [ "$2" == "debug" ]; then
                echo "line: $i"
                echo "bridge_id: $bridge_id"
                echo "current_type: $current_type"
                echo "current_id: $current_id"
                echo "current_room: $current_room"
                echo "current_name: $current_name"
                echo "current_description: $current_description"
                fi
                echo "" >> ${destfile}
                echo "//${current_name}" >> ${destfile}
                case $current_type in
                        presencesensor )
                                echo "Switch ${current_name}_Motion \"${current_name} Bewegung\" <motion> (gMotion_${current_room}) {channel=\"deconz:${current_type}:${bridge_id}:${current_id}:presence\"}" >> ${destfile}
                                echo "DateTime ${current_name}_LastUpdate \"${current_name} Letztes Update\"  {channel=\"deconz:${current_type}:${bridge_id}:${current_id}:last_updated\"}" >> ${destfile}
                                echo "Number ${current_name}_batteryLevel \"${current_name} Batterie\"  {channel=\"deconz:${current_type}:${bridge_id}:${current_id}:battery_level\"}" >> ${destfile}
                                echo "Switch ${current_name}_batteryLow \"${current_name} Batterie niedrig\"  {channel=\"deconz:${current_type}:${bridge_id}:${current_id}:battery_low\"}" >> ${destfile}
                                ;;
                        switch )
                                echo "Number ${current_name}_button \"${current_name} ButtonID\" (gButtonPressed_${current_room}) {channel=\"deconz:${current_type}:${bridge_id}:${current_id}:button\"}" >> ${destfile}
                                echo "DateTime ${current_name}_LastUpdate \"${current_name} Letztes Update\"  {channel=\"deconz:${current_type}:${bridge_id}:${current_id}:last_updated\"}" >> ${destfile}
                                echo "Number ${current_name}_batteryLevel \"${current_name} Batterie\"  {channel=\"deconz:${current_type}:${bridge_id}:${current_id}:battery_level\"}" >> ${destfile}
                                echo "Switch ${current_name}_batteryLow \"${current_name} Batterie niedrig\"  {channel=\"deconz:${current_type}:${bridge_id}:${current_id}:battery_low\"}" >> ${destfile}
                                ;;
                        openclosesensor )
                                echo "Contact ${current_name}_Contact \"${current_name} T√ľr/Fensterkontakt \" <door> (gContact_${current_room}) {channel=\"deconz:${current_type}:${bridge_id}:${current_id}:open\"}" >> ${destfile}
                                echo "DateTime ${current_name}_LastUpdate \"${current_name} Letztes Update\"  {channel=\"deconz:${current_type}:${bridge_id}:${current_id}:last_updated\"}" >> ${destfile}
                                echo "Number ${current_name}_batteryLevel \"${current_name} Batterie\"  {channel=\"deconz:${current_type}:${bridge_id}:${current_id}:battery_level\"}" >> ${destfile}
                                echo "Switch ${current_name}_batteryLow \"${current_name} Batterie niedrig\"  {channel=\"deconz:${current_type}:${bridge_id}:${current_id}:battery_low\"}" >> ${destfile}
                                ;;
                esac
                j=$[j+1]
        fi
done

need a hue and deconz thing creator? Here it is:
/etc/openhab2/scripts/autoCreateThings_hue.sh

!/bin/bash
destfile="/etc/openhab2/things/${1}.things"
# Add all Things
bridgeIP="127.0.0.1:18443"
bridgeID=`curl -s -X GET http://127.0.0.1:18443/api/778DAE9F74/ | jq -r '.config.bridgeid'`
apikey="XXXXX"
pollingInterval="5"
sensorPollingInterval="500"
echo "Bridge hue:bridge:${bridgeID} [ ipAddress=\"${bridgeIP}\", userName=\"${apikey}\", pollingInterval=\"${pollingInterval}\", sensorPollingInterval=\"${sensorPollingInterval}\" ] {" > $destfile
for h in `curl -s -X GET http://127.0.0.1:18443/api/778DAE9F74/lights | jq keys_unsorted[] -r`
do
#       echo $h
        current_name=`curl -s -X GET http://127.0.0.1:18443/api/778DAE9F74/lights | jq -r --arg h "$h" '.[$h].name'` 
        current_type=`echo $current_name |cut -d "_" -f3`
        #Create general Items
                case $current_type in
                        White )
                                echo "  Thing 0100 $h \"${current_name}\" @ \"${current_room}\" [ lightId=\"$h\" ]" >> $destfile
                                ;;
                        Color )
                                echo "  Thing 0210 $h \"${current_name}\" @ \"${current_room}\" [ lightId=\"$h\" ]" >> $destfile
                                ;;
                        Stripe )
                                echo "  Thing 0210 $h \"${current_name}\" @ \"${current_room}\" [ lightId=\"$h\" ]" >> $destfile
                                ;;
                        Steckdose )
                                echo "  Thing 0010 $h \"${current_name}\" @ \"${current_room}\" [ lightId=\"$h\" ]" >> $destfile
                                ;;
                esac
done
echo "}" >> $destfile

Here for deconz

#!/bin/bash
destfile="/etc/openhab2/things/${1}.things"
# Add all Things
        echo ""> $destfile
bridgeID=`curl -s -X GET http://127.0.0.1:18443/api/778DAE9F74/ | jq -r '.config.bridgeid'`
bridgeIP="127.0.0.1:18443"
apikey="XXXXXXXX"
pollingInterval="5"
sensorPollingInterval="500"
echo "Bridge deconz:deconz:${bridgeID} [ host=\"${bridgeIP}\", apikey=\"${apikey}\" ] {" > $destfile
for h in `curl -s -X GET http://127.0.0.1:18443/api/778DAE9F74/sensors | jq keys_unsorted[] -r`
do
        current_name=`curl -s -X GET http://127.0.0.1:18443/api/778DAE9F74/sensors | jq -r --arg h "$h" '.[$h].name'` 
        current_type=`curl -s -X GET http://127.0.0.1:18443/api/778DAE9F74/sensors | jq -r --arg h "$h" '.[$h].type'`
        current_room=`echo $current_name |cut -d "_" -f1`
        #Create general Items
                case $current_type in
                        ZHAPresence )
                                echo "  Thing presencesensor ${h} \"${current_name}\" @ \"${current_room}\" [ id=\"${h}\" ]" >> $destfile
                                ;;
                        ZHASwitch )
                                echo "  Thing switch ${h} \"${current_name}\" @ \"${current_room}\" [ id=\"${h}\" ]" >> $destfile
                                ;;
                        Kontakt )
                                echo "  Thing openclosesensor ${h} \"${current_name}\" @ \"${current_room}\" [ id=\"${h}\" ]" >> $destfile
                                ;;
                esac
done
echo "}" >> $destfile

Its now a completed process for automatically creating things and items in openhab for hue and deconz on file level. Homematic should also be ppossible with xmlapi plugin on CCU.
I will look into it!

1 Like

This is also possible using the new rule, scripted automation, and the helper libraries, using the core.items module to add/remove Items.

Currently, a ManagedItemProvider is used, so the Items are added into the jsondb (like when added through the UI) and persist after OH restarts. However, I am currently testing an update that adds the option to use a regular ItemProvider so that the Items are no longer available after an OH restart, similar to the functionality of .items files.

3 Likes

Nice Idea,

For me personally as a Bash friend, i prefer mine solution. This way i can easily modify the process for my needs! As someone said, there are many ways that lead to rome :slight_smile:

This is a good idea. I am finding a similar pattern - adding something especially MQTT based, e.g. a Tasmota based light bulb, I will first have to add the same set of channels to a thing, then create the same set of items for that thing.

Using a script I can just say create this thing/item named Bedroom4_Light and it will generate the .things and .items entries for me.

Thanks for the idea! I’ll write my own script to suit my needs.

I don‚Äôt know how OpenHAB 3 will implement things / items database, but if they will be GUI based, it should let us create ‚Äúthing‚ÄĚ and ‚Äúitem‚ÄĚ templates to achieve this.

1 Like

Update: Just added deconz and homematic Templates

If you get this working with MQTT Things and items please let me know as this would be a great tool.

Added Hue and deconz Things creator.

a Wrapperscript could look like that:
autoCreate.sh

#!/bin/bash

/etc/openhab2/scripts/autoCreateThings_${1}.sh $1
/etc/openhab2/scripts/autoCreateItems_${1}.sh $1