# Zigbee2mqtt to Domoticz flow help

**URL:** <https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453>\
**Category:** General\
**Created:** [16 January 2020 13:39 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453 "2020-01-16T13:39:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [16 January 2020 13:39 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/1 "2020-01-16T13:39:42Z")

</div>

Hi, (newbie in node-red)

I have created a node-red flow from Domoticz/out to Zigbee2mqtt/in which does the following:  
When I turn on/off a virtual switch in Domoticz, a command is send to Zigbee2mqtt which sets a group of ikea GU10 bulbs in a certain state. This is working.

However the zigbee2mqtt group is also bound to a physical ikea dimmer remote.  
Now if I change the state of the group with the remote to e.g. ON/OFF (which is a toggle button), the virtual switch in Domoticz doesn't know that the group state is changed to ON/OFF.

So I need to create a flow from Zigbee2mqtt/out to Domoticz/in to get the current state of the group or one of the devices in it and set the Domoticz virtual switch accordingly to the same state (e.g. ON/OFF) .

Should this be a separate flow or is it possible to combine this with the first flow?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [16 January 2020 15:04 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/2 "2020-01-16T15:04:48Z")

</div>

I thought Domoticz could control those groups directly ? It is home automation software with mqtt support.

Although this doesn't help you with your flow, my tip would be to keep it as simple as possible. The more software in between the more potential problems. (note - i have all my home-automation in node-red only, including states and interface(s))

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [17 January 2020 13:05 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/3 "2020-01-17T13:05:49Z")

</div>

Nope sadly not for zigbee2mqtt groups.. 😢

However, if you do everything with node-red i have some questions because my javascript skills (from scratch) are bad. I can read scripts and with trial and error i'll manage, but i don't have good examples

**How would my flow and javascript function look like when I want to**  
Get the state of a zigbee2mqtt bulb and set the virtual switch in Domoticz to the same state:

1. add an mqtt object to the flow (zigbee2mqtt location and login credentials)  
and set the topic _ **zigbee2mqtt/Keuken\_Spot1/get/state** _  
which should return something like this (can i check this in node red?)  
_ **{"state": "OFF", "brightness": 200, "color\_temp": 350}.** _

2. add a JSON obect to the flow

3. add a Function to the flow (The javascript funtion must execute something like this:)  
If the **"state": "OFF"**  
Then set the **nvalue** of the virtual domoticz switch (idx=183) to "0"  
And If the **"state": "ON"**  
Then set the **nvalue** of the virtual domoticz switch (idx=183) to "1"

4. Add an mqtt object to the flow (domoticz location and login credentials)  
and set the topic to **domoticz/in**

5. Connect the objects from 1 to 4 and deploy

(this flow is needed when I turn on the group of bulbs with the remote instead of the virtual switch)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [17 January 2020 13:51 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/4 "2020-01-17T13:51:35Z")

</div>

I have some ideas, but could you elaborate on:

> Get the state of a zigbee2mqtt bulb and set the virtual switch in Domoticz to the same state

_When_ do you need to get this state ?

Is it only in this situation ?:

> when I turn on the group of bulbs with the remote instead of the virtual switc

and do you receive information from that virtual switch as well ?

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [17 January 2020 14:30 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/5 "2020-01-17T14:30:19Z")

</div>

> [@bakman2](#):
>
> _When_ do you need to get this state ?

Every time the group of spots is turned on/off with the remote instead of the Domoticz virtual switch.

> [@bakman2](#):
>
> and do you receive information from that virtual switch as well ?

Yes, but since it is a normal switch only ON/OFF information i guess?  
I already have a working flow which turns on/off the zigbee2mqtt group of bulbs when the Domoticz virtual switch is turned on/off. I based this flow on an existing example on the domoticz forum.

But I also need a flow (the one I am asking your help for) which tells the virtual switch, that the group is turned on/off with the remote so that the ON / OFF state is set equal to the actions that the remote does

The problem is that zigbee2mqtt can't send commands to the IKEA remote (apparently a limitation of the remote 😢) the buttons only act as a sensor.

(I also use google home voice commands to turn on/off the virtual switch, but my wife is always using the remote 😜)

I am now at work, but I will send the flow I already have this weekend

Thanx for helping anyway 👍

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [18 January 2020 07:51 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/6 "2020-01-18T07:51:09Z")

</div>

```auto
[{"id":"56035fe2.21c4e8","type":"tab","label":"Keuken_Licht","disabled":false,"info":""},{"id":"17b6b703.ebe381","type":"mqtt in","z":"56035fe2.21c4e8","name":"","topic":"domoticz/out","qos":"2","datatype":"auto","broker":"b90f182d.2e6838","x":413.5,"y":215,"wires":[["452631d0.ef45a8"]]},{"id":"52d623f.852d35c","type":"comment","z":"56035fe2.21c4e8","name":"Domoticz Switch for Kitchen Light Group","info":"","x":165,"y":215,"wires":[]},{"id":"452631d0.ef45a8","type":"json","z":"56035fe2.21c4e8","name":"","property":"payload","action":"","pretty":false,"x":567.5000305175781,"y":215,"wires":[["96dc8119.c7418"]]},{"id":"96dc8119.c7418","type":"function","z":"56035fe2.21c4e8","name":"Turn On/Off Z2M Group","func":"if(msg.payload.idx == '183') {\nif(msg.payload.nvalue == '0') {\n msg.payload.state = 'OFF'\n}\nif(msg.payload.nvalue == '1') {\n msg.payload.state = 'ON',\n msg.payload.brightness = 200,\n msg.payload.color_temp = 350\n}\nreturn msg;\n}","outputs":1,"noerr":0,"x":768.7713623046875,"y":215.00000381469727,"wires":[["5eba5b0b.72b304"]]},{"id":"5eba5b0b.72b304","type":"mqtt out","z":"56035fe2.21c4e8","name":"zigbee2mqtt/in","topic":"zigbee2mqtt/Keuken_Spots/set","qos":"","retain":"","broker":"1ec43ef1.2b0269","x":1010.8785247802734,"y":216.3785514831543,"wires":[]},{"id":"b90f182d.2e6838","type":"mqtt-broker","z":"","name":"Domoticz","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"1ec43ef1.2b0269","type":"mqtt-broker","z":"","name":"Zigbee2mqtt","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"domoticz/bridge/state","birthQos":"0","birthPayload":"online","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 January 2020 09:49 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/7 "2020-01-18T09:49:54Z")

</div>

Please export your flow again, [read this post](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506) and edit your post.

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [18 January 2020 10:49 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/8 "2020-01-18T10:49:52Z")

</div>

It is different then described in the link.  
I first had to select the preformatted text format button and then paste the code inside.

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [18 January 2020 10:58 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/9 "2020-01-18T10:58:18Z")

</div>

This is the flow I was trying but functiondoes not work.  
I need some examples how I get the information (variables) of the mqtt topic and then use them in a function

```auto
[{"id":"35e7b173.9567ee","type":"function","z":"80f07896.7cae2","name":"Set Virtual Switch State equal to Group State","func":"if(msg.payload.state == 'OFF')\n{\n if(msg.payload.idx == '183') {msg.payload.state = '0'}\n return msg;\n}\n\nif(msg.payload.state == 'ON')\n{\n if(msg.payload.idx == '183') {msg.payload.state = '1'}\n return msg;\n}","outputs":1,"noerr":0,"x":536.7666320800781,"y":412.23333740234375,"wires":[["b83a6cfb.4910a"]]}]

```

I actually want to get the state of the zigbee2mqtt group, but that is not possible with zigbee2mqtt therefor I get the state of of one of the group members

[Edit] This flow maybe already OK, but to run it, it needs to be triggered if one of the Remote Buttons is used. The remote has 5 buttons but only 3 are recognized by zigbee2mqtt when paired (known issue).  
when I subscribe to mqtt topic **zigbee2mqtt/Remote\_E1524-E1810**  
And I press the buttons the following JSON the following messages are send to the topic:

```auto
{"linkquality" : 31, "battery" : 74, "action" : "toggle"} = Toggle ON/OFF button
{"linkquality" : 36, "battery" : 74, "action" : "brightness_up_click"}
{"linkquality" : 36, "battery" : 74, "action" : "brightness_up_hold"}
{"linkquality" : 36, "battery" : 74, "action" : "brightness_up_release"}
{"linkquality" : 36, "battery" : 74, "action" : "brightness_down_click"}
{"linkquality" : 36, "battery" : 74, "action" : "brightness_down_hold"}
{"linkquality" : 36, "battery" : 74, "action" : "brightness_down_release"}
{"linkquality" : 39, "battery" : 47, "action" : "arrow_right_click"}
{"linkquality" : 39, "battery" : 47, "action" : "arrow_right_hold"}
{"linkquality" : 39, "battery" : 47, "action" : "arrow_right_release"}
{"linkquality" : 39, "battery" : 47, "action" : "arrow_left_click"}
{"linkquality" : 39, "battery" : 47, "action" : "arrow_left_hold"}
{"linkquality" : 39, "battery" : 47, "action" : "arrow_left_release"}

```

Both brightness and toggle commands of the remote trigger the group of bulbs

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 January 2020 17:10 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/10 "2020-01-18T17:10:52Z")

</div>

1. you have a physical remote that produces mqtt messages, the `toggle` does not state on/off, only toggle ?
2. you have a "virtual switch" in Domoticz which produces ON/OFF ?

Your goal is to have them in sync ?  
If domo is ON and physical remote is toggled, the virtual switch needs to turn OFF ?

To keep track the state you can work with context.

I am missing the complete picture in your topic. I see some JSON, some part of a flow, some function node.  
Describe the flow in simple terms with the json output of each part.

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [18 January 2020 18:16 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/11 "2020-01-18T18:16:43Z")

</div>

> [@bakman2](#):
>
> - you have a physical remote that produces mqtt messages, the `toggle` does not state on/off, only toggle ?
> - you have a "virtual switch" in Domoticz which produces ON/OFF ?

Yes and yes

> [@bakman2](#):
>
> Your goal is to have them in sync ?  
> If domo is ON and physical remote is toggled, the virtual switch needs to turn OFF ?

Yes,  
And how is the other way around handled: If physical remote toggles group ON, the virtual switch also should to be turned ON to stay in sync, but then there are 2 commands that wants to turn ON the group?

> [@bakman2](#):
>
> To keep track the state you can work with context.

Where and how do I use context?

> [@bakman2](#):
>
> I am missing the complete picture in your topic. I see some JSON, some part of a flow, some function node.  
> Describe the flow in simple terms with the json output of each part.

This is why I ask help, I don't know exactly where and how to start.  
I have a working flow that turns on/off a group of bulbs when a virtual switch is set to on/off, thats basically it. But implementing physical remote and virtual switch in sync is much more compicated.

I even don't know if both ations can be combined in 1 flow or in separate flows, and how to do this?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 January 2020 18:50 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/12 "2020-01-18T18:50:42Z")

</div>

What is the output from domoticz, the virtual switch (mqtt in -\> debug - complete msg object)  
Output from the physical switch (mqtt in -\> debug - complete msg object)  
What is the expected input towards domoticz ?

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [19 January 2020 08:41 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/13 "2020-01-19T08:41:21Z")

</div>

Hi,

I am not sure of this is a debugged output, but here you go!

**Virtual Switch (Domoticz):**  
In Domoticz I have installed _MQTT Client Gateway with LAN Interface_ plugin to communicate with the mqtt server. The default "Publish Topic" setting of the plugin is domoticz/out (and domoticz/in)

Publish Topic: domoticz/out

```auto
{"Battery":255,"RSSI":12,"description":"","dtype":"Lighting 1","id":"73","idx":183,"name":"Keuken Licht","nvalue":0,"stype":"X10","switchType":"On/Off","unit":14,"state":"OFF"}

```

**Physical Remote (Zigbee2mqtt):**

Publish Topic: zigbee2mqtt/Remote\_E1524-E1810

```auto
{"linkquality":42,"battery":47,"action":"toggle"}

```

**Remote\_E1524-E1810 as a Sensor device (Domoticz) :**  
In Domoticz I also installed a _zigbee2mqtt-domoticz_ plugin which discovers the zigbee2mqtt devices and turns them into Domoticz devices. The Remote\_E1524-E1810 is integrated here as a sensor. Therefor when the physical remote toggle button is pressed, domoticz/out is also sending an output of the remote device.

Publish Topic: domoticz/out

```auto
{"Battery" : 47, "RSSI" : 1, "description" : "", "dtype" : "Light/Switch", "id" : "0x000d6ffffe5e7ec7_switch", "idx" : 261, "name" : "Remote_E1524-E1810", "nvalue" : 0, "stype" : "Switch", "svalue1" : "Off", "switchType" : "On/Off", "unit" : 10}

```

**LOG File of (Zigbee2)MQTT:**  
Here the LOG file (with debug info) produced by the mqtt server after restart and setting both remote and virtual switch to ON and OFF.  
[log.txt](https://discourse.nodered.org/uploads/short-url/c0DIeBgUqDGWtFNhB3br9nge91q.txt) (8.8 KB)

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [19 January 2020 09:20 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/14 "2020-01-19T09:20:52Z")

</div>

> [@bakman2](#):
>
> What is the expected input towards domoticz ?

If the remote toggle button is used, the virtual switch in domoticz must sync ON/OFF with the remote (topic: domoticz/in)  
If the Virtual Switch is used the remote must sync ON/OFF with the virtual switch.(topic: domoticz/out)

But the remote can not set/get ON/OFF information because it acts as a sensor (toggle button), therefor the **zigbee2mqtt group state** \* info must be used to get the ON/OFF infomation.

\*Get group state is not a function in zigbee2mqtt, therefor one of the devices in the group is used to get the ON/OFF info.  
topic: _zigbee2mqtt/Keuken\_Spot1/get/state_

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [24 January 2020 06:15 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/15 "2020-01-24T06:15:58Z")

</div>

And then?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [24 January 2020 17:24 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/16 "2020-01-24T17:24:21Z")

</div>

Sorry for the delay.  
And then....it is still confusing.

You can get the status from the topic: `zigbee2mqtt/Keuken_Spot1/get/state` ? so that would be the single truth of the current status whether or not the virtual switch/group is on or ff ?

is it not easier to move the controls to node-red only ? you can update the virtual switch from node-red

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [26 January 2020 09:10 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/17 "2020-01-26T09:10:41Z")

</div>

> [@bakman2](#):
>
> You can get the status from the topic: `zigbee2mqtt/Keuken_Spot1/get/state` ? so that would be the single truth of the current status whether or not the virtual switch/group is on or ff ?

Yes, because not only the virtual switch but also  
the (toggle) remote can change the state of the Zigbee2mqtt group.  
The remote has no On/Off status but only a toggle, therefor I can’t use it to get the status of the group.

> [@bakman2](#):
>
> is it not easier to move the controls to node-red only ? you can update the virtual switch from node-red

This is what I am trying to achieve.

I already figured out that with an injection node I can get the status of `zigbee2mqtt/Keuken_Spot1/get/state`  
but this injection node needs to be triggered by a toggle action of the remote, which can change the group state too.  
So I want to achieve that:

If remote button (toggle) is used  
Then `zigbee2mqtt/Keuken_Spot1/get/state`  
If state = on  
Then set virtual switch on  
Else virtual switch = off

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [26 January 2020 11:21 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/18 "2020-01-26T11:21:29Z")

</div>

Check this flow.  
The key is to store the state of the "keuken\_spot" into a context variable.

The toggle inject will check the context state and change it to on/off (if on then off, if off then on).

```auto
[{"id":"4ed0283c.0c14d8","type":"inject","z":"9a68d73d.80d63","name":"","topic":"","payload":"toggle","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":122,"y":96,"wires":[["a815f7d7.b0d2d8"]]},{"id":"9329a5dc.7c4a78","type":"mqtt in","z":"9a68d73d.80d63","name":"","topic":"zigbee2mqtt/Keuken_Spot1/get/state","qos":"0","datatype":"json","broker":"228872c0.fd94d6","x":198,"y":168,"wires":[["b99004e9.4c27e"]]},{"id":"b99004e9.4c27e","type":"change","z":"9a68d73d.80d63","name":"","rules":[{"t":"set","p":"light_state","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":474,"y":168,"wires":[[]]},{"id":"397b4971.eabf7e","type":"mqtt out","z":"9a68d73d.80d63","name":"","topic":"zigbee2mqtt/Keuken_Spot1/get/state","qos":"","retain":"","broker":"228872c0.fd94d6","x":438,"y":408,"wires":[]},{"id":"492f688e.13375","type":"inject","z":"9a68d73d.80d63","name":"Spot state ON","topic":"","payload":"{\"state\": \"ON\", \"brightness\": 200, \"color_temp\": 350}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":142,"y":384,"wires":[["397b4971.eabf7e"]]},{"id":"a815f7d7.b0d2d8","type":"change","z":"9a68d73d.80d63","name":"Toggle on/off","rules":[{"t":"set","p":"payload","pt":"msg","to":"$flowContext(\"light_state.state\") =\"OFF\" ? \"ON\" : \"OFF\" \t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":262,"y":96,"wires":[["fb58b972.c98e6"]]},{"id":"fb58b972.c98e6","type":"debug","z":"9a68d73d.80d63","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":430,"y":96,"wires":[]},{"id":"b8688af1.bf5a18","type":"inject","z":"9a68d73d.80d63","name":"Spot state OFF","topic":"","payload":"{\"state\": \"OFF\", \"brightness\": 200, \"color_temp\": 350}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":152,"y":432,"wires":[["397b4971.eabf7e"]]},{"id":"e163737f.109a78","type":"comment","z":"9a68d73d.80d63","name":"Ignore - emulation only","info":"","x":148,"y":336,"wires":[]},{"id":"228872c0.fd94d6","type":"mqtt-broker","z":"","name":"mqtt","broker":"10.0.0.6","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"connections","birthQos":"0","birthRetain":"false","birthPayload":"connected","closeTopic":"connections","closeQos":"0","closeRetain":"false","closePayload":"disconnected","willTopic":"connections","willQos":"0","willRetain":"false","willPayload":"disconnected"}]

```

This flow assumes this payload from the keuken spot (on/off):

`{"state": "ON", "brightness": 200, "color_temp": 350}`

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [26 January 2020 13:22 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/19 "2020-01-26T13:22:37Z")

</div>

Thanx for the flow, I tested it but ran into some problems because it didn't work

when a `zigbee2mqtt/Keuken_Spot1/get/state` is published, `zigbee2mqtt/Keuken_Spot1` will get the output. (group `zigbee2mqtt/Keuken_Spots` can also be used to subscribe to)

`zigbee2mqtt/Keuken_Spot1/get/state` or `zigbee2mqtt/Keuken_Spot1/get` both return this json string `{"state": "ON", "brightness": 200, "color_temp": 350}`  
Not "ON" or "OFF" which you may have expected.

As a result "set flow.light\_state" change node returns  
{"state":"OFF","brightness":200,"color\_temp":350}  
instead of ON or OFF

So the JSON string should be splitted up with some code in order to get ON or OFF I guess?  
Where and how is that done?  
I modified the flow to the correct topics:

```auto
[{"id":"4ff533af.0e6fbc","type":"inject","z":"f7ed534b.a4e54","name":"","topic":"","payload":"toggle","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":409.8833312988281,"y":195.88333129882812,"wires":[["a9174dcd.63141"]]},{"id":"9799f8fa.a0d96","type":"mqtt in","z":"f7ed534b.a4e54","name":"","topic":"zigbee2mqtt/Keuken_Spots","qos":"0","datatype":"json","broker":"1ec43ef1.2b0269","x":455.8833312988281,"y":267.8833312988281,"wires":[["5d19ba20.7f0cbc"]]},{"id":"5d19ba20.7f0cbc","type":"change","z":"f7ed534b.a4e54","name":"","rules":[{"t":"set","p":"light_state","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":761.8833312988281,"y":267.8833312988281,"wires":[["d0d45c46.1b2a98"]]},{"id":"49f621ee.a07268","type":"mqtt out","z":"f7ed534b.a4e54","name":"","topic":"zigbee2mqtt/Keuken_Spot1/get/state","qos":"","retain":"","broker":"1ec43ef1.2b0269","x":725.8833312988281,"y":507.8833312988281,"wires":[]},{"id":"fccc5630.5a0ef8","type":"inject","z":"f7ed534b.a4e54","name":"zigbee2mqtt/Keuken_Spot1/get/state","topic":"zigbee2mqtt/Keuken_Spot1/get/state","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":333.8833312988281,"y":507.8833312988281,"wires":[["49f621ee.a07268"]]},{"id":"a9174dcd.63141","type":"change","z":"f7ed534b.a4e54","name":"Toggle on/off","rules":[{"t":"set","p":"payload","pt":"msg","to":"$flowContext(\"light_state.state\") =\"OFF\" ? \"ON\" : \"OFF\" \t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":549.8833312988281,"y":195.88333129882812,"wires":[["c2639e15.36732"]]},{"id":"c2639e15.36732","type":"debug","z":"f7ed534b.a4e54","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":717.8833312988281,"y":195.88333129882812,"wires":[]},{"id":"f19a96d6.52b75","type":"comment","z":"f7ed534b.a4e54","name":"Ignore - emulation only","info":"","x":435.8833312988281,"y":435.8833312988281,"wires":[]},{"id":"d0d45c46.1b2a98","type":"debug","z":"f7ed534b.a4e54","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":962.2666015625,"y":267.4499816894531,"wires":[]},{"id":"1ec43ef1.2b0269","type":"mqtt-broker","z":"","name":"Zigbee2mqtt","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"domoticz/bridge/state","birthQos":"0","birthPayload":"online","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![Dylantje](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dylantje/32/16492_2.png) [@Dylantje](https://discourse.nodered.org/u/Dylantje)\
**Post date:** [26 January 2020 13:23 UTC](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453/20 "2020-01-26T13:23:55Z")

</div>

Dombo71 here....

First flows with NR and i work with Domoticz....

```auto
[{"id":"976d0acd.c2c738","type":"mqtt in","z":"ac795f5f.c3495","name":"","topic":"domoticz/out","qos":"2","datatype":"auto","broker":"734a852b.3ac33c","x":410,"y":160,"wires":[["1b904ebd.d592c1"]]},{"id":"1b904ebd.d592c1","type":"json","z":"ac795f5f.c3495","name":"","property":"payload","action":"","pretty":false,"x":567.5000305175781,"y":215,"wires":[["a44861ee.30264"]]},{"id":"a44861ee.30264","type":"function","z":"ac795f5f.c3495","name":"Ikea tussenstekker1","func":"if(msg.payload.idx == '12984') {\nif(msg.payload.nvalue == '0') {\n msg.payload.state = 'OFF'\n}\nif(msg.payload.nvalue == '1') {\n msg.payload.state = 'ON'\n // msg.payload.brightness = 200,\n //msg.payload.color_temp = 350\n}\nreturn msg;\n}","outputs":1,"noerr":0,"x":758.7713623046875,"y":215.00000381469727,"wires":[["53df0851.f5b228"]]},{"id":"53df0851.f5b228","type":"mqtt out","z":"ac795f5f.c3495","name":"domoticz/in","topic":"zigbee2mqtt/Ik: Tustek-1","qos":"1","retain":"true","broker":"734a852b.3ac33c","x":990,"y":200,"wires":[]},{"id":"734a852b.3ac33c","type":"mqtt-broker","z":"","name":"Domoticz mqtt","broker":"192.168.5.70","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"15","cleansession":true,"birthTopic":"Domoticz","birthQos":"2","birthRetain":"true","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

Will try just a simple on off device from ikea switching in Domoticz  
And perhaps possible te other value from a sensor..

Only this flow is not working...?  
Do someone have perhaps some noce flows that are working in Domoticz as an example.[so i can build from that one]

[Next page](https://discourse.nodered.org/t/zigbee2mqtt-to-domoticz-flow-help/20453.md?page=2)
