Changing a Dashboard Image upon boolean MQTT input

Hi, I'm fairly new to NodeRed, and I've been scratching my head on how to change a picture upon a boolean input.

The thing that I want the program to do is display a certain image if the input is true, and display another image in case the input is false.

In the picture, the two pictures I want to be alternating are the two with the forklifts in it, where the air vent on the top right is open or closed.

My question is if this can be done with any kind of boolean input, which for now can be a UI switch, but the final product has to be from the MQTT broker thingy.

Thank you!

I might need to specify: the two images have to alternate in the same space to simulate an animation of the opening of the air vent.

Hi @aresh Maybe you could use UI_control node, and use your basic logic, for example:

if input is true
-> show this group (image 1).
-> hide this group (image 2).
else (if input is false)
-> hide this group (image 1).
-> show this group (image 2).

you could use a switch node or function node to describe your logic, and
here there are information to how to use ui_control node: ui_control info

I hope it can helps you!!

I have no idea on how to write the code, is it C++? Because that's the only language I know lol.
If you could show me like an image of the code I should write I would be so grateful, because I have no clue even on how to cite the images in the code.

by the way, i'm guessing this is the order of the blocks that have to be in the flow to make it work, correct me if i'm wrong.
immagine_2023-06-02_100953868

thank you!

open_close

[{"id":"708559a77743b59a","type":"ui_template","z":"777d1097bd4779da","group":"1067c487a1fd6cfe","name":"","order":3,"width":"9","height":"6","format":"<body>\n\n    <p>\n        <a href=\"/test/close_vent.png\" target=\"_blank\">\n            <img border=\"0\" alt=\"Close\" src={{msg.payload}} width=\"400\"  height=\"290\">\n        </a>\n    </p>\n            ","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":580,"y":180,"wires":[[]]},{"id":"77d105fa02f477fe","type":"ui_button","z":"777d1097bd4779da","name":"","group":"1067c487a1fd6cfe","order":4,"width":"3","height":"1","passthru":false,"label":"CLOSE","tooltip":"","color":"","bgcolor":"red","className":"","icon":"","payload":"/test/close_vent.png","payloadType":"str","topic":"topic","topicType":"msg","x":390,"y":180,"wires":[["708559a77743b59a"]]},{"id":"f30bf600e43529c0","type":"ui_button","z":"777d1097bd4779da","name":"","group":"1067c487a1fd6cfe","order":4,"width":"3","height":"1","passthru":false,"label":"OPEN","tooltip":"","color":"","bgcolor":"green","className":"","icon":"","payload":"/test/open_vent.png","payloadType":"str","topic":"topic","topicType":"msg","x":380,"y":270,"wires":[["708559a77743b59a"]]},{"id":"1067c487a1fd6cfe","type":"ui_group","name":"Dashboard","tab":"85b1ab4efdea8f73","order":1,"disp":false,"width":"24","collapse":false,"className":""},{"id":"85b1ab4efdea8f73","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

You would need some settings change in settings.js file to get the images to display in the dashboard. if you have gif files, you can make the opening closing action smoother.

START_STOP_FILL

6 Likes

open_close1

5 Likes

huge thanks to @smanjunath211 for helping me through discord!
for those who are on my level- so don't know anything on what they should do, here's a list:

1 - create a temp folder on your OS disk, in this case i decided to call it simply "temp", and inside it put the files that you want to be displayed. let's call them "myphoto.png"
and "theotherphoto.png" for this example.
2 - find the settings.js file! this might be tricky for the newbies, but its directory can be found while booting nodered on the node.js terminal:
immagine_2023-06-05_184308591

3 - before editing the settings.js file, create a backup, just to be sure.
4 - now we edit the file, which can be opened with notepad: search for the first "httpStatic:" line, and delete the two backslashes before the line. (tip! if you can't find it, use the 'find' tool, which can be summoned by pressing CTRL+F)

5 - this one IS IMPORTANT!! delete the directory between the '' brackets and write the name of the folder you named before: in my case: '/temp'
6 - now we can save the file and reboot NodeRed. if everything has been done correctly, you should see that a new line in the terminal has appeared, and it's the httpStatic directory!

immagine_2023-06-05_185022201

7 - we can now test if the image got uploaded correctly, and that is by writing on the search bar the directory of the file, which in this case is going to be "localhost:1880/myphoto.png". if the photo is displayed, we can continue, if the website replies with "Cannot GET /myphoto.png" check if the name of the photo is written properly, and if it is, check the previous steps shown before, from the beginning possibly.

8 - now we can go in the flow of NodeRed: import the flow from @smanjunath211

[{"id":"708559a77743b59a","type":"ui_template","z":"777d1097bd4779da","group":"1067c487a1fd6cfe","name":"","order":3,"width":"9","height":"6","format":"<body>\n\n    <p>\n        <a href=\"/test/close_vent.png\" target=\"_blank\">\n            <img border=\"0\" alt=\"Close\" src={{msg.payload}} width=\"400\"  height=\"290\">\n        </a>\n    </p>\n            ","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":580,"y":180,"wires":[[]]},{"id":"77d105fa02f477fe","type":"ui_button","z":"777d1097bd4779da","name":"","group":"1067c487a1fd6cfe","order":4,"width":"3","height":"1","passthru":false,"label":"CLOSE","tooltip":"","color":"","bgcolor":"red","className":"","icon":"","payload":"/test/close_vent.png","payloadType":"str","topic":"topic","topicType":"msg","x":390,"y":180,"wires":[["708559a77743b59a"]]},{"id":"f30bf600e43529c0","type":"ui_button","z":"777d1097bd4779da","name":"","group":"1067c487a1fd6cfe","order":4,"width":"3","height":"1","passthru":false,"label":"OPEN","tooltip":"","color":"","bgcolor":"green","className":"","icon":"","payload":"/test/open_vent.png","payloadType":"str","topic":"topic","topicType":"msg","x":380,"y":270,"wires":[["708559a77743b59a"]]},{"id":"1067c487a1fd6cfe","type":"ui_group","name":"Dashboard","tab":"85b1ab4efdea8f73","order":1,"disp":false,"width":"24","collapse":false,"className":""},{"id":"85b1ab4efdea8f73","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

and make sure you have two buttons and one template function. forgot to tell you, but you absolutely NEED the ui_media palette! check if you have it, if not, it ain't gonna work out.
(if you don't know how to import a file, that's fine, i didn't know either 3 hours before writing this guide, haha. just go in the nodered flow and press CTRL+i. a small window might pop up, and in the bigger text box you're gonna paste the whole flow code written before, then.. just import.)

9 - open one of the two buttons and edit the playload image name: in this case, we are gonna write '/myphoto.png'. remember the slash before "myphoto.png" because you need it!!
also, check the little box under the topic text box.

image

10 - now everything should be good to go! if you press one of the two buttons, one of the two images should display.

3 Likes

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