rgb and autodiscovery

For devices supporting the Auto Discovery feature. Like ZWaveJS2MQTT, Zigbee2MQTT.

Moderator: leecollings

Post Reply
akamming
Posts: 422
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

rgb and autodiscovery

Post by akamming »

Hi,

i have a selfmade LED wordclock which is controlled by an ESP8266. I created a web interface to control the colors. But now i want to connect to domoticz using autodiscovery.

I have a few questions. Hopefully someone can answer me...

Most easy would be to create a pure RGB switch. however. Whatever i try, i allways get and at least RGBW (including the WarmWhite).

I tested several types of discovery messages. Like

Code: Select all

{
  "name": "testeltje",
  "unique_id": "testeltje",
  "cmd_t": "domesphelper/light/testeltje/set",
  "stat_t": "domesphelper/light/testeltje/state",
  "schema": "json",
  "brightness": true,
  "rgb": true
}

,

or a bit more complex:

Code: Select all

{
  "name": "testeltje",
  "unique_id": "testeltje",
  "cmd_t": "domesphelper/light/testeltje/set",
  "stat_t": "domesphelper/light/teseltje/state",
  "schema": "json",
  "rgb_command_template": "{{ {'red': red, 'green': green, 'blue': blue}|to_json }}",
  "rgb_value_template": "{{ value_json.value.red }},{{ value_json.value.green }},{{ value_json.value.blue }}",
  "rgb_state_topic": "domesphelper/light/testeltje/currentColor",
  "rgb_command_topic": "domesphelper/light/testeltje/TargetColor"
}
or even the complex messages zwave2mqtt is using:

Code: Select all

{
"state_topic": "zwave/EZ/12/38/0/currentValue",
"command_topic": "zwave/EZ/12/38/0/targetValue/set",
"on_command_type": "brightness",
"state_value_template": "{{ "OFF" if value_json.value == 0 else "ON" }}",
"brightness_value_template": "{{ value_json.value }}",
"brightness_scale": 99,
"rgb_command_template": "{{ {'red': red, 'green': green, 'blue': blue}|to_json }}",
"rgb_value_template": "{{ value_json.value.red }},{{ value_json.value.green }},{{ value_json.value.blue }}",
"rgb_state_topic": "zwave/EZ/12/51/0/currentColor",
"rgb_command_topic": "zwave/EZ/12/51/0/targetColor/set",
"brightness_state_topic": "zwave/EZ/12/38/0/currentValue",
"brightness_command_topic": "zwave/EZ/12/38/0/targetValue/set",
"device": {
"identifiers": [
"zwavejs2mqtt_0xf3981245_node12"
],
"manufacturer": "Fibargroup",
"model": "RGBW Controller (FGRGBW)",
"name": "EZ-RBGW1",
"sw_version": "25.25"
},
"name": "EZ-RBGW1_rgb_dimmer",
"unique_id": "zwavejs2mqtt_0xf3981245_12-51-0-currentColor"
}
in all cases: Normal RGB operation works fine. E.g. if i click a color in domoticz in
rgb.png
rgb.png (135.16 KiB) Viewed 884 times
i get an output message in mqtt like:

Code: Select all

{"color":{"b":255,"g":141,"r":106},"state":"ON"}
however since i have to use rgbw(w): i can also set a color using this dialog
ww.png
ww.png (36.67 KiB) Viewed 884 times
and if i then pick a color i just get something like:

Code: Select all

{"brightness":3,"state":"ON"}
so i am missing the color values.

So after this long story my 2 questions are:
1. Is there some way to remove the "W" functionality from the RGBW using some kind of other autodiscovery message?
2. If not: what do i have to change so the wharmwhite color picker also results in output to MQTT?

