Page 2 of 8

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Wed Jun 10, 2020 4:45 pm
by siclark
Done it... I use switch, based on whether redLevel is null, ie is it an RGB device or not (assumption if not is colour temp device for now), sure there is better way.

Wild card incoming MQTT devices, so I have a dedicated MQTT conncector publishing to indigo/bulbs for now, and have set up the zigbee2mqtt friendly names (that is the topic for the control message, to be the same as the indigo deviceid.

All I need to do now for a new Hue bulb, is create the dummy device in Indigo and rename the device in zigbee2mqtt and I should have it controlled from indigo.

Time for bed but this is looking good. So much so I have just ordered 4 more zigbee bulbs to get a stronger mesh working.

Code: Select all
[{"id":"912583bd.193ff","type":"tab","label":"Zigbee bulbs","disabled":false,"info":""},{"id":"197df9cb.54b346","type":"mqtt in","z":"912583bd.193ff","name":"","topic":"indigo/bulbs/#","qos":"0","datatype":"auto","broker":"628714c4.ba20ac","x":150,"y":220,"wires":[["64f796c3.fb2568"]]},{"id":"64f796c3.fb2568","type":"yaml","z":"912583bd.193ff","property":"payload","name":"","x":330,"y":220,"wires":[["b3a7269b.9b6888"]]},{"id":"4ade006f.5dc57","type":"switch","z":"912583bd.193ff","name":"","property":"payload.states.blueLevel","propertyType":"msg","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","repair":false,"outputs":2,"x":990,"y":220,"wires":[["afd675e3.e48768"],["14c27476.c3293c"]]},{"id":"14c27476.c3293c","type":"template","z":"912583bd.193ff","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"state\":\"{{payload.states.onOffState}}\",\n\"brightness\":\"{{payload.states.brightnessLevel}}\",\n\"color_temp\":\"{{payload.states.color_temp}}\"}","output":"str","x":1200,"y":300,"wires":[["ac6914e7.86bcc8"]]},{"id":"afd675e3.e48768","type":"template","z":"912583bd.193ff","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"state\":\"{{payload.states.onOffState}}\",\n\"brightness\":\"{{payload.states.brightnessLevel}}\",\n\"color\":\n{\"r\":\"{{payload.states.redLevel}}\",\n\"g\":\"{{payload.states.greenLevel}}\",\n\"b\":\"{{payload.states.blueLevel}}\"}}","output":"str","x":1200,"y":160,"wires":[["5269ca8a.5f63b4"]]},{"id":"9b280440.dd88d8","type":"change","z":"912583bd.193ff","name":"","rules":[{"t":"delete","p":"payload.name","pt":"msg"},{"t":"change","p":"payload.states.onOffState","pt":"msg","from":"True","fromt":"str","to":"ON","tot":"str"},{"t":"change","p":"payload.states.onOffState","pt":"msg","from":"False","fromt":"str","to":"OFF","tot":"str"},{"t":"set","p":"payload.states.brightnessLevel","pt":"msg","to":"$number(payload.states.brightnessLevel)","tot":"jsonata"},{"t":"set","p":"payload.states.color_temp","pt":"msg","to":"payload.states[\"whiteTemperature.ui\"]","tot":"msg"},{"t":"set","p":"payload.states.color_temp","pt":"msg","to":"1000000/$number(payload.states.color_temp)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":220,"wires":[["8d992373.40f7f"]]},{"id":"8d992373.40f7f","type":"template","z":"912583bd.193ff","name":"","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"zigbee2mqtt/{{payload.deviceId}}/set/","output":"str","x":840,"y":220,"wires":[["4ade006f.5dc57"]]},{"id":"5269ca8a.5f63b4","type":"mqtt out","z":"912583bd.193ff","name":"","topic":"","qos":"0","retain":"false","broker":"628714c4.ba20ac","x":1370,"y":160,"wires":[]},{"id":"ac6914e7.86bcc8","type":"mqtt out","z":"912583bd.193ff","name":"","topic":"","qos":"0","retain":"false","broker":"628714c4.ba20ac","x":1370,"y":300,"wires":[]},{"id":"b3a7269b.9b6888","type":"range","z":"912583bd.193ff","minin":"0","maxin":"100","minout":"0","maxout":"255","action":"clamp","round":true,"property":"payload.states.brightnessLevel","name":"","x":480,"y":220,"wires":[["9b280440.dd88d8"]]},{"id":"628714c4.ba20ac","type":"mqtt-broker","z":"","name":"qnap mqqt","broker":"192.168.0.104","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]


So it
converts message string to object,
scales the brightness,
changes True/False to ON/OFF,
changes brightness level from string to number (need to check if actually required),
creates template for the MQTT topic,
splits if RGB or colour_temp,
creates template for the payload, then sends the MQTT message.

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Wed Jun 10, 2020 6:07 pm
by FlyingDiver
Minor tweak: You could get rid of the "delete msg.payload.name" rule by taking it out of the published template. Unless you want to keep it there for debugging purposes.

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Thu Jun 11, 2020 12:29 am
by siclark
Cheers. Missed that one. No need for it as you say. It was late last night.

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Sat Jun 13, 2020 12:40 am
by siclark
A bit of a status update.

I’ve now got RGW and white ambience hue bulbs working from indigo using a zigbee USB stick and also the Hue dimmer controlling them along with the previous Aqara sensors.

The hue dimmer works just like the sensors with Shims although I haven’t worked out how to replicate the cycling of different scenes for repeated on button presses it does give the ability to now set actions for single, double and triple clicks of all 4 buttons that is good.

Actually I wonder if Philips set the double click timer to a second or more for their behaviour?

Whilst I’ve got a generic workflow working in node red for the device translations which works for both the RGB bulbs and the ambience ones, I haven’t worked out the logic for the determining how to send a colour temp change to the rgb bulb.

Whilst it works well with node red and only a limited easy setup there, I’m wondering if this is something that could be entirely done in python in indigo, although entirely beyond my skills.

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Sat Jun 13, 2020 4:38 am
by FlyingDiver
siclark wrote:
Whilst it works well with node red and only a limited easy setup there, I’m wondering if this is something that could be entirely done in python in indigo, although entirely beyond my skills.


I suspect that a plugin that works with these devices using the MQTT connector wouldn't be that hard, or possibly just a very specific Shims configuration would work. But until I can get a minimal zigbee2mqtt setup working for development purposes, I can't be sure.

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Sat Jun 13, 2020 9:37 am
by FlyingDiver
What is the purpose of the "yaml" node right after the incoming MQTT node? The payload coming in is a JSON string generated by a custom template in the MQTT Connector plugin, right?

zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Sat Jun 13, 2020 9:40 am
by siclark
It converts the json strong into an object so I can query and manipulate the individual states.

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Sat Jun 13, 2020 9:46 am
by FlyingDiver
siclark wrote:
It converts the json strong into an object so I can query and manipulate the individual states.


Then shouldn't it be the JSON parser node?

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Sat Jun 13, 2020 10:02 am
by siclark
You would have thought wouldn’t you. I tried that first but it didn’t work. The yaml one did so I left it.

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Sat Jun 13, 2020 10:04 am
by FlyingDiver
Can you post some additional topic/payload pairs for devices you're publishing to zigbee2mqtt?

Here's the flow I'm working with to replicate your setup:

Code: Select all
[{"id":"f9d8d924.9ac498","type":"tab","label":"Zigbee bulbs","disabled":false,"info":""},{"id":"be8a3e22.22205","type":"mqtt in","z":"f9d8d924.9ac498","name":"","topic":"indigo/bulbs/#","qos":"0","datatype":"auto","broker":"62088df5.2f09e4","x":150,"y":220,"wires":[["3dbc28a4.c14fb"]]},{"id":"24e32828.6e17e8","type":"switch","z":"f9d8d924.9ac498","name":"","property":"payload.states.blueLevel","propertyType":"msg","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":480,"wires":[["e5a0a4e2.806648"],["57f45746.d8e818"]]},{"id":"57f45746.d8e818","type":"template","z":"f9d8d924.9ac498","name":"color_temp Template","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"state\":\"{{payload.states.onOffState}}\",\n\"brightness\":\"{{payload.states.brightnessLevel}}\",\n\"color_temp\":\"{{payload.states.color_temp}}\"}","output":"str","x":940,"y":520,"wires":[["79d159c.2151228","5c54fd35.f535b4"]]},{"id":"e5a0a4e2.806648","type":"template","z":"f9d8d924.9ac498","name":"RGB Template","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"state\":\"{{payload.states.onOffState}}\",\n\"brightness\":\"{{payload.states.brightnessLevel}}\",\n\"color\":\n{\"r\":\"{{payload.states.redLevel}}\",\n\"g\":\"{{payload.states.greenLevel}}\",\n\"b\":\"{{payload.states.blueLevel}}\"}}","output":"str","x":920,"y":380,"wires":[["538d69ed.de936","5c54fd35.f535b4"]]},{"id":"5922ac6a.8ebb2c","type":"change","z":"f9d8d924.9ac498","name":"","rules":[{"t":"delete","p":"payload.name","pt":"msg"},{"t":"change","p":"payload.states.onOffState","pt":"msg","from":"True","fromt":"str","to":"ON","tot":"str"},{"t":"change","p":"payload.states.onOffState","pt":"msg","from":"False","fromt":"str","to":"OFF","tot":"str"},{"t":"set","p":"payload.states.brightnessLevel","pt":"msg","to":"$number(payload.states.brightnessLevel)","tot":"jsonata"},{"t":"set","p":"payload.states.color_temp","pt":"msg","to":"payload.states[\"whiteTemperature.ui\"]","tot":"msg"},{"t":"set","p":"payload.states.color_temp","pt":"msg","to":"1000000/$number(payload.states.color_temp)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":220,"wires":[["e9b78bcb.94a0f"]]},{"id":"e9b78bcb.94a0f","type":"template","z":"f9d8d924.9ac498","name":"Change Topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"zigbee2mqtt/{{payload.deviceId}}/set/","output":"str","x":540,"y":480,"wires":[["24e32828.6e17e8"]]},{"id":"538d69ed.de936","type":"mqtt out","z":"f9d8d924.9ac498","name":"","topic":"","qos":"0","retain":"false","broker":"62088df5.2f09e4","x":1130,"y":380,"wires":[]},{"id":"79d159c.2151228","type":"mqtt out","z":"f9d8d924.9ac498","name":"","topic":"","qos":"0","retain":"false","broker":"62088df5.2f09e4","x":1130,"y":520,"wires":[]},{"id":"bafd4a46.b76768","type":"range","z":"f9d8d924.9ac498","minin":"0","maxin":"100","minout":"0","maxout":"255","action":"clamp","round":true,"property":"payload.states.brightnessLevel","name":"","x":480,"y":220,"wires":[["5922ac6a.8ebb2c"]]},{"id":"571c6e7e.d09a68","type":"mqtt out","z":"f9d8d924.9ac498","name":"","topic":"indigo/bulbs/626280811/update ","qos":"","retain":"","broker":"62088df5.2f09e4","x":400,"y":140,"wires":[]},{"id":"cdb71963.7f861","type":"inject","z":"f9d8d924.9ac498","name":"","topic":"","payload":"{\"name\": \"DummyBulb\", \"deviceId\": \"626280811\", \"states\": { \"brightnessLevel\": \"61\", \"onOffState\": \"True\" } }","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":140,"wires":[["571c6e7e.d09a68"]]},{"id":"d5f24877.968a48","type":"debug","z":"f9d8d924.9ac498","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":460,"y":280,"wires":[]},{"id":"3dbc28a4.c14fb","type":"json","z":"f9d8d924.9ac498","name":"","property":"payload","action":"","pretty":false,"x":330,"y":220,"wires":[["bafd4a46.b76768","d5f24877.968a48"]]},{"id":"5c54fd35.f535b4","type":"debug","z":"f9d8d924.9ac498","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1120,"y":460,"wires":[]},{"id":"62088df5.2f09e4","type":"mqtt-broker","z":"","name":"Synology","broker":"192.168.111.20","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""}]

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Sat Jun 13, 2020 10:28 am
by siclark
The setup is RGB devices In indigo using the SDK for example devices using either RGB and colour temp or just white levels and white colour temp

To zigbee2mqtt I’m sending state, brightness, rgb levels and colour temp as per the
https://www.zigbee2mqtt.io/information/mqtt_topics_and_message_structure.html
On the zigbee2mqtt/friendly_name/set section.

The bit I was confused with was if bulb was on colour mode ie red then colour temp changed how to ensure that was sent rather than previous rgb levels.

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Sat Jun 13, 2020 11:54 am
by FlyingDiver
Let me make sure I have this exactly right. I'm trying to figure out if this can be done using the Shims plugin, possibly with some enhancements, so you don't need the node-red flow for MQTT for message translation.

  1. Create "dummy" devices using the "Example Device - Relay/Dimmer" plugin. These are your controls for the actual Hue bulbs.
  2. Publish these devices using the MQTT Connector plugin, using a somewhat customized payload and topic teemplates.
  3. The topics for the published devices are subscribed to in the node-red flow, the topic and payload are re-written there, then re-published.
  4. zigbee2mqtt running on some device (Mac, rPi, etc) receives these MQTT messages and sends commands via the ZigBee stick to actually control the bulbs.

I don't see any way in this scenario that status reports coming back from the bulb could effect your "dummy" devices, so this is one-way only. Correct?

I have a (different) Zigbee stick on order. When I get it I'll try getting zigbee2mqtt set up again and see if I can figure out a way to do this all in the MQTT Shims plugin. I'll probably have to add some code to enable the value scaling you're doing in the flow. I'm pretty sure you can do on/off commands with it as-is.

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Sat Jun 13, 2020 12:11 pm
by siclark
Correct to the flow.

Correct to the one way status. I discussed with Nathan but he queries the hue hub not the bulbs.

It appears that hue bulbs don’t report their status, but Ikea and some other bulbs do.

Per here. https://www.zigbee2mqtt.io/information/report.html

I’m ordering some Ikea mains sockets to work as boosters so might through in a bulb as well to test.

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Sun Jun 14, 2020 9:48 am
by FlyingDiver
Can you try something for me? Create an MQTT Shims device using this template, with the unique ID value the same as one of your Hue bulbs (like you use in the node-red flow).
More info on using templates here: viewtopic.php?f=316&t=23656
Don't worry about a trigger, you don't need it for this test.
Does it control the bulb? On, Off, setBrightness?

Code: Select all
message_type: hue-dimmer
type: shimDimmer
props:
    SupportsBatteryLevel: false
    SupportsEnergyMeter: false
    SupportsEnergyMeterCurPower: false
    SupportsOnState: false
    SupportsSensorValue: true
    SupportsStatusRequest: false
    action_template: zigbee2mqtt/{{uniqueID}}/set/state
    dimmer_action_payload: '{"state": "ON", "brightness": {{brightness}} }'
    dimmer_action_template: zigbee2mqtt/{{uniqueID}}/set
    off_action_payload: 'OFF'
    on_action_payload: 'ON'
    state_location: payload
    state_location_payload_key: state
    state_location_payload_type: json
    state_location_topic_field: '0'
    status_action_template: cmnd/{{uniqueID}}/Status
    uid_location: topic
    uid_location_topic_field: '1'
    value_location_payload_key: brightness

Re: zigbee2mqtt & zigbee USB for Hue bulbs

PostPosted: Sun Jun 14, 2020 10:27 am
by FlyingDiver
Tweaked this a little more. Here's a template for a dimmer and a switch. I'm going to have to add color devices to the Shims plugin for the next step.

Code: Select all
type: shimDimmer
message_type: zigbee2mqtt
props:
    SupportsBatteryLevel: false
    SupportsEnergyMeter: false
    SupportsEnergyMeterCurPower: false
    SupportsOnState: false
    SupportsSensorValue: true
    SupportsStatusRequest: true
    action_template: zigbee2mqtt/{{uniqueID}}/set
    dimmer_action_payload: '{"state": "ON", "brightness": {{brightness}} }'
    dimmer_action_template: zigbee2mqtt/{{uniqueID}}/set
    off_action_payload: '{"state": "OFF"}'
    on_action_payload: '{"state": "ON"}'
    state_location: payload
    state_location_payload_key: state
    state_location_payload_type: json
    state_location_topic_field: '0'
    status_action_payload: '{"state": ""}'
    status_action_template: zigbee2mqtt/{{uniqueID}}/get
    uid_location: topic
    uid_location_topic_field: '1'
    value_location_payload_key: brightness
trigger:
    match_list: '["Match: zigbee2mqtt", "Any: ", "End: "]'
    queueMessage: true
[code]

[/code]
type: shimRelay
message_type: zigbee2mqtt
props:
    SupportsBatteryLevel: false
    SupportsEnergyMeter: false
    SupportsEnergyMeterCurPower: false
    SupportsOnState: false
    SupportsSensorValue: true
    SupportsStatusRequest: true
    action_template: zigbee2mqtt/{{uniqueID}}/set
    dimmer_action_payload: '{"state": "ON", "brightness": {{brightness}} }'
    dimmer_action_template: zigbee2mqtt/{{uniqueID}}/set
    off_action_payload: '{"state": "OFF"}'
    on_action_payload: '{"state": "ON"}'
    shimSensorSubtype: Generic
    state_location: payload
    state_location_payload_key: state
    state_location_payload_type: json
    state_location_topic_field: '0'
    status_action_payload: '{"state": ""}'
    status_action_template: zigbee2mqtt/{{uniqueID}}/get
    uid_location: topic
    uid_location_topic_field: '1'
    value_location_payload_key: brightness
trigger:
    match_list: '["Match: zigbee2mqtt", "Any: ", "End: "]'
    queueMessage: true