# Google, node-red-contrib-googlehome set level

**URL:** https://discourse.nodered.org/t/google-node-red-contrib-googlehome-set-level/42620
**Category:** General
**Created:** [14 March 2021 14:21 UTC](https://discourse.nodered.org/t/google-node-red-contrib-googlehome-set-level/42620 "2021-03-14T14:21:08Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![bce](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@bce](https://discourse.nodered.org/u/bce)
#### Post date: [14 March 2021 14:21 UTC](https://discourse.nodered.org/t/google-node-red-contrib-googlehome-set-level/42620/1 "2021-03-14T14:21:08Z")

</div>

Good afternoon.  
I try to create via node-red-contrib-googlehome, Level set function for domoticz.  
For this I created an account with [[Node-RED Google Assistant Bridge](https://googlehome.hardill.me.uk/login).  
I added it to my google home, and added a device.  
Now I have managed to give a, on and off command, but dimming is not possible. I can't created the right command. I added the flow. I have a raspberry 4, I run on docker/docker compose

```auto
[{"id":"34e77087.0485d","type":"google-home","z":"753ec312.e5c01c","conf":"73171d30.8abbf4","device":"10241","acknowledge":true,"name":"keuken links","topic":".idx.4","x":130,"y":400,"wires":[["f1794ef8.4343c"]]},{"id":"df5a008a.babad","type":"link out","z":"753ec312.e5c01c","name":"","links":["28dd7675.a7986a"],"x":895,"y":520,"wires":[]},{"id":"c9fc8cbe.afe96","type":"template","z":"753ec312.e5c01c","name":"","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\"command\":\"switchlight\",\"idx\":64,\"switchcmd\": \"{{{payload}}}\" };","output":"str","x":660,"y":620,"wires":[["df5a008a.babad"]]},{"id":"112270b8.7db2ef","type":"change","z":"753ec312.e5c01c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"On","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":340,"wires":[["67cb33bd.1ae27c"]]},{"id":"257688d1.c1bcb8","type":"change","z":"753ec312.e5c01c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":640,"wires":[["2e98c7dd.7c0f58","c9fc8cbe.afe96"]]},{"id":"2e98c7dd.7c0f58","type":"debug","z":"753ec312.e5c01c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":700,"wires":[]},{"id":"56f5e63e.956618","type":"switch","z":"753ec312.e5c01c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"true","vt":"str"},{"t":"neq","v":"","vt":"prev"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":380,"wires":[["112270b8.7db2ef"],["da854be4.26b0b8"]]},{"id":"67cb33bd.1ae27c","type":"debug","z":"753ec312.e5c01c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":320,"wires":[]},{"id":"aa403066.3c881","type":"debug","z":"753ec312.e5c01c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":970,"y":400,"wires":[]},{"id":"da854be4.26b0b8","type":"function","z":"753ec312.e5c01c","name":"Function out Dimmer","func":"\nvar brightness = msg.payload\nif ( msg.payload === 0 )\n{\nmsg.payload = { \"command\": \"switchlight\", \"idx\": 64, \"switchcmd\": \"Off\" };\nreturn [msg, null]\n}\nelse\n{\nmsg.payload = { \"command\": \"switchlight\", \"idx\": 64, \"switchcmd\": \"Set Level\", \"level\": brightness };\nreturn [null, msg]\n}\n\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":740,"y":400,"wires":[["df5a008a.babad"],["aa403066.3c881","df5a008a.babad"]]},{"id":"f1794ef8.4343c","type":"function","z":"753ec312.e5c01c","name":"","func":"\nif (msg.payload.command == \"action.devices.commands.OnOff\") {\n if (msg.payload.params.on) {\n msg.payload = true;\n return [msg,null];\n } else {\n msg.payload = false;\n return [null,msg];\n }\n} else {\n //brightness\n var brightness = Math.round(100 * (msg.payload.params.brightness / 100));\n msg.payload = { brightness\n }\n return [msg,null];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","x":320,"y":400,"wires":[["56f5e63e.956618"],["257688d1.c1bcb8"]]},{"id":"73171d30.8abbf4","type":"google-home-conf","username":"bce626"}]

```

log output

```auto
{"command":"switchlight","idx":64,"switchcmd":"Set Level","level":{"brightness":53}}

```

instead of what is needed for the trigger to take place

```auto
{"command":"switchlight","idx":64,"switchcmd":"Set Level","level":{53}}

```

thank you in advance for all the help.  
this post was created with online translate

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [14 March 2021 15:15 UTC](https://discourse.nodered.org/t/google-node-red-contrib-googlehome-set-level/42620/2 "2021-03-14T15:15:46Z")

</div>

> [@bce](#):
>
> I added the flow

The top flow that you pasted above is just a debug node.... no other flow components.

---

<div class="post-metadata">

### Author: ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)
#### Post date: [14 March 2021 15:50 UTC](https://discourse.nodered.org/t/google-node-red-contrib-googlehome-set-level/42620/3 "2021-03-14T15:50:23Z")

</div>

Hello bce,

According to Domoticz WIKI ([MQTT - Domoticz](https://www.domoticz.com/wiki/MQTT)), the command should be:

```auto
{"command": "switchlight", "idx": 64, "switchcmd": "Set Level", "level": 53}

```

So without the { }.

Can you try that?

Regards

---

<div class="post-metadata">

### Author: ![bce](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@bce](https://discourse.nodered.org/u/bce)
#### Post date: [14 March 2021 18:24 UTC](https://discourse.nodered.org/t/google-node-red-contrib-googlehome-set-level/42620/4 "2021-03-14T18:24:18Z")

</div>

good evening FireWizard52,

thank you voor the respons, this will work.  
only will this set the lights to 53%, and not the command i gif to google. like, oke google set light to 25 %. the outputt will be 53% and not 25%

---

<div class="post-metadata">

### Author: ![bce](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@bce](https://discourse.nodered.org/u/bce)
#### Post date: [14 March 2021 18:31 UTC](https://discourse.nodered.org/t/google-node-red-contrib-googlehome-set-level/42620/5 "2021-03-14T18:31:16Z")

</div>

thank you Paul-Reed

I added the other components.  
😅

---

<div class="post-metadata">

### Author: ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)
#### Post date: [14 March 2021 21:20 UTC](https://discourse.nodered.org/t/google-node-red-contrib-googlehome-set-level/42620/6 "2021-03-14T21:20:38Z")

</div>

> only will this set the lights to 53%, and not the command i gif to google. like, oke google set light to 25 %. the outputt will be 53% and not 25%

This is correct, as the command contains a fixed value for the level, in this case 53, but that was your own proposal 🙂  
This value should be replaced by the brightness variable, you receive from Google Home.

I cannot follow or test your flow completely, as I do not use this device.

However, if I look to the first "Function" node, I see something as:

> } else {  
> //brightness  
> var brightness = Math.round(100 \* (msg.payload.params.brightness / 100));  
> msg.payload = { brightness  
> }  
> return [msg,null];

I don't think that is correct.

This probably has to be: msg.payload = brightness

or something like:  
msg.payload = {"brightness":brightness}

In this case, you have to change the line:

> msg.payload = { "command": "switchlight", "idx": 64, "switchcmd": "Set Level", "level": brightness };

in the Function, called "Function out Dimmer" into::

```auto
msg.payload = { "command": "switchlight", "idx": 64, "switchcmd": "Set Level", "level": msg.payload};

```

or (second example)

```auto
msg.payload = { "command": "switchlight", "idx": 64, "switchcmd": "Set Level", "level": msg.payload.brightness};

```

I have not been able to test this code, but you can try.

Regards

---

<div class="post-metadata">

### Author: ![bce](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@bce](https://discourse.nodered.org/u/bce)
#### Post date: [15 March 2021 05:23 UTC](https://discourse.nodered.org/t/google-node-red-contrib-googlehome-set-level/42620/7 "2021-03-15T05:23:54Z")

</div>

good morning FireWizard52,

> _This is correct, as the command contains a fixed value for the level, in this case 53, but that was your own proposal_

hahahaha wrong way of asking a questions. 😃

Thank you for helping, I'm going to try this tonight.

---

<div class="post-metadata">

### Author: ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)
#### Post date: [15 March 2021 14:05 UTC](https://discourse.nodered.org/t/google-node-red-contrib-googlehome-set-level/42620/8 "2021-03-15T14:05:38Z")

</div>

A little warning.

I noticed in your first node (Google Assistants), that a topic has been set as : .idx.4  
So the topic start with a dot. Perhaps your system but quite unusual.

---

<div class="post-metadata">

### Author: ![bce](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@bce](https://discourse.nodered.org/u/bce)
#### Post date: [15 March 2021 16:51 UTC](https://discourse.nodered.org/t/google-node-red-contrib-googlehome-set-level/42620/9 "2021-03-15T16:51:45Z")

</div>

thank you  
`msg.payload = brightness`  
and

```auto
msg.payload = { "command": "switchlight", "idx": 64, "switchcmd": "Set Level", "level": brightness };

```

did the trick  
That I didn't see that.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [29 March 2021 16:51 UTC](https://discourse.nodered.org/t/google-node-red-contrib-googlehome-set-level/42620/10 "2021-03-29T16:51:52Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