UPDATE:
I just noticed in the 2 dialogs also the brightness slide bar does not do anything. I update the brightness on the main button (like it's a normal dimmer) i get proper output like {"brightness":96}. But if i use the brightness slider in the color picker dialog i just get an updates color message like {"state":"ON","value":{"blue":255,"green":255,"red":255,"warmWhite":0}}. so question 3 would be:
3: How do i get that brightness slider bar in the color picker to get output the value in an mqtt message
Last edited by akamming on Saturday 28 January 2023 8:08, edited 1 time in total.
User avatar
gizmocuz
Posts: 2707
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: rgb and autodiscovery

Post by gizmocuz »

Please use ESPHome, this should get you started
Domoticz does not support code inside templates

With ESPHome you can also simulate a RGB/W/WW
Quality outlives Quantity!
akamming
Posts: 422
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: rgb and autodiscovery

Post by akamming »

tx for (very quick!) response.
gizmocuz wrote: Saturday 28 January 2023 8:06 Domoticz does not support code inside templates
clear, so I have to stick to the simple version of the autodiscovery message

gizmocuz wrote: Saturday 28 January 2023 8:06 Please use ESPHome, this should get you started
the firmware is a custom firmware (does much more than just controlling a led) see https://github.com/akamming/WordclockV3. So i cannot use ESP Home for it. That's why i'm looking for the correct autodiscovery message for a RGB color switch.

Do you know where the find the autodiscovery message ESPHome is using for a RGB switch?
akamming
Posts: 422
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: rgb and autodiscovery

Post by akamming »

@gizmocuz:

I did a test: installed esphome, created a default RGB switch using autodiscovery example using esphome docs.

So go news is:

1. It created a RGB (not RGBW) switch.
2. I also captured that discovery message:

Code: Select all

{
  "schema": "json",
  "clrm": true,
  "supported_color_modes": [
    "rgb"
  ],
  "brightness": true,
  "name": "RGB Test",
  "stat_t": "rgb_test/light/rgb_test/state",
  "cmd_t": "rgb_test/light/rgb_test/command",
  "avty_t": "rgb_test/status",
  "uniq_id": "ESPlightrgb_test",
  "dev": {
    "ids": "3c6105e37e8d",
    "name": "rgb_test",
    "sw": "esphome v2022.12.8 Jan 28 2023, 09:39:21",
    "mdl": "esp01_1m",
    "mf": "espressif"
  }
}
Also the dimmer on the normal switch works fine:
dimmer.png
dimmer.png (13.6 KiB) Viewed 865 times
The bad news is: i think there is a bug in domoticz: Cause nothing is updated if i try to set the dimmer value in this dialog:
rgb.png
rgb.png (33.35 KiB) Viewed 865 times
nothing is updated

Just to be sure it is not a bug in my own code, i verified this behaviour using an ESP8266 flashed with the ESPHome firmware. Outcome: Dimmer in the RGB dialog indeed not working (same as in my own code), on the normal switch it works fine.

How to proceed... shall i report an issue on github?
User avatar
gizmocuz
Posts: 2707
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: rgb and autodiscovery

Post by gizmocuz »

I know it works with ESPHome. You can enable logging in your test device
Quality outlives Quantity!
User avatar
gizmocuz
Posts: 2707
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: rgb and autodiscovery

Post by gizmocuz »

And you can see what is send to the command topic with MQTT Explorer
RGB/W/WW switches are quite common and work
Quality outlives Quantity!
akamming
Posts: 422
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: rgb and autodiscovery

Post by akamming »

gizmocuz wrote: Saturday 28 January 2023 14:19 I know it works with ESPHome. You can enable logging in your test device
as stated above: I already tested with ESP Home and see the same issue

when (all tested using ESP Home with an RGB Switch)
- i set a dimmer using the dimmer on the switch: domoticz sends {"brightness":124} in the command topic (correct behaviour)
- i set a color using the color picker: domoticz sends {"color":{"b":77,"g":132,"r":255},"state":"ON"} in the command topic (correct be
- but when i set the color brightness using the bar in the color picker, it again sends the exact same message. No brightness info is sent:
{"color":{"b":77,"g":132,"r":255},"state":"ON"}

I know what you want to ask: I verified using mosquitto_sub. This is not the previous message. see mosquitto_sub output:

Code: Select all

{"brightness":124}
{"color":{"b":77,"g":132,"r":255},"state":"ON"}
{"color":{"b":77,"g":132,"r":255},"state":"ON"}
The 3 messages of the 3 above actions. The last one should have had some brightness info, cause i changed the brightness slider in the color picker

UPDATE:
Just to understand how it's working i installed a docker container with Home Assistant for which Autodiscovery and ESPHome was developed. In HA there is only one slider bar for brightness and it sends "{"brightness":<value>}" in the command topic. Ofcourse the color picker also works (the same way as in domoticz)

So my conclusion: the brightness slider for an RGB light in the colorpicker in Domoticz should behave the same way as the brightness slider on the button (when not using the colorpicker) and send commands like {"brightness":124} instead of {"color":{"b":77,"g":132,"r":255},"state":"ON"}

So full info for developers to reproduce this behaviour:

1. Create an ESP Home sensor with the following YAML file

Code: Select all

esphome:
  name: rgb_test
  platform: esp8266
  board: d1_mini

wifi:
  ssid: <SSID>
  password: <Secret>

# HASS API
api:

# Allow API
ota:

# Print Updates
logger:

# Example configuration entry
# Example configuration entry
light:
  - platform: rgb
    name: "Living Room Lights"
    red: output_component1
    green: output_component2
    blue: output_component3

# Example output entry
output:
  - platform: esp8266_pwm
    id: output_component1
    pin: D1
  - platform: esp8266_pwm
    id: output_component2
    pin: D2
  - platform: esp8266_pwm
    id: output_component3
    pin: D3

      # WebServer component, displays some information
web_server:
    port: 80

# Example configuration entry
mqtt:
  broker: <IP Adress of broker>
  username: <user>
  password: <pw>
2. log the mqtt output :

Code: Select all

mosquitto_sub -h <MQTT host> -p <MQTT port> -u <MQTT User> -P <MQTT Password> -t "rgb_test/light/living_room_lights/command"
3. enable autodiscovery in domoticz
4. click on "Living room lights" in domoticz (so the colorpicker appears)
5. click on the brightness slider bar.

EXPECTED Result: a message like {"brightness":<Brightness>} (and the brightness of the LED changing)
ACTUAL Result: a message like {"color":{"b":<b>,"g":<g>,"r":<r>},"state":"ON"} (which have the same values as before, so lightness of LED not changing)

i will record an issue on github

UPDATE:

no need to respond here. Recorded the issue this morning and an hour later it was fixed by @gizmocuz in latest beta (build 15013): https://github.com/domoticz/domoticz/co ... 6770b858d8
lwolf
Posts: 216
Joined: Saturday 10 November 2018 18:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hungary
Contact:

Re: rgb and autodiscovery

Post by lwolf »

gizmocuz wrote: Saturday 28 January 2023 8:06 Domoticz does not support code inside templates
Its very sad, as i see all RGB and Dimmer Shelly devices needs some sort of code inside MQTT config templates. Any plan to add simple comparison like %if json_value.ison% ?
User avatar
gizmocuz
Posts: 2707
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: rgb and autodiscovery

Post by gizmocuz »

Not at the present as I have no clue how to do this with c++, maybe there is a library for this?
But when devices just publish the correct values it won't be needed (as we already support lots of other RGB/W/WW/CT bulbs that don't need this)

Ps. the above issue with from 'akamming' was fixed recently (brightness) and does not have anything to do with config templates
Quality outlives Quantity!
lwolf
Posts: 216
Joined: Saturday 10 November 2018 18:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hungary
Contact:

Re: rgb and autodiscovery

Post by lwolf »

gizmocuz wrote: Monday 06 February 2023 11:04 But when devices just publish the correct values it won't be needed (as we already support lots of other RGB/W/WW/CT bulbs that don't need this)
I am able to integrate dimmable Shelly Duo bulb to Domoticz AD with "brightness" and "temp" JSON attributes, it seems almost fine.

But the RGBW bulb is a major headache.
Domoticz sends mqtt messages like this to the RGB light

Code: Select all

 {"color": {"r": ..., "g": ..., "b": ...}}
I tried to alter this with rgb_command_template to get proper JSON with this:

Code: Select all

"rgb_command_template": "{{ {'mode': 'color', 'red': red, 'green': green, 'blue': blue}|to_json }}"
But resulted this JSON:

Code: Select all

{"value": {"red": ..., "green": ..., "blue": ...}}
Sadly the Shelly awaits this structure to function properly:

Code: Select all

{ "mode": "color", "turn": "on","red": 0,"green": 0,"blue": 255,"gain": 100,"white": 0}
This is why simple value replacement template support is necessary, as without this, the Shelly integration into MQTT AD will never be complete.

Another interesting thing, this structure is actually working in Domoticz, tested:

Code: Select all

"val_tpl": "{%if value_json.charger==true%}ON{%else%}OFF{%endif%}"
But i am not sure if the following structure work with Domoticz, sadly this is the only way to convert values to "Wh" came from a Shelly with power monitoring:

Code: Select all

"val_tpl": "{{(value|float/60)|round(2)}}"
lwolf
Posts: 216
Joined: Saturday 10 November 2018 18:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hungary
Contact:

Re: rgb and autodiscovery

Post by lwolf »

gizmocuz wrote: Monday 06 February 2023 11:04 Not at the present as I have no clue how to do this with c++, maybe there is a library for this?
Unfortunately i did not find a library about HA templates, and HA core source code is in python, not c++.
But i am sure that we can implement basic value replacement in a template string and basic math functions, to support some more complex device which needs another payload or conversion.
(i can live without several line long templates which contains multiple nested IF-ELSE structs)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest