HA really needs to rethink light templates

I have some zigbee rgbw lights connected to an zigbee gateway and it exposes me a RESTful like this to update my lights parameters (rgb color, white temperature, brightness,…):

"state": {
	"power": {
		"powerState": "on"
	},
	"brightness": {
		"brightness": 30
	},
	"color-temperature": {
		"colorTemperature": 70
	},
	"color-rgb": {
		"red": 0,
		"green": 252,
		"blue": 255,
		"updated_at": 1689610155714
	},
	"startup": {
		"startup": "off"
	},
	"rssi": {
		"rssi": -58,
		"updated_at": 1689610155090
	}
}

Changing parameters and integrating with the gateway is a big challenge and needs a lot of hard working with some difficulties which may be really hard to solve.
One example of it is changing from color mode to white mode (still haven’t been solved):

In this example:

I changed my light to white and worked (because I’ve done a beautiful work around using node-red)

But HA still think my light is blue, which create some other problems for scenes, external triggers,…:

I already tried lots and lots of parameters but every time I get some type of error os miss behavior.

In summary, integrate lights is hard, demands work arounds and most of time doesn’t work as expected. I really would like to see some improvements on it.

Are you using zigbee2mqtt or Zha?

Apparently, you are not using HA native support for zigbee, so are you using the RESTful integration, or…?
Bottom-line is that nobody will consider this FR if they don’t know what you actually want to be improved.

3 Likes

integrate My lights is hard

It sounds like you’re not using one of the many standard zigbee libraries to integrate your lights and you’re having a tough time. This is expected. You should switch to Zigbee2MQTT or ZHA to integrate your lights in HA. It’s seamless. A 1 button click. No need for any “work arounds” that you’re applying here.

REST. I have an iHost and I’m connecting my RGBW Zigbee (connected to the iHost gateway) lights through REST.

Yes, I’m using a RESTful integration.
I believe the improvement needs to be discussed, but a start point should be more like a RESTful switch. On HA we have RESTful switch, sensor,… but no lights.

If it was possible it would be really awesome, but in my case I need to use RESTful integration.
In my old HA “server” I used to have the ZHA native integration, but with the current server it is not an option anymore. I had this “loss” with zigbee but gained a lot with other stuff.

Then your FR should be for a restful light, which you don’t mention at all until this post.

Some ideias I had and really miss in the settings are simple things such as:
1- The option of controlling the light colors with RGB (all my lights use RGB and the conversion from HS is not funny as appears LoL), and I even tried the other way (convert from RGB to HS to update HA from the API);
2- The option of changing brightness using percentage (instead of the current mireds I think);
3- The option of changing the scale of color temperature (each light can use different scale, mine for example uses -100 to 100);
4- And other small things like this.

1 - Why not?
2 - Not sure about ZHA, but Zigbee2MQTT can run anywhere; it doesnt have to be native to HA. When I started with HA, I ran Z2M on a w10 machine :thinking:

A Server where you would run Zigbee2MQTT. Most Raspberry-Pi models are known to work but you can run it on many computers and platforms including Linux

1 Like

You are right.
Now my work around is working like this:

Light Template:

- platform: template
  lights:
    dicroica_teste_escritorio:
      unique_id: dicroica_teste_escritorio
      friendly_name: "Dicroica Teste - Escritório"
      value_template: "{{ states('input_boolean.status_dicroica_1_escritorio') }}"
      level_template: "{{ states('input_number.brilho_dicroica_1_escritorio') | int }}"
      turn_off:
        - service: input_boolean.turn_off
          data_template:
            entity_id:
              - input_boolean.status_dicroica_1_escritorio
        - service: rest_command.status_dicroica_ihost
          data: { "sn": "dasdasdas", "n1": "power", "n2": "powerState", "state": "off"}
      turn_on:
        - service: input_boolean.turn_on
          data_template:
            entity_id:
              - input_boolean.status_dicroica_1_escritorio
        - service: rest_command.status_dicroica_ihost
          data: { "sn": "dasdasdas", "n1": "power", "n2": "powerState", "state": "on"}
      set_level:
        - service: input_number.set_value
          data:
            value: "{{ brightness | int }}"
          target:
            entity_id: input_number.brilho_dicroica_1_escritorio
        - service: rest_command.status_dicroica_ihost
          data: >
            { 
              "sn": "dasdasdas",
              "n1": "brightness", 
              "n2": "brightness", 
              "state": "{{ (brightness *  0.392156862745098) | round(2) }}" 
            }
      set_temperature:
        - service: input_number.set_value
          data:
            value: "{{ color_temp }}"
            entity_id: input_number.temperatura_cor_dicroica_1_escritorio
        - service: rest_command.status_dicroica_ihost
          data: >
            { 
              "sn": "dasdasdas", 
              "n1": "color-temperature", 
              "n2": "colorTemperature", 
              "state": "{{ (100 - ((color_temp | int - 152) / 1.74)) | round(2)}}"
            }
      set_color:
        - service: input_number.set_value
          data:
            value: "{{ h }}"
            entity_id: input_number.hue_dicroica_1_escritorio
        - service: input_number.set_value
          data:
            value: "{{ s }}"
            entity_id: input_number.sat_dicroica_1_escritorio
        - service: rest_command.color_dicroica_ihost
          data: >
            { 
              "sn": "dasdasdas", 
              "h": {{h}}, 
              "s": {{s}}, 
              "v": {{ states('input_number.brilho_dicroica_1_escritorio') }}
            }

