Problem with reduce and jsonata

#1

I have this flow to get values from a postgres database, and do a reduce, i get a "Invalid JSONata expression: Argument 1 of function "reduce" does not match function signature"

[{"id":"61cc9c87.55a894","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"16605903.265397","type":"inject","z":"61cc9c87.55a894","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":102,"y":484,"wires":[["9f945fbe.c06e9","fb6a6dbd.c48e7","e11b3102.852b6"]]},{"id":"e69c5ac4.5c1ff8","type":"debug","z":"61cc9c87.55a894","name":"DEBUG","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":989.5,"y":438,"wires":[]},{"id":"56e96211.6feaec","type":"change","z":"61cc9c87.55a894","name":"Set Values","rules":[{"t":"set","p":"eur_watio","pt":"msg","to":"0.139","tot":"num"},{"t":"set","p":"range_minutes","pt":"msg","to":"1440","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":601,"y":540,"wires":[["5ee6ff24.7b3d8","a45abee3.b2b49"]]},{"id":"fb6a6dbd.c48e7","type":"postgrestor","z":"61cc9c87.55a894","name":"QUERY","query":"SELECT state, created\nFROM \"states\"\nWHERE \"entity_id\" = 'sensor.qubino_zmnhtdx_smart_meter_s4_s5_s6_power' AND \"state\" >= '0' AND \"state\" <= '8000' AND DATE(created) = current_date -1","postgresDB":"7d271799.7d3f88","output":true,"outputs":1,"x":282,"y":438,"wires":[["ee15803b.85f26"]]},{"id":"5ee6ff24.7b3d8","type":"change","z":"61cc9c87.55a894","name":"Set result","rules":[{"t":"set","p":"result","pt":"msg","to":"$reduce(payload, function ($a,$v) {(\t                    $calculo := function ($eur_w,$range,$watios,$start_date,$finish_date) {(\t                                    ($start_date = \"\") ? $start_date := $finish_date;\t                                     $part := $floor($abs($toMillis($finish_date) - $toMillis($start_date))/1000)/60;\t                                    (($eur_w/60) * $watios * $part) / ($range)\t                                    )};\t{\"state\" : $calculo(eur_watio,range_minutes,$number($v.state),$a.created,$v.created) +  $a.state, \"created\" : $v.created})},\t{\"state\" : 0, \"created\" : \"\"})\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":844,"y":438,"wires":[["e69c5ac4.5c1ff8"]]},{"id":"7ac6637b.fd083c","type":"json","z":"61cc9c87.55a894","name":"","property":"payload","action":"","pretty":false,"x":975,"y":266,"wires":[["5ee6ff24.7b3d8"]]},{"id":"a45abee3.b2b49","type":"change","z":"61cc9c87.55a894","name":"Fix payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"$string(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":837,"y":266,"wires":[["7ac6637b.fd083c"]]},{"id":"b3d9f452.483738","type":"postgres","z":"61cc9c87.55a894","postgresdb":"7390e72a.b8f828","name":"Query","output":true,"outputs":1,"x":455.5,"y":539,"wires":[["56e96211.6feaec"]]},{"id":"9f945fbe.c06e9","type":"change","z":"61cc9c87.55a894","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[{\"query\":\"SELECT state, created FROM \\\"states\\\" WHERE \\\"entity_id\\\" = 'sensor.qubino_zmnhtdx_smart_meter_s4_s5_s6_power' AND \\\"state\\\" >= '0' AND \\\"state\\\" <= '8000' AND DATE(created) = current_date -1\",\"params\":{},\"output\":true}]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":300.5,"y":540,"wires":[["b3d9f452.483738"]]},{"id":"ee15803b.85f26","type":"change","z":"61cc9c87.55a894","name":"Set values","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.rows","tot":"msg"},{"t":"set","p":"eur_watio","pt":"msg","to":"0.139","tot":"num"},{"t":"set","p":"range_minutes","pt":"msg","to":"1440","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":434,"y":438,"wires":[["5ee6ff24.7b3d8","a45abee3.b2b49"]]},{"id":"a40b958b.2afc38","type":"comment","z":"61cc9c87.55a894","name":"postgrestor","info":"","x":283.5,"y":399,"wires":[]},{"id":"27ca6398.8f59bc","type":"comment","z":"61cc9c87.55a894","name":"node-red-contrib-postgres-multi","info":"","x":346.5,"y":502,"wires":[]},{"id":"e11b3102.852b6","type":"change","z":"61cc9c87.55a894","name":"Set manual values","rules":[{"t":"set","p":"payload","pt":"msg","to":"[{\"state\":\"269.4\",\"created\":\"2019-03-27T00:00:32.866Z\"},{\"state\":\"268.6\",\"created\":\"2019-03-27T00:10:27.963Z\"},{\"state\":\"266.3\",\"created\":\"2019-03-27T00:20:28.031Z\"},{\"state\":\"265.3\",\"created\":\"2019-03-27T00:30:29.600Z\"},{\"state\":\"264.1\",\"created\":\"2019-03-27T00:40:29.664Z\"},{\"state\":\"261.2\",\"created\":\"2019-03-27T00:50:31.154Z\"},{\"state\":\"263.2\",\"created\":\"2019-03-27T01:00:31.347Z\"},{\"state\":\"258.3\",\"created\":\"2019-03-27T01:10:28.138Z\"},{\"state\":\"272.0\",\"created\":\"2019-03-27T01:20:29.481Z\"},{\"state\":\"269.4\",\"created\":\"2019-03-27T01:30:29.514Z\"},{\"state\":\"224.5\",\"created\":\"2019-03-27T01:36:59.971Z\"},{\"state\":\"311.4\",\"created\":\"2019-03-27T01:37:12.721Z\"},{\"state\":\"481.9\",\"created\":\"2019-03-27T01:37:20.772Z\"},{\"state\":\"484.4\",\"created\":\"2019-03-27T01:40:31.246Z\"},{\"state\":\"486.1\",\"created\":\"2019-03-27T01:50:32.952Z\"},{\"state\":\"488.8\",\"created\":\"2019-03-27T02:00:26.396Z\"},{\"state\":\"226.7\",\"created\":\"2019-03-27T02:02:26.368Z\"},{\"state\":\"265.2\",\"created\":\"2019-03-27T02:06:31.176Z\"},{\"state\":\"306.5\",\"created\":\"2019-03-27T02:06:37.532Z\"},{\"state\":\"293.2\",\"created\":\"2019-03-27T02:10:31.178Z\"},{\"state\":\"281.7\",\"created\":\"2019-03-27T02:20:31.304Z\"},{\"state\":\"297.3\",\"created\":\"2019-03-27T02:30:31.240Z\"},{\"state\":\"275.9\",\"created\":\"2019-03-27T02:40:32.871Z\"},{\"state\":\"283.7\",\"created\":\"2019-03-27T02:50:26.633Z\"},{\"state\":\"271.6\",\"created\":\"2019-03-27T03:00:28.015Z\"},{\"state\":\"252.8\",\"created\":\"2019-03-27T03:10:29.719Z\"},{\"state\":\"253.6\",\"created\":\"2019-03-27T03:20:31.284Z\"},{\"state\":\"269.5\",\"created\":\"2019-03-27T03:30:31.144Z\"},{\"state\":\"224.3\",\"created\":\"2019-03-27T03:34:35.919Z\"},{\"state\":\"221.2\",\"created\":\"2019-03-27T03:40:32.805Z\"},{\"state\":\"243.6\",\"created\":\"2019-03-27T03:47:03.070Z\"},{\"state\":\"271.0\",\"created\":\"2019-03-27T03:47:11.090Z\"},{\"state\":\"256.9\",\"created\":\"2019-03-27T03:50:29.474Z\"},{\"state\":\"260.4\",\"created\":\"2019-03-27T04:00:31.546Z\"},{\"state\":\"255.1\",\"created\":\"2019-03-27T04:10:26.342Z\"},{\"state\":\"252.9\",\"created\":\"2019-03-27T04:20:27.811Z\"},{\"state\":\"254.4\",\"created\":\"2019-03-27T04:30:27.869Z\"},{\"state\":\"291.1\",\"created\":\"2019-03-27T04:35:04.659Z\"},{\"state\":\"290.5\",\"created\":\"2019-03-27T04:40:27.946Z\"},{\"state\":\"255.1\",\"created\":\"2019-03-27T04:43:27.088Z\"},{\"state\":\"254.1\",\"created\":\"2019-03-27T04:50:29.589Z\"},{\"state\":\"286.2\",\"created\":\"2019-03-27T04:52:15.056Z\"},{\"state\":\"257.4\",\"created\":\"2019-03-27T04:59:49.626Z\"},{\"state\":\"250.9\",\"created\":\"2019-03-27T05:00:31.192Z\"},{\"state\":\"277.3\",\"created\":\"2019-03-27T05:03:09.657Z\"},{\"state\":\"243.7\",\"created\":\"2019-03-27T05:06:19.884Z\"},{\"state\":\"241.1\",\"created\":\"2019-03-27T05:10:31.155Z\"},{\"state\":\"284.0\",\"created\":\"2019-03-27T05:13:55.890Z\"},{\"state\":\"243.0\",\"created\":\"2019-03-27T05:18:26.279Z\"},{\"state\":\"221.5\",\"created\":\"2019-03-27T05:20:31.388Z\"},{\"state\":\"259.0\",\"created\":\"2019-03-27T05:22:23.079Z\"},{\"state\":\"303.5\",\"created\":\"2019-03-27T05:22:37.706Z\"},{\"state\":\"259.7\",\"created\":\"2019-03-27T05:24:08.760Z\"},{\"state\":\"275.1\",\"created\":\"2019-03-27T05:30:32.623Z\"},{\"state\":\"253.1\",\"created\":\"2019-03-27T05:40:27.914Z\"},{\"state\":\"254.4\",\"created\":\"2019-03-27T05:50:27.911Z\"},{\"state\":\"255.2\",\"created\":\"2019-03-27T06:00:27.900Z\"},{\"state\":\"227.2\",\"created\":\"2019-03-27T06:00:42.265Z\"},{\"state\":\"216.4\",\"created\":\"2019-03-27T06:10:29.459Z\"},{\"state\":\"241.3\",\"created\":\"2019-03-27T06:14:13.482Z\"},{\"state\":\"280.2\",\"created\":\"2019-03-27T06:14:26.294Z\"},{\"state\":\"251.2\",\"created\":\"2019-03-27T06:15:06.388Z\"},{\"state\":\"254.3\",\"created\":\"2019-03-27T06:20:30.922Z\"},{\"state\":\"257.2\",\"created\":\"2019-03-27T06:30:32.616Z\"},{\"state\":\"314.9\",\"created\":\"2019-03-27T06:38:27.862Z\"},{\"state\":\"291.8\",\"created\":\"2019-03-27T06:40:26.367Z\"},{\"state\":\"253.1\",\"created\":\"2019-03-27T06:44:23.160Z\"},{\"state\":\"291.8\",\"created\":\"2019-03-27T06:48:46.972Z\"},{\"state\":\"286.5\",\"created\":\"2019-03-27T06:50:26.178Z\"},{\"state\":\"256.0\",\"created\":\"2019-03-27T06:51:33.488Z\"},{\"state\":\"351.1\",\"created\":\"2019-03-27T06:53:51.085Z\"},{\"state\":\"1786.0\",\"created\":\"2019-03-27T06:53:57.482Z\"},{\"state\":\"254.3\",\"created\":\"2019-03-27T06:54:37.500Z\"},{\"state\":\"1284.3\",\"created\":\"2019-03-27T06:54:43.758Z\"},{\"state\":\"1788.6\",\"created\":\"2019-03-27T06:54:50.134Z\"},{\"state\":\"292.5\",\"created\":\"2019-03-27T06:55:04.579Z\"},{\"state\":\"1304.5\",\"created\":\"2019-03-27T06:55:44.591Z\"},{\"state\":\"1779.0\",\"created\":\"2019-03-27T06:55:51.067Z\"},{\"state\":\"282.2\",\"created\":\"2019-03-27T06:56:03.943Z\"},{\"state\":\"219.5\",\"created\":\"2019-03-27T06:57:04.557Z\"},{\"state\":\"221.2\",\"created\":\"2019-03-27T07:00:29.304Z\"},{\"state\":\"262.6\",\"created\":\"2019-03-27T07:01:15.886Z\"},{\"state\":\"293.1\",\"created\":\"2019-03-27T07:03:33.420Z\"},{\"state\":\"329.1\",\"created\":\"2019-03-27T07:07:19.303Z\"},{\"state\":\"282.6\",\"created\":\"2019-03-27T07:08:11.765Z\"},{\"state\":\"359.4\",\"created\":\"2019-03-27T07:09:10.952Z\"},{\"state\":\"320.9\",\"created\":\"2019-03-27T07:09:04.579Z\"},{\"state\":\"332.1\",\"created\":\"2019-03-27T07:10:29.503Z\"},{\"state\":\"287.8\",\"created\":\"2019-03-27T07:14:27.884Z\"},{\"state\":\"311.6\",\"created\":\"2019-03-27T07:18:18.314Z\"},{\"state\":\"349.6\",\"created\":\"2019-03-27T07:20:31.161Z\"},{\"state\":\"347.7\",\"created\":\"2019-03-27T07:19:38.705Z\"},{\"state\":\"445.2\",\"created\":\"2019-03-27T07:26:21.579Z\"},{\"state\":\"330.1\",\"created\":\"2019-03-27T07:26:41.035Z\"},{\"state\":\"317.8\",\"created\":\"2019-03-27T07:30:26.320Z\"},{\"state\":\"268.9\",\"created\":\"2019-03-27T07:31:19.350Z\"},{\"state\":\"305.8\",\"created\":\"2019-03-27T07:41:59.041Z\"},{\"state\":\"263.1\",\"created\":\"2019-03-27T07:40:26.335Z\"},{\"state\":\"274.7\",\"created\":\"2019-03-27T07:47:09.440Z\"},{\"state\":\"242.0\",\"created\":\"2019-03-27T07:50:21.766Z\"},{\"state\":\"241.4\",\"created\":\"2019-03-27T07:50:27.864Z\"},{\"state\":\"242.7\",\"created\":\"2019-03-27T08:00:29.375Z\"},{\"state\":\"270.8\",\"created\":\"2019-03-27T08:02:34.290Z\"},{\"state\":\"240.1\",\"created\":\"2019-03-27T08:10:10.318Z\"},{\"state\":\"240.8\",\"created\":\"2019-03-27T08:10:31.111Z\"},{\"state\":\"212.1\",\"created\":\"2019-03-27T08:10:56.628Z\"},{\"state\":\"238.7\",\"created\":\"2019-03-27T08:12:48.617Z\"},{\"state\":\"209.8\",\"created\":\"2019-03-27T08:20:11.788Z\"},{\"state\":\"207.1\",\"created\":\"2019-03-27T08:20:30.962Z\"},{\"state\":\"249.7\",\"created\":\"2019-03-27T08:24:02.234Z\"},{\"state\":\"244.6\",\"created\":\"2019-03-27T08:30:32.579Z\"},{\"state\":\"275.3\",\"created\":\"2019-03-27T08:33:18.199Z\"},{\"state\":\"244.6\",\"created\":\"2019-03-27T08:40:13.519Z\"},{\"state\":\"276.0\",\"created\":\"2019-03-27T08:43:25.365Z\"},{\"state\":\"244.2\",\"created\":\"2019-03-27T08:48:42.106Z\"},{\"state\":\"274.3\",\"created\":\"2019-03-27T08:49:28.659Z\"},{\"state\":\"272.9\",\"created\":\"2019-03-27T08:50:27.784Z\"},{\"state\":\"242.4\",\"created\":\"2019-03-27T08:54:26.124Z\"},{\"state\":\"240.8\",\"created\":\"2019-03-27T09:00:29.514Z\"},{\"state\":\"268.7\",\"created\":\"2019-03-27T09:03:20.576Z\"},{\"state\":\"241.6\",\"created\":\"2019-03-27T09:07:57.320Z\"},{\"state\":\"240.7\",\"created\":\"2019-03-27T09:10:29.251Z\"},{\"state\":\"276.8\",\"created\":\"2019-03-27T09:14:13.398Z\"},{\"state\":\"242.4\",\"created\":\"2019-03-27T09:18:45.258Z\"},{\"state\":\"240.9\",\"created\":\"2019-03-27T09:20:31.067Z\"},{\"state\":\"273.0\",\"created\":\"2019-03-27T09:29:38.378Z\"},{\"state\":\"242.6\",\"created\":\"2019-03-27T09:32:10.276Z\"},{\"state\":\"207.8\",\"created\":\"2019-03-27T09:37:54.119Z\"},{\"state\":\"207.1\",\"created\":\"2019-03-27T09:40:27.633Z\"},{\"state\":\"237.4\",\"created\":\"2019-03-27T09:44:13.351Z\"},{\"state\":\"282.3\",\"created\":\"2019-03-27T09:48:30.926Z\"},{\"state\":\"241.8\",\"created\":\"2019-03-27T09:50:29.387Z\"},{\"state\":\"251.9\",\"created\":\"2019-03-27T09:49:03.035Z\"},{\"state\":\"269.5\",\"created\":\"2019-03-27T09:53:14.212Z\"},{\"state\":\"242.0\",\"created\":\"2019-03-27T09:58:18.170Z\"},{\"state\":\"241.4\",\"created\":\"2019-03-27T10:00:30.907Z\"},{\"state\":\"272.9\",\"created\":\"2019-03-27T10:03:28.583Z\"},{\"state\":\"239.3\",\"created\":\"2019-03-27T10:07:58.941Z\"},{\"state\":\"242.0\",\"created\":\"2019-03-27T10:10:32.538Z\"},{\"state\":\"271.0\",\"created\":\"2019-03-27T10:13:23.734Z\"},{\"state\":\"302.5\",\"created\":\"2019-03-27T10:15:03.132Z\"},{\"state\":\"282.3\",\"created\":\"2019-03-27T10:20:26.289Z\"},{\"state\":\"402.5\",\"created\":\"2019-03-27T10:22:24.585Z\"},{\"state\":\"279.2\",\"created\":\"2019-03-27T10:22:45.229Z\"},{\"state\":\"248.9\",\"created\":\"2019-03-27T10:23:50.843Z\"},{\"state\":\"243.1\",\"created\":\"2019-03-27T10:30:27.794Z\"},{\"state\":\"269.6\",\"created\":\"2019-03-27T10:31:06.113Z\"},{\"state\":\"242.6\",\"created\":\"2019-03-27T10:33:18.824Z\"},{\"state\":\"276.8\",\"created\":\"2019-03-27T10:33:31.930Z\"},{\"state\":\"242.9\",\"created\":\"2019-03-27T10:38:02.004Z\"},{\"state\":\"241.8\",\"created\":\"2019-03-27T10:40:27.635Z\"},{\"state\":\"271.3\",\"created\":\"2019-03-27T10:44:05.328Z\"},{\"state\":\"242.1\",\"created\":\"2019-03-27T10:50:08.562Z\"},{\"state\":\"243.2\",\"created\":\"2019-03-27T10:50:29.359Z\"},{\"state\":\"621.7\",\"created\":\"2019-03-27T10:50:48.598Z\"},{\"state\":\"1310.1\",\"created\":\"2019-03-27T10:51:01.217Z\"},{\"state\":\"1101.4\",\"created\":\"2019-03-27T10:52:27.957Z\"},{\"state\":\"1222.8\",\"created\":\"2019-03-27T10:52:34.132Z\"},{\"state\":\"352.7\",\"created\":\"2019-03-27T10:52:21.237Z\"},{\"state\":\"1383.4\",\"created\":\"2019-03-27T10:54:13.395Z\"},{\"state\":\"431.1\",\"created\":\"2019-03-27T10:54:47.066Z\"},{\"state\":\"1396.9\",\"created\":\"2019-03-27T10:54:53.560Z\"},{\"state\":\"512.1\",\"created\":\"2019-03-27T10:56:18.535Z\"},{\"state\":\"445.0\",\"created\":\"2019-03-27T10:56:32.579Z\"},{\"state\":\"338.3\",\"created\":\"2019-03-27T10:56:44.702Z\"},{\"state\":\"534.7\",\"created\":\"2019-03-27T10:57:10.956Z\"},{\"state\":\"507.6\",\"created\":\"2019-03-27T10:56:48.167Z\"},{\"state\":\"412.5\",\"created\":\"2019-03-27T10:56:58.414Z\"},{\"state\":\"413.7\",\"created\":\"2019-03-27T10:57:18.956Z\"},{\"state\":\"334.1\",\"created\":\"2019-03-27T10:57:25.277Z\"},{\"state\":\"421.8\",\"created\":\"2019-03-27T10:57:31.772Z\"},{\"state\":\"387.9\",\"created\":\"2019-03-27T10:57:44.482Z\"},{\"state\":\"525.5\",\"created\":\"2019-03-27T10:57:38.155Z\"},{\"state\":\"1556.8\",\"created\":\"2019-03-27T10:58:03.739Z\"},{\"state\":\"569.5\",\"created\":\"2019-03-27T10:57:57.505Z\"},{\"state\":\"569.5\",\"created\":\"2019-03-27T10:59:51.300Z\"},{\"state\":\"1552.6\",\"created\":\"2019-03-27T10:59:59.729Z\"},{\"state\":\"1543.3\",\"created\":\"2019-03-27T11:00:30.865Z\"},{\"state\":\"1309.7\",\"created\":\"2019-03-27T11:00:56.579Z\"},{\"state\":\"423.6\",\"created\":\"2019-03-27T11:01:04.458Z\"},{\"state\":\"527.9\",\"created\":\"2019-03-27T11:01:17.273Z\"},{\"state\":\"378.1\",\"created\":\"2019-03-27T11:01:10.876Z\"},{\"state\":\"423.3\",\"created\":\"2019-03-27T11:01:23.749Z\"},{\"state\":\"333.9\",\"created\":\"2019-03-27T11:01:38.212Z\"},{\"state\":\"336.5\",\"created\":\"2019-03-27T11:01:57.295Z\"},{\"state\":\"537.3\",\"created\":\"2019-03-27T11:01:44.567Z\"},{\"state\":\"491.8\",\"created\":\"2019-03-27T11:02:10.824Z\"},{\"state\":\"480.0\",\"created\":\"2019-03-27T11:01:51.023Z\"},{\"state\":\"336.2\",\"created\":\"2019-03-27T11:02:18.122Z\"},{\"state\":\"484.3\",\"created\":\"2019-03-27T11:02:24.532Z\"},{\"state\":\"543.3\",\"created\":\"2019-03-27T11:02:30.839Z\"},{\"state\":\"373.0\",\"created\":\"2019-03-27T11:02:37.351Z\"},{\"state\":\"520.3\",\"created\":\"2019-03-27T11:02:45.543Z\"},{\"state\":\"431.9\",\"created\":\"2019-03-27T11:02:51.643Z\"},{\"state\":\"334.9\",\"created\":\"2019-03-27T11:02:58.167Z\"},{\"state\":\"401.3\",\"created\":\"2019-03-27T11:03:10.939Z\"},{\"state\":\"540.8\",\"created\":\"2019-03-27T11:03:04.656Z\"},{\"state\":\"369.7\",\"created\":\"2019-03-27T11:03:38.027Z\"},{\"state\":\"538.6\",\"created\":\"2019-03-27T11:03:25.377Z\"},{\"state\":\"467.4\",\"created\":\"2019-03-27T11:03:44.460Z\"},{\"state\":\"391.9\",\"created\":\"2019-03-27T11:03:52.497Z\"},{\"state\":\"579.2\",\"created\":\"2019-03-27T11:03:59.156Z\"},{\"state\":\"579.0\",\"created\":\"2019-03-27T11:04:26.207Z\"},{\"state\":\"407.7\",\"created\":\"2019-03-27T11:04:32.663Z\"},{\"state\":\"369.4\",\"created\":\"2019-03-27T11:04:11.725Z\"},{\"state\":\"495.6\",\"created\":\"2019-03-27T11:04:18.553Z\"},{\"state\":\"576.0\",\"created\":\"2019-03-27T11:04:38.973Z\"},{\"state\":\"491.2\",\"created\":\"2019-03-27T11:04:45.344Z\"},{\"state\":\"365.7\",\"created\":\"2019-03-27T11:04:51.681Z\"},{\"state\":\"526.3\",\"created\":\"2019-03-27T11:04:59.698Z\"},{\"state\":\"468.5\",\"created\":\"2019-03-27T11:05:12.487Z\"},{\"state\":\"365.9\",\"created\":\"2019-03-27T11:05:18.918Z\"},{\"state\":\"435.9\",\"created\":\"2019-03-27T11:05:38.232Z\"},{\"state\":\"470.1\",\"created\":\"2019-03-27T11:05:25.251Z\"},{\"state\":\"573.9\",\"created\":\"2019-03-27T11:05:31.762Z\"},{\"state\":\"571.2\",\"created\":\"2019-03-27T11:05:52.525Z\"},{\"state\":\"361.4\",\"created\":\"2019-03-27T11:06:05.505Z\"},{\"state\":\"461.8\",\"created\":\"2019-03-27T11:06:11.845Z\"},{\"state\":\"556.5\",\"created\":\"2019-03-27T11:06:18.120Z\"},{\"state\":\"408.2\",\"created\":\"2019-03-27T11:06:24.581Z\"},{\"state\":\"563.8\",\"created\":\"2019-03-27T11:06:32.565Z\"},{\"state\":\"556.1\",\"created\":\"2019-03-27T11:06:51.701Z\"},{\"state\":\"388.8\",\"created\":\"2019-03-27T11:06:45.376Z\"},{\"state\":\"458.2\",\"created\":\"2019-03-27T11:06:59.676Z\"},{\"state\":\"368.6\",\"created\":\"2019-03-27T11:07:06.026Z\"}]","tot":"json"},{"t":"set","p":"eur_watio","pt":"msg","to":"0.139","tot":"num"},{"t":"set","p":"range_minutes","pt":"msg","to":"1440","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":246.5,"y":716,"wires":[["5ee6ff24.7b3d8"]]},{"id":"fa3e50f4.8a6aa","type":"comment","z":"61cc9c87.55a894","name":"Works without query","info":"","x":247.5,"y":679,"wires":[]},{"id":"316212b1.5f484e","type":"comment","z":"61cc9c87.55a894","name":"Works with query after fix payload","info":"","x":893,"y":225,"wires":[]},{"id":"7ab928fa.365f58","type":"comment","z":"61cc9c87.55a894","name":"Don't Work","info":"","x":629,"y":435,"wires":[]},{"id":"334646fb.dcff8a","type":"comment","z":"61cc9c87.55a894","name":"Don't Work","info":"","x":782,"y":492,"wires":[]},{"id":"7d271799.7d3f88","type":"postgresDB","z":"","name":"DDBB","host":"homeassistantbbdd","port":"5432","database":"homeassistant","ssl":false,"max":"10","min":1,"idle":"1000"},{"id":"7390e72a.b8f828","type":"postgresdb","z":"","hostname":"homeassistantbbdd","port":"5432","db":"homeassistant","ssl":false}]

Someone can tell me what the problem is so that it does not accept the reduced array that comes directly from the queries to the databases, and yet work perfectly once the conversion is done with the json node

0 Likes

#2

On a quick look, I would guess that your msg.payload isn't actually an array but rather is an object.

0 Likes

#3

msg.payload is and array before result node

0 Likes

#4

@TotallyInformation

Online rednode with the flow to test:
http://XXX/admin/
User: TotallyInformation
Pass: TotallyInformation

0 Likes

#5

@ElGranLoky - you realize anyone reading this thread can now access that. I would suggest you delete that post. I hope you have it backed up!

As we are all (other than Nick and Dave) just NR users like yourself, my suggestion, if you want speedy help, is to try to recreate the problem with as small a flow as possible. Like use an insert or change node to build a copy of your data, pass that to the 'Set Values' node and if it creates the problem, you can provide a small flow so people have something to look at.

Be aware, some people (myself included) may not give you the answer but point you at things you can try so you will learn to solve your own problems.

0 Likes

#6

Just to re-enforce @zenofmud's comment. Even with online access to your database, the first thing someone trying to troubleshoot your flow is likely to do is what he suggests: grab a copy of your data and try injecting it into change nodes configured in various ways.

0 Likes

#7

Thanks for the comments.

Don't worry is a clone database with old data and testing data. And the rednode is a docker container with the last version with a small part of the project.

But I think online access with a live test is a faster way to find the problem, is it?

@zenofmud Yeah "solve your own problems" I had already solved the problem, before creating the topic, in the flow you can see the part where quering to the database modifies the payload,so that works properly, but I need two more nodes that I shouldn´t need.

I can not just insert the data manually. If I do so, it will work properly, but it wouldn´t be an automatically generated array with the data in the database.

I have publish this issue not to solve the problem (because I have already solved). I publish to notify the community about a possible bug in the transformation of the message when entering in the following node.

0 Likes

#8

Or maybe you haven't taken into account that some action you took - node you used - has transformed the data...

0 Likes

#9

surely, but I do not know exactly where the transformation is made, I always pass an array in the first argument.

0 Likes

#10

I think that if you look closely, you will find that the created properties of the elements in msg.payload are date objects, not strings. Your "fix" transforms them into strings, so that the JSONata $reduce operation is able to deal with them.

1 Like

#11

@drmibell Thank you very much for the information, I assumed that reduce could manage an array of date objects without problems.

I close the connection, for the next I have learned to check the type for each object.

Thank you very much again.

1 Like