Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device Template #3808

Open
jimtng opened this issue Sep 23, 2023 · 1 comment
Open

Device Template #3808

jimtng opened this issue Sep 23, 2023 · 1 comment
Labels
enhancement An enhancement or new feature of the Core

Comments

@jimtng
Copy link
Contributor

jimtng commented Sep 23, 2023

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.
@jimtng jimtng added the enhancement An enhancement or new feature of the Core label Sep 23, 2023
@ThaDaVos
Copy link

ThaDaVos commented Oct 3, 2023

This would make configuring certain devices really easy - also, can be used to easily reproduce certain issues too - by giving a device template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

No branches or pull requests

2 participants