I have defined lights and other templates in my config.yaml like follows:
light:
- platform: template
lights:
office_light:
friendly_name: "Office Light"
unique_id: office_light
turn_on:
service: rest_command.grenton_update
data:
object: "LIGHT_BIURO_14TSH"
state: "on"
turn_off:
service: rest_command.grenton_update
data:
object: "LIGHT_BIURO_14TSH"
state: "off"
# etc
but at the same time my lights system (Grenton) will call local Home Assistant API with the status of the light office_light
anytime it changes, when it boots up, on timer etc.
Example lua code for the updates:
if module == "LIGHT_BIURO_14TSH" then
path = "/api/states/light.office_light"
if CLUZ->LIGHT_BIURO_14TSH->Value > 0 then
eventJson = {
state = "on",
attributes = {
friendly_name = "Office Light",
device_class = "light"
}
}
else
eventJson = {
state = "off",
attributes = {
friendly_name = "Office Light",
device_class = "light"
}
}
end
This leads to an issue that depending on the order of first update (either when from HA, or when from Grenton system via REST api), the following error is shown in the logs:
Platform template does not generate unique IDs. ID office_light is already used by light.office_light - ignoring light.office_light_2
Platform template does not generate unique IDs. ID living_room_main_light is already used by light.living_room_main_light - ignoring light.living_room_main_light_2
This is even more annoying because sometimes just one or two lights are not set up correctly, the rest works fine, so until I try to use it, I don’t even know that it’s not linked properly.
What should be the correct approach here?
I can try to reverse the order of updates such that it’s always polling the lights system for updates, but then I won’t get updates when the light status changes outside of HA immediately. The reverse seems not possible, as I won’t get all the lights ids until I send all of them from lights system…