openhab-core
openhab-core copied to clipboard
Device Template
An idea:
Create "device templates" which define how a device is combined into Thing + Channels + Items.
For example, a lightbulb "template" contains the information on what thing(s) to create, from what binding, and what items it should have, e.g. Switch Item for on/off, Dimmer for Brightness, Dimmer for Color Temp, A Color item (so e.g. 4 items).
So when someone wants to add 50x lightbulbs into openhab, they just define 50 instances of this template, instead of creating: 50x Things + 50 * 4 = 200 Items one by one.
Also should they want to add another item to the template, or modify the parameters of an item, e.g. Change the Brightness min/max/steps, or e.g. change its MQTT topic, it can be done on the template, and all the 50 devices will immediately follow suit.
This will greatly simplify things. Hopefully
I have been doing this for years. My "device list" is stored in a YAML file, like this (just to illustrate)
LivingRoom_Switch:
type: esphome-switch
switches:
- name: LivingRoom_Kitchen_Light
label: Living Room Kitchen Light
groups:
- gInsideLights
- gLivingRoomLights
- LivingRoom_Kitchen_Light_Bulb
tags:
- Light
ga: Light
alexa: Light
metadata:
probability: 0.95
- name: LivingRoom_TV_Light
label: Living Room TV Light
groups:
- gInsideLights
- gPresenceSimulators
- gLivingRoomLights
- LivingRoom_TV_Light_Bulb
tags:
- Light
ga: Light
alexa: Light
metadata:
probability: 0.95
- name: LivingRoom_Table_Light
label: Living Room Table Light
groups:
- gInsideLights
- gPresenceSimulators
- gLivingRoomLights
- LivingRoom_Table_Light_Bulb
tags:
- Light
ga: Light
alexa: Light
metadata:
probability: 0.95
- name: LivingRoom_Bar_Light
label: Living Room Tea Corner Light
groups:
- gInsideLights
- gPresenceSimulators
- gLivingRoomLights
- LivingRoom_Bar_Light_Bulb
tags:
- Light
ga: Light
alexa: Light
metadata:
probability: 0.95
buttons:
- name: LivingRoom_Kitchen_Light_Button
groups:
- gGroupedSwitches
metadata:
group: gLivingRoomLights
- name: LivingRoom_TV_Light_Button
groups:
- gGroupedSwitches
metadata:
group: gLivingRoomLights
- name: LivingRoom_Table_Light_Button
groups:
- gGroupedSwitches
metadata:
group: gLivingRoomLights
- name: LivingRoom_Bar_Light_Button
groups:
- gGroupedSwitches
metadata:
group: gLivingRoomLights
So I have a "Device template" (aka type) of esphome-switch. In this, I would create the Thing, Channels (MQTT), and Items based on that given YAML definition.
Obviously the structure of the YAML is not the point here. It is specific to my implementation.
What this does:
- I can add more Switch devices easily by just adding another entry like that
- I can still fully customise each items with group / tags / metadata etc.
- I can modify the template should I need to make adjustments
- I can easily keep the yaml structure above and set it to use a different "template" (i.e.
type) and instantly migrate my things/items to a different type of device, e.g. a Zigbee switch instead of ESPHome.
This would make configuring certain devices really easy - also, can be used to easily reproduce certain issues too - by giving a device template