Google, node-red-contrib-googlehome set level

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.
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

[{"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

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

instead of what is needed for the trigger to take place

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

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

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

Hello bce,

According to Domoticz WIKI (MQTT - Domoticz), the command should be:

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

So without the { }.

Can you try that?

Regards

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%

thank you Paul-Reed

I added the other components.
:sweat_smile:

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 :slight_smile:
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::

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

or (second example)

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

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. :smiley:

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

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.

thank you
msg.payload = brightness
and

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

did the trick
That I didn't see that.

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