Nora google, ikea tradfri lamp

This post might be helpful to solve your request --> Node-RED google home integration

Math.round((value+1) * 2.55) where value is between 0-99

1 Like

Or use the range node to do it for you.

In fact to map 0-99 to 0-255 you should have
Math.round(value * 2.5758)
but better to use the Range node as suggested.

Yes. But YAGNI :grin:

Not quite sure what is intended by that, if you mean it isn't needed because the Range node is better then I entirely agree. If you mean that the the original formula was actually good enough then I don't see that. It gives wrong answers (0 maps to 3 instead of 0) and also it is less efficient as it involves an extra addition, so hasn't got much going for it.

:yum: you are totally right, the +1 should go but the value of 2.5x might just as well be rounded to 3 or even 4. You are not going to 'see' 255 different levels of brightness with a tradfri light.

Well personally I couldn't sleep at night knowing that I had put the wrong multiplier in when I could have just as easily put the right one (or at least right to an appropriate number of significant digits). Maths is too important for that.

2 Likes

Solved it guys, with some help from you and other forums
my flow now, ON and OFF and bridgtness is working

[{"id":"f8c14e86.993d1","type":"subflow","name":"NORA - Pre","info":"","category":"","in":[{"x":80,"y":100,"wires":[{"id":"80d5ccc0.ec5fc"}]}],"out":[{"x":700,"y":100,"wires":[{"id":"1299dce8.4f3fe3","port":0},{"id":"6a9ad5b9.ffa89c","port":0},{"id":"8a79f3e5.6b135","port":0}]}]},{"id":"a4b673f4.bd373","type":"switch","z":"f8c14e86.993d1","name":"Status","property":"payload.brightness","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"255","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":370,"y":100,"wires":[["1299dce8.4f3fe3"],["6a9ad5b9.ffa89c"],["8a79f3e5.6b135"]]},{"id":"1299dce8.4f3fe3","type":"change","z":"f8c14e86.993d1","name":"Off","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.on","pt":"msg","to":"OFF","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":60,"wires":[[]]},{"id":"6a9ad5b9.ffa89c","type":"change","z":"f8c14e86.993d1","name":"On","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.on","pt":"msg","to":"ON","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":100,"wires":[[]]},{"id":"8a79f3e5.6b135","type":"change","z":"f8c14e86.993d1","name":"Brightness","rules":[{"t":"set","p":"brightness","pt":"flow","to":"payload","tot":"msg"},{"t":"move","p":"payload","pt":"msg","to":"payload.brightness","tot":"msg"},{"t":"set","p":"payload.on","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":140,"wires":[[]]},{"id":"80d5ccc0.ec5fc","type":"function","z":"f8c14e86.993d1","name":"toNumber","func":"msg.payload = parseInt(msg.payload,10);\nreturn msg;","outputs":1,"noerr":0,"x":200,"y":100,"wires":[["a4b673f4.bd373"]]},{"id":"ddfed62f.093d68","type":"nora-light","z":"1a9416eb.ba0129","devicename":"boekenkast lamp","lightcolor":false,"brightnesscontrol":true,"turnonwhenbrightnesschanges":true,"passthru":false,"statepayload":false,"brightnessoverride":"","roomhint":"Slaapkamer","name":"","nora":"9d167d4b.443f","topic":"","onvalue":"{\"state\":\"ON\",\"brightness\":245}","onvalueType":"json","offvalue":"{\"state\":\"OFF\"}","offvalueType":"json","x":110,"y":240,"wires":[["b8e8124d.b8462"]]},{"id":"1eac81c2.ab392e","type":"mqtt out","z":"1a9416eb.ba0129","name":"Boekenkast lamp","topic":"zigbee2mqtt/0xccccccfffe8ab8f4/set","qos":"0","retain":"true","broker":"c40e4a64.770398","x":670,"y":240,"wires":[]},{"id":"89417983.26c418","type":"subflow:f8c14e86.993d1","z":"1a9416eb.ba0129","name":"","env":[],"x":470,"y":240,"wires":[["1eac81c2.ab392e"]]},{"id":"b8e8124d.b8462","type":"range","z":"1a9416eb.ba0129","minin":"0","maxin":"100","minout":"0","maxout":"255","action":"scale","round":false,"property":"payload","name":"","x":300,"y":240,"wires":[["89417983.26c418"]]},{"id":"9d167d4b.443f","type":"nora-config","z":"","name":"nora config","group":"","notify":true},{"id":"c40e4a64.770398","type":"mqtt-broker","z":"","name":"Hassio main","broker":"192.168.2.23","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
1 Like

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