Help with button

Hi!

I have almost got this working as i want but i can´t make the icon appear in button. I also want true and false work in boolean. now it´s working if msg.payload is true as a string.

[{"id":"9f204859.1263e8","type":"ui_button","z":"d62f0d9d.6268a","name":"on/off test1","group":"d1877cae.519f1","order":5,"width":6,"height":1,"passthru":false,"label":"{{msg.topic}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"lightstate","payloadType":"global","topic":"homie/homey-topic/binnenring/onoff/set","x":1090,"y":3140,"wires":[[]]},{"id":"e3e88d4d.043e9","type":"function","z":"d62f0d9d.6268a","name":"store the state of light","func":"var lightstate = flow.get(\"lightstate\") || undefined;\nvar label;\nvar color;\nvar icon;\n\nif(msg.payload === \"true\"){\n// state is true (lets make button green)\n label = msg.label;\n color = \"green\";\n image = \"fa-lock_open\";\n lightstate = true;\n}\nelse{\n // state is false (lets make button red)\n label = msg.label;\n color = \"red\";\n lightstate = false;\n image = \"fa-lock\";\n}\n\n\nflow.set(\"lightstate\",lightstate);\nmsg = {enabled:true, topic:label, background:color,image:icon};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":860,"y":3140,"wires":[["9f204859.1263e8"]]},{"id":"eda8a71.4d1ba58","type":"inject","z":"d62f0d9d.6268a","name":"","props":[{"p":"payload"},{"p":"label","v":"rey","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"str","x":640,"y":3140,"wires":[["e3e88d4d.043e9"]]},{"id":"d1877cae.519f1","type":"ui_group","z":"","name":"Motorlås","tab":"8ae3ce41.59647","order":1,"disp":true,"width":6,"collapse":false},{"id":"8ae3ce41.59647","type":"ui_tab","z":"","name":"Maria Åkerberg AB","icon":"dashboard","disabled":false,"hidden":false}]

Best Regards Niclasbutton

You declare var icon then never set it to anything.

=== "true" will always check that your values STRICTLY equals a string containing true

In a somewhat verbose but easy to understand way - you can do if (msg.payload == true || msg.payload == "true") {

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