And my RESTful Command:

status_dicroica_ihost:
    url: http://192.168.xxxxx/open-api/v1/rest/devices/{{sn}}
    method: PUT
    headers:
      Authorization: "Bearer xxxxxxxxxxxxxxxxxxxx"
      accept: "application/json, text/html"
    payload:  >
      { 
        "state": { 
          {%- if "power" in n1 -%}
            "power": { 
              "powerState": "{{state}}" 
            }
          {%- else -%}
            "power": { 
              "powerState": "on" 
            },
            "{{n1}}": { 
              "{{n2}}": {{state}}
            }
          {%- endif -%}
        } 
      }
    content_type:  'application/json; charset=utf-8'
    verify_ssl: false

  color_dicroica_ihost:
    url: http://192.168.xxxxx/open-api/v1/rest/devices/{{sn}}
    method: PUT
    headers:
      Authorization: "Bearer xxxxxxxxxxxxxxxxxxxxx"
      accept: "application/json, text/html"
    payload:  >
      {
        "state": {
          "power": {
            "powerState": "on"
          },
          {%- if (((h / 360) * 6) | round(0, 'floor')) % 6 == 0 -%}
            "color-rgb": {
              "red": {{ ((v / 255) * 255) | round(2, 'ceil') }},
              "green": {{ (((v / 255) * (1 - (1 - (((h / 360) * 6) - (((h / 360) * 6) ))) * (s / 100))) * 255) | round(2, 'ceil') }},
              "blue": {{ (((v / 255) * (1 - (s / 100))) * 255) | round(2, 'ceil') }}
            }
          {%- elif (((h / 360) * 6) | round(0, 'floor')) % 6 == 1 -%}
            "color-rgb": {
              "red": {{ (((v / 255) * (1 - (((h / 360) * 6) - (((h / 360) * 6) )) * (s / 100))) * 255) | round(2, 'ceil') }},
              "green": {{ ((v / 255) * 255) | round(2, 'ceil') }},
              "blue": {{ (((v / 255) * (1 - (s / 100))) * 255) | round(2, 'ceil') }}
            }
          {%- elif (((h / 360) * 6) | round(0, 'floor')) % 6 == 2 -%}
            "color-rgb": {
              "red": {{ (((v / 255) * (1 - (s / 100))) * 255) | round(2, 'ceil') }},
              "green": {{ ((v / 255) * 255) | round(2, 'ceil') }},
              "blue": {{ (((v / 255) * (1 - (1 - (((h / 360) * 6) - (((h / 360) * 6) ))) * (s / 100))) * 255) | round(2, 'ceil') }}
            }
          {%- elif (((h / 360) * 6) | round(0, 'floor')) % 6 == 3 -%}
            "color-rgb": {
              "red": {{ (((v / 255) * (1 - (s / 100))) * 255) | round(2, 'ceil') }},
              "green": {{ (((v / 255) * (1 - (((h / 360) * 6) - (((h / 360) * 6) )) * (s / 100))) * 255) | round(2, 'ceil') }},
              "blue": {{ ((v / 255) * 255) | round(2, 'ceil') }}
            }
          {%- elif (((h / 360) * 6) | round(0, 'floor')) % 6 == 4 -%}
            "color-rgb": {
              "red": {{ (((v / 255) * (1 - (1 - (((h / 360) * 6) - (((h / 360) * 6) ))) * (s / 100))) * 255) | round(2, 'ceil') }},
              "green": {{ (((v / 255) * (1 - (s / 100))) * 255) | round(2, 'ceil') }},
              "blue": {{ ((v / 255) * 255) | round(2, 'ceil') }}
            }
          {%- elif (((h / 360) * 6) | round(0, 'floor')) % 6 == 5 -%}
            "color-rgb": {
              "red": {{ ((v / 255) * 255) | round(2, 'ceil') }},
              "green": {{ (((v / 255) * (1 - (s / 100))) * 255) | round(2, 'ceil') }},
              "blue": {{ (((v / 255) * (1 - (((h / 360) * 6) - (((h / 360) * 6) )) * (s / 100))) * 255) | round(2, 'ceil') }}
            }
          {%- endif -%}
        }
      }

              
    content_type:  'application/json; charset=utf-8'
    verify_ssl: false

It’s not pretty, but is working fine.

Because iHost ( iHost User Guide Zigbee-support List - SONOFF Official ) doesn’t provide me direct access to the chip, it exposes me a RESTful API instead.

Pfft…Why are you stuck with that host ?
I would ditch that host, and get myself a ConbeeII or something else :stuck_out_tongue:

iHost provides me a beautiful integration with my Sonoff Home Automation (I have some sensors, modules,…) and other useful stuff which helps me a lot. In fact the only problem I have today is with the RESTful light integration with HA. And some old door sensors (less important).
I already had HA in Raspberry Pi, old PC,… Dockerized, Supervised,… all with Zigbee USB Dongle.

Maybe consider

It seems sanest than creating a RESTful light integration, which would only be useful in very specific cases.

It would be great too!!