Multiple instances of Items or Things , from a template Thing -- Is it possible?

Hi

I downloaded OH today on a Pi3 with a bespoke MQTT client from here: https://github.com/gpbenton/engMQTTClient

Using the homebuilder and ‘standard’ PaperUI I have successfully setup an Energenie eTRV using the MQTT addon and an MQTT Broker thing.
I can read/set TRV with ID 8008. Ive wound back the config a bit and now I;m stuck,

What I want to do is create a single “generic/template” thing for an Energenie eTRV and “instantiate” this for the 11 TRV physical devices in my home. I want to avoid having to duplicate all the effort to set up 11 TRVs when in fact I want all the same command and report topics (ref. that GitHub link above) - where the only aspect that will change is the eTRV ID. So somehow I’d need to pass the ID of the TRV , somehow.

MQTT Commands tree at /energenie/eTRV/Command/(command-as-below)/(device-id)

Command Payload Comment
Temperature 4-30 (Ascii) Set Target Temperature
Identify None Makes the MIH0013 flash
Exercise None Causes Valve to go up and down. Creates Diagnostic when finished.
Voltage None MIH0013 reports battery Voltage
Diagnostics None Causes MIH0013 to report diagnostics
ValveState “0”, “1” or “2” (ascii) 0=Set Valve Open 1=Closed 2=Normal Operation
PowerMode “0”, “1” 0=Low Power Mode off 1=On
ReportingInterval 300-3600 (ascii) Set the Reporting Interval (not tested)

MQTT States tree at /energenie/eTRV/Report/(report-command-as-below)/(device-id):

Report Payload Comment
Temperature Ascii string Measured Temperature in degrees Centigrade
TargetTemperature Ascii String Target Temperature set
Diagnostics 2 bytes byte 0 = low byte, 1 = high byte
Voltage Ascii String Reported Battery Voltage

So in other words, I want to define a single thing in OH for a “template/generic” TRV , with (if possible)
one set of topics I want to publish/subscribe to, and the channels; and finally based on this , I want to create the 11 items to represent the physical TRVs in the home. I might need to rework how I do this but you get the idea?

It seems a huge overkill to have to create all the same for all 11 TRvs where the only parameter will be the ID of the TRV I want to set/read. So Is it possible , and how.?

All I have is an items and sitemap file so I’ve posted these below:

p.s. I am a total newbie at this so please explain the solution - Ive read OH documents on Things and MQTT but clearly not capable of getting further with this,

My items file:

Group     Home                           "Keats"              <house>                                            ["Building"]

Group     OU                             "Outside"            <garden>        (Home)                             ["Outdoor"]
Group     GF                             "Ground Floor"       <groundfloor>   (Home)                             ["GroundFloor"]
Group     FF                             "First Floor"        <firstfloor>    (Home)                             ["FirstFloor"]
Group     F2                             "Second Floor"       <attic>         (Home)                             ["Attic"]

Group     OU_Garden                      "Garden"             <none>          (Home, OU)
Group     OU_Garage                      "Garage"             <garage>        (Home, OU)                         ["Garage"]
Group     OU_Driveway                    "Driveway"                           (Home, OU)                         ["Outdoor"]
Group     GF_Porch                       "Porch"              <group>         (Home, GF)                         ["Outside"]
Group     GF_Toilet                      "Toilet"             <toilet>        (Home, GF)                         ["Bathroom"]
Group     GF_Garage                      "Garage"             <garage>        (Home, GF)                         ["Garage"]
Group     GF_Kitchen                     "Kitchen"            <kitchen>       (Home, GF)                         ["Kitchen"]
Group     FF_Lounge                      "Lounge"             <sofa>          (Home, FF)                         ["Room"]
Group     FF_Bedroom                     "Bedroom"            <bedroom>       (Home, FF)                         ["Bedroom"]
Group     F2_Wardrobe                    "Wardrobe"           <wardrobe>      (Home, F2)
Group     F2_BedroomSummer               "Bedroom-Summer"     <none>          (Home, F2)
Group     F2_BedroomSpare                "Bedroom-Spare"      <none>          (Home, F2)
Group     F2_Toilet                      "Toilet"             <toilet>        (Home, F2)                         ["Bathroom"]

Switch    OU_Garage_UpAndOverDoor        "Up-and-Over-Door"   <none>          (OU_Garage, gUpAndOverDoor)                                           {channel=""}
Switch    GF_Porch_Motion                "Motion Sensor"      <motion>        (GF_Porch, gMotion)                ["MotionDetector", "Switchable"]   {channel=""}
Switch    GF_Porch_Light                 "Light"              <light>         (GF_Porch, gLight)                 ["Lighting", "Switchable"]         {channel=""}
Contact   GF_Toilet_Window               "Window"             <window>        (GF_Toilet, gWindow)               ["Window"]                         {channel=""}
Contact   GF_Garage_Door                 "Door"               <door>          (GF_Garage, gDoor)                 ["Door"]                           {channel=""}
Switch    GF_Garage_Motion               "Motion Sensor"      <motion>        (GF_Garage, gMotion)               ["MotionDetector", "Switchable"]   {channel=""}
Switch    GF_Kitchen_Fan                 "Fan"                <fan_ceiling>   (GF_Kitchen, gFan)                 ["Switchable"]                     {channel=""}
Contact   GF_Kitchen_Door                "Door"               <door>          (GF_Kitchen, gDoor)                ["Door"]                           {channel=""}
Contact   GF_Kitchen_Window              "Window"             <window>        (GF_Kitchen, gWindow)              ["Window"]                         {channel=""}
Number    GF_Kitchen_Heating             "Heating"            <heating>       (GF_Kitchen, gHeating)             ["HVAC"]                           {channel=""}
Switch    GF_Kitchen_Motion              "Motion Sensor"      <motion>        (GF_Kitchen, gMotion)              ["MotionDetector", "Switchable"]   {channel=""}
Contact   FF_Lounge_Window               "Window"             <window>        (FF_Lounge, gWindow)               ["Window"]                         {channel=""}
Number    FF_Lounge_Temperature          "Temperature"        <temperature>   (FF_Lounge, gTemperature)          ["Temperature"]                    {channel=""}
Switch    FF_Lounge_Light                "Light"              <light>         (FF_Lounge, gLight)                ["Lighting", "Switchable"]         {channel=""}
Switch    FF_Bedroom_Motion              "Motion Sensor"      <motion>        (FF_Bedroom, gMotion)              ["MotionDetector", "Switchable"]   {channel=""}
Number    FF_Bedroom_Temperature         "Temperature"        <temperature>   (FF_Bedroom, gTemperature)         ["Temperature"]                    {channel=""}
Switch    FF_Bedroom_Light               "Light"              <light>         (FF_Bedroom, gLight)               ["Lighting", "Switchable"]         {channel=""}
Contact   FF_Bedroom_Window              "Window"             <window>        (FF_Bedroom, gWindow)              ["Window"]                         {channel=""}
Contact   FF_Bedroom_Door                "Door"               <door>          (FF_Bedroom, gDoor)                ["Door"]                           {channel=""}
Contact   F2_Wardrobe_Window             "Window"             <window>        (F2_Wardrobe, gWindow)             ["Window"]                         {channel=""}
Number    F2_BedroomSummer_Temperature   "Temperature"        <temperature>   (F2_BedroomSummer, gTemperature)   ["Temperature"]                    {channel=""}
Switch    F2_BedroomSummer_Light         "Light"              <light>         (F2_BedroomSummer, gLight)         ["Lighting", "Switchable"]         {channel=""}
Contact   F2_BedroomSummer_Window        "Window"             <window>        (F2_BedroomSummer, gWindow)        ["Window"]                         {channel=""}
Contact   F2_BedroomSpare_Window         "Window"             <window>        (F2_BedroomSpare, gWindow)         ["Window"]                         {channel=""}

Group:Switch:OR(ON, OFF)         gFan             "Fan"                <fan_ceiling>   (Home)   ["Switchable"]
Group:Contact:OR(OPEN, CLOSED)   gDoor            "Door"               <door>          (Home)   ["Door"]
Group:Contact:OR(OPEN, CLOSED)   gWindow          "Window"             <window>        (Home)   ["Window"]
Group:Number:AVG                 gHeating         "Heating"            <heating>       (Home)   ["HVAC"]
Group:Switch:OR(ON, OFF)         gMotion          "Motion Sensor"      <motion>        (Home)   ["MotionDetector", "Switchable"]
Group:Switch:OR(ON, OFF)         gLight           "Light"              <light>         (Home)   ["Lighting", "Switchable"]
Group:Switch:OR(ON, OFF)         gUpAndOverDoor   "Up-and-Over-Door"   <none>          (Home)
Group:Number:AVG                 gTemperature     "Temperature"        <temperature>   (Home)   ["Temperature"]

My sitemap file:

sitemap keats label="Keats" {


    Frame label="Outside" icon="garden" {
        Group item=OU_Garden
        Group item=OU_Garage
        Group item=OU_Driveway
    }

    Frame label="Ground Floor" icon="groundfloor" {
        Group item=GF_Porch
        Group item=GF_Toilet
        Group item=GF_Garage
        Group item=GF_Kitchen
    }

    Frame label="First Floor" icon="firstfloor" {
        Group item=FF_Lounge
        Group item=FF_Bedroom
    }

    Frame label="Second Floor" icon="attic" {
        Group item=F2_Wardrobe
        Group item=F2_BedroomSummer
        Group item=F2_BedroomSpare
        Group item=F2_Toilet
    }

    Frame {
        Text label="Fan" icon="fan_ceiling" {
            Default item=GF_Kitchen_Fan label="Kitchen"
        }

        Text label="Door" icon="door" {
            Default item=GF_Garage_Door label="Garage"
            Default item=GF_Kitchen_Door label="Kitchen"
            Default item=FF_Bedroom_Door label="Bedroom"
        }

        Text label="Window" icon="window" {
            Default item=GF_Toilet_Window label="Toilet"
            Default item=GF_Kitchen_Window label="Kitchen"
            Default item=FF_Lounge_Window label="Lounge"
            Default item=FF_Bedroom_Window label="Bedroom"
            Default item=F2_Wardrobe_Window label="Wardrobe"
            Default item=F2_BedroomSummer_Window label="Bedroom-Summer"
            Default item=F2_BedroomSpare_Window label="Bedroom-Spare"
        }

        Text label="Heating" icon="heating" {
            Default item=GF_Kitchen_Heating label="Kitchen"
        }

        Text label="Motion Sensor" icon="motion" {
            Default item=GF_Porch_Motion label="Porch"
            Default item=GF_Garage_Motion label="Garage"
            Default item=GF_Kitchen_Motion label="Kitchen"
            Default item=FF_Bedroom_Motion label="Bedroom"
        }

        Text label="Light" icon="light" {
            Default item=GF_Porch_Light label="Porch"
            Default item=FF_Lounge_Light label="Lounge"
            Default item=FF_Bedroom_Light label="Bedroom"
            Default item=F2_BedroomSummer_Light label="Bedroom-Summer"
        }

        Text label="Up-and-Over-Door" {
            Default item=OU_Garage_UpAndOverDoor label="Garage"
        }

        Text label="Temperature" icon="temperature" {
            Default item=FF_Lounge_Temperature label="Lounge"
            Default item=FF_Bedroom_Temperature label="Bedroom"
            Default item=F2_BedroomSummer_Temperature label="Bedroom-Summer"
        }
    }
}

There are three approaches you can do. You can define your Things using .things files and use copy/paste/edit to create your Things. Personally, I don’t recommend this approach but you will find lots of examples with a search of the forum.

The other approach is to use the REST API docs. Create one example Thing using PaperUI. Then using the REST API you can query for that Thing to get the JSON, copy that to a text editor, make your edits, then add the Thing through the REST API docs.

The final approach, which is my least recommended approach is to stop openHAB, and copy/paste/edit the JSONDB file directly. It’s located in $OH_USERDATA/jsondb and has “Things” in the name.

Once you have the Things, you can create the Items if you haven’t already. Finally you need to link the Items to the Channels on the Things. Both of these can be done using the same approaches as described above for the Things. In this case, I recommend using .items files instead.

Unfortunately you have to create each and every Thing. If your script supported the Homie or Home Assistant MQTT topic standards, the Things could be automatically discovered and created. But since it isn’t, you have to create each Thing yourself. But you don’t have to use PaperUI to do so. There are better ways.

1 Like

You do this once. You’ve already done the hard part, getting the first device working.

Thanks, but I have no idea whar your are talking about, and in my OP I did mention I would probably need an example, a guide.

The simple method is copying and pasting in the things config , but I just wanted to confirm I guess that there is no way to configure a “template” TRV then “instantiate” it for the 11 physical devices. The answer is NO then. Mmmmm, it’s easy in HomeAssistant using the configuration file - but then again editing and updating the HomeAssistant config requires far more in depth knowledge of the system than does OpenHabian.

In all three cases you are creating one Thing, then copy/paste/edit the Thing to create more Things that are only slightly different from the first.

Ah, I see, thanks.

So would I be close if I said this would be the best start for me, modifying the IDs and topics , for my broker and things, or is there a better way>

Bridge mqtt:broker:MyMQTTBroker [ host="192.168.178.50", secure=false, username="MyUserName", password="MyPassword"] {
  Thing topic sonoff_Dual_Thing "Light_Dual" @ "Sonoff" {
    Channels:
      Type switch : PowerSwitch1  [ stateTopic="stat/sonoff_dual/POWER1" , commandTopic="cmnd/sonoff_dual/POWER1", on="ON", off="OFF"]
      Type switch : PowerSwitch2  [ stateTopic="stat/sonoff_dual/POWER2" , commandTopic="cmnd/sonoff_dual/POWER2", on="ON", off="OFF"]
      Type string : Version [stateTopic="stat/sonoff_dual/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
      }
  Thing topic sonoff_TH_Thing "Light_TH" @ "Sonoff" {
    Channels:
      Type switch : PowerSwitch  [ stateTopic="stat/sonoff_TH/POWER", commandTopic="cmnd/sonoff_TH/POWER", on="ON", off="OFF" ]
      Type string : Version [stateTopic="stat/sonoff_TH/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
      Type number : Temperature [stateTopic="tele/sonoff_TH/SENSOR", transformationPattern="JSONPATH:$.AM2301.Temperature"]
      Type number : Humidity [stateTopic="tele/sonoff_TH/SENSOR", transformationPattern="JSONPATH:$.AM2301.Humidity"]
   }
}

I don’t use .things files so I can’t say for certain, but it looks reasonable.

Thanks Rich for your kind help on this; sorry for not replying sooner, I’ve been grappling with a HVAC Z-Wave network which the super dudes on here have been helping out with.
Yes, in the end I just copied the definitions in the .things file, much quicker than using the UI albeit not as easy - well for me at least.
Cheers Rifch
Daz