Hi,
I'm using text input (set as time picker) to store hours and minutes to a json file. This part works (well...).
Then when the web page is loaded/reloaded, I need to read the json file and set the text input to the saved time.
So, I'm having a few issues:
- I cannot get to parse the json data to manipulate it.
- I don't know how to read said file when the web page is loaded.
- I'm now storing hour and minutes, but what if the file contains more data like:
{"led": on, "relay": off, "hour":12, "minute":15}
I really appreciate some assistance on this.
TIA
[{"id":"e3f00cd4.c13ba8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"d084f6b3.0b2fe8","type":"debug","z":"e3f00cd4.c13ba8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":220,"wires":[]},{"id":"60686e6d.c19ee8","type":"ui_text_input","z":"e3f00cd4.c13ba8","name":"webTime","label":"Hora persiana","tooltip":"","group":"e624b78b.0592d8","order":2,"width":"3","height":"1","passthru":false,"mode":"time","delay":"400","topic":"","x":100,"y":140,"wires":[["f88152f4.dd1"]]},{"id":"f88152f4.dd1","type":"function","z":"e3f00cd4.c13ba8","name":"extractTime","func":"var time = msg.payload;\nvar minutes = time / 60000;\nvar hour = 0;\nif (minutes > 59) {\n hour = Math.floor(minutes / 60)\n minutes = minutes % 60\n}\nmsg.payload = {\"hour\":hour, \"minute\":minutes};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":250,"y":140,"wires":[["6402657c.6bc40c"]]},{"id":"c672fbec.bf17d8","type":"file","z":"e3f00cd4.c13ba8","name":"","filename":"/home/pi/test.log","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":540,"y":140,"wires":[[]]},{"id":"6402657c.6bc40c","type":"json","z":"e3f00cd4.c13ba8","name":"","property":"payload","action":"","pretty":false,"x":390,"y":140,"wires":[["c672fbec.bf17d8"]]},{"id":"b1db9cb4.baf77","type":"inject","z":"e3f00cd4.c13ba8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":220,"wires":[["9d14a4c.cb751d8"]]},{"id":"9d14a4c.cb751d8","type":"file in","z":"e3f00cd4.c13ba8","name":"","filename":"/home/pi/test.log","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":290,"y":220,"wires":[["fe5c13a5.c61c6"]]},{"id":"fe5c13a5.c61c6","type":"function","z":"e3f00cd4.c13ba8","name":"timeConvert","func":"var m=msg.payload;\nvar hr=JSON.parse(m.hour);\nvar min=JSON.parse(x.minute);\nvar time=((hr*60)+(min))*60000;\nmsg.payload=time;\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":510,"y":220,"wires":[["d084f6b3.0b2fe8","60686e6d.c19ee8"]]},{"id":"e624b78b.0592d8","type":"ui_group","z":"","name":"Mnto","tab":"2332b0a1.2f261","order":3,"disp":true,"width":"6","collapse":true},{"id":"2332b0a1.2f261","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]