Problem with the date format

I have been using a flow to get the day and time on the main screen, and to use it with a "buzzer alarm" function. So far it has worked perfectly, but yesterday I realized that the "month" field appears as "undefined".

I have checked the translation of the variables and they are correct, but I don't know what is the reason that it appears in the month field "undefined".

Any ideas?

I attach the Flow so you can see it.

[{"id":"a9b22498.87eb98","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"8402276a.e0a6b8","type":"simpletime","z":"a9b22498.87eb98","name":"Tijd","x":390,"y":320,"wires":[["2d8392ad.99ffbe"]]},{"id":"ffe249a4.a4d708","type":"inject","z":"a9b22498.87eb98","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":320,"wires":[["8402276a.e0a6b8"]]},{"id":"2d8392ad.99ffbe","type":"moment","z":"a9b22498.87eb98","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Europe/London","adjAmount":"2","adjType":"hours","adjDir":"add","format":"HH:mm:ss","locale":"es_ES","output":"","outputType":"msg","outTz":"Etc/UTC","x":600,"y":320,"wires":[["1b0ed193.c3b86e","a5a5decd.5a7c6"]]},{"id":"1b0ed193.c3b86e","type":"function","z":"a9b22498.87eb98","name":"Store Time in global variable","func":"var Time=global.get(\"GlobalTime\") || '';\nglobal.set(\"GlobalTime\",msg.payload);\n\nreturn msg;","outputs":1,"noerr":0,"x":900,"y":340,"wires":[[]]},{"id":"d82b7fdd.7423c","type":"ui_template","z":"a9b22498.87eb98","group":"9e908f06.94c48","name":"Tijd / Datum","order":1,"width":10,"height":3,"format":"<p style=\"font-size:45px; text-align: center; font-weight: bold;\">{{msg.time}}</p> \n<p style=\"font-size:15px; text-align: center; font-weight: bold;\"><i style=\"color:#0094CE!important;\" class=\"fa fa-calendar\" aria-hidden=\"true\"></i>&nbsp;&nbsp;{{msg.date}}</p>\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":1230,"y":300,"wires":[[]]},{"id":"a5a5decd.5a7c6","type":"function","z":"a9b22498.87eb98","name":"Set icon color and temperature","func":"var Datevar=global.get(\"GlobalDate\") || '';\nmsg = {time:msg.payload, date:Datevar};\nreturn msg;","outputs":1,"noerr":0,"x":910,"y":300,"wires":[["d82b7fdd.7423c"]]},{"id":"e195ed38.554f9","type":"comment","z":"a9b22498.87eb98","name":"Obtenemos el DĂ­a y la Hora","info":"","x":640,"y":200,"wires":[]},{"id":"2665fac5.857026","type":"moment","z":"a9b22498.87eb98","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Europe/Berlin","adjAmount":"2","adjType":"hours","adjDir":"add","format":"dddd DD MMMM YYYY","locale":"es_ES","output":"","outputType":"msg","outTz":"Etc/UTC","x":600,"y":420,"wires":[["f8d657ff.1a2848"]]},{"id":"213ad1ce.7410ae","type":"function","z":"a9b22498.87eb98","name":"Store date in global variable","func":"var Datevar=global.get(\"GlobalDate\") || '';\nglobal.set(\"GlobalDate\",msg.payload);\n\nreturn msg;","outputs":1,"noerr":0,"x":1020,"y":420,"wires":[[]]},{"id":"f8d657ff.1a2848","type":"function","z":"a9b22498.87eb98","name":"Translate","func":"var mapObj = {\n Monday:\"Lunes\",\n Tuesday:\"Martes\",\n Wednesday:\"Miercoles\",\n Thursday:\"Jueves\",\n Friday:\"Viernes\",\n Saturday:\"Sabado\",\n Sunday:\"Domingo\",\n January:\"Enero\",\n February:\"Febrero\",\n March:\"Marzo\",\n April:\"Abril\",\n May:\"Mayo\",\n June:\"Junio\",\n July:\"Julio\",\n August:\"Agosto\",\n September:\"Septiembre\",\n October:\"Octubre\",\n November:\"Noviembre\",\n December:\"Diciembre\"\n};\nmsg.payload = msg.payload.replace(/Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday|January|February|March|April|May|June|July|August|September|October|November|December/gi, function(matched){\n return mapObj[matched];\n});\n\n\nreturn msg;","outputs":1,"noerr":0,"x":800,"y":420,"wires":[["213ad1ce.7410ae"]]},{"id":"cb3b0425.e4a2a8","type":"simpletime","z":"a9b22498.87eb98","name":"Tijd","x":390,"y":420,"wires":[["2665fac5.857026","31ca4d0d.4fa6f2"]]},{"id":"634e7ca1.e31ef4","type":"inject","z":"a9b22498.87eb98","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":420,"wires":[["cb3b0425.e4a2a8"]]},{"id":"d4c4d2f9.8f37e","type":"function","z":"a9b22498.87eb98","name":"Store date in global variable","func":"var Datevar=global.get(\"GlobalDateShort\") || '';\nglobal.set(\"GlobalDateShort\",msg.payload);\n\nreturn msg;","outputs":1,"noerr":0,"x":1020,"y":460,"wires":[[]]},{"id":"31ca4d0d.4fa6f2","type":"moment","z":"a9b22498.87eb98","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Europe/Berlin","adjAmount":"2","adjType":"hours","adjDir":"add","format":"DD-MM","locale":"es_ES","output":"","outputType":"msg","outTz":"Etc/UTC","x":600,"y":460,"wires":[["d4c4d2f9.8f37e"]]},{"id":"9e908f06.94c48","type":"ui_group","z":"","name":"Hoy","tab":"41973f9d.b568a","order":2,"disp":true,"width":"10","collapse":false},{"id":"41973f9d.b568a","type":"ui_tab","z":"","name":"Home","icon":"home","order":1}]

232336

Thank you.

a greeting

Hi, wow, not certain what you are actually trying to achieve but there was a fair amount of extra nodes and extra processing and function nodes that were not necessary.

Before...


image

After...

[{"id":"2a6e9727.ba3b18","type":"inject","z":"19e1b6f3.b0b619","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"onceDelay":0.1,"x":990,"y":100,"wires":[["51dbcbb7.3e8524"]]},{"id":"dfc7657c.b0c688","type":"comment","z":"19e1b6f3.b0b619","name":"Obtenemos el DĂ­a y la Hora","info":"","x":1020,"y":60,"wires":[]},{"id":"8dc6ee6b.69de4","type":"ui_template","z":"19e1b6f3.b0b619","group":"744a90ef.637b9","name":"Tijd / Datum","order":1,"width":10,"height":3,"format":"<p style=\"font-size:45px; text-align: center; font-weight: bold;\">{{msg.time}}</p> \n<p style=\"font-size:15px; text-align: center; font-weight: bold;\"><i style=\"color:#0094CE!important;\" class=\"fa fa-calendar\" aria-hidden=\"true\"></i>&nbsp;&nbsp;{{msg.date}}</p>\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":1190,"y":220,"wires":[[]]},{"id":"bafd4649.a56698","type":"change","z":"19e1b6f3.b0b619","name":"update global vars","rules":[{"t":"set","p":"GlobalDateShort","pt":"global","to":"dateShort","tot":"msg"},{"t":"set","p":"GlobalDate","pt":"global","to":"date","tot":"msg"},{"t":"set","p":"GlobalTime","pt":"global","to":"time","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":220,"wires":[["8dc6ee6b.69de4","c765af18.10afa"]]},{"id":"c765af18.10afa","type":"debug","z":"19e1b6f3.b0b619","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1170,"y":260,"wires":[]},{"id":"51dbcbb7.3e8524","type":"moment","z":"19e1b6f3.b0b619","name":"HH:mm:ss --> msg.time","topic":"","input":"payload","inputType":"msg","inTz":"Europe/London","adjAmount":"2","adjType":"hours","adjDir":"add","format":"HH:mm:ss","locale":"es_ES","output":"time","outputType":"msg","outTz":"Etc/UTC","x":1230,"y":100,"wires":[["7f904698.bdfdb8"]]},{"id":"7f904698.bdfdb8","type":"moment","z":"19e1b6f3.b0b619","name":"date --> msg.date","topic":"","input":"payload","inputType":"msg","inTz":"Europe/Berlin","adjAmount":"2","adjType":"hours","adjDir":"add","format":"dddd DD MMMM YYYY","locale":"es_ES","output":"date","outputType":"msg","outTz":"Etc/UTC","x":990,"y":160,"wires":[["e5bdb315.80dd"]]},{"id":"e5bdb315.80dd","type":"moment","z":"19e1b6f3.b0b619","name":"DD-MM --> msg.dateShort","topic":"","input":"payload","inputType":"msg","inTz":"Europe/Berlin","adjAmount":"2","adjType":"hours","adjDir":"add","format":"DD-MM","locale":"es_ES","output":"dateShort","outputType":"msg","outTz":"Etc/UTC","x":1240,"y":160,"wires":[["bafd4649.a56698"]]},{"id":"744a90ef.637b9","type":"ui_group","z":"","name":"Default","tab":"a17cee11.28837","order":1,"disp":true,"width":"10","collapse":false},{"id":"a17cee11.28837","type":"ui_tab","z":"","name":"Home Orig","icon":"dashboard","disabled":false,"hidden":false}]

Issues...

  1. SimpleTime node is unnecessary (the inject generates a time stamp)
  2. You had 2 separate flows but 1 of them didnt actually update globals
  3. I suspect you dont need the globals at all (i guess you were using them to display all values at once?) By putting the nodes in series, all values the values you need are collected in one msg - all in one go
  4. Your Translate node was unnecessary as the moment node returns spanish text.
  5. Function nodes are heavy & overkill for storing values in global context.
1 Like

Hello

I want to thank you for the code you sent me.

It works perfectly!!!!. The truth is that you "re-use" the code from another site.

I want to apologize for not having answered you before, health problems have already occurred.

Very thankful!!!!

1 Like

Very many of the examples you will see here are examples that have already been used somewhere. Very often we see the same problem repeated time and again.

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