Monthly inject

320 views
Skip to first unread message

David Caparrós

unread,
Jul 4, 2017, 2:06:33 PM7/4/17
to Node-RED
Good afternoon,

I'm trying to collect data for a power consumption on a easy way just to be shown on a chart on node red.

I try to get a report on the average per day, one per week an one per month.

Per day and week was easy just doing a inject a specific time a day to enable reading and inject to disable one minute later and at that time resetting the average however to get this done monthly I find the problem that inject longer period of time is once per week and I can not do it every 4 weeks or every specific day of the month (what should be great) and now I'm wonder if someone did already something like this and can bring me some idea.

The flow I did for day and week is:

[{"id":"b61f55fb.64fec8","type":"average","z":"aa1ac307.b2cbd","name":"","topic":"","x":340,"y":840,"wires":[["45f21625.37a828","db9084cf.a88288"]]},{"id":"93230056.24fcb","type":"inject","z":"aa1ac307.b2cbd","name":"","topic":"","payload":"msg.reset","payloadType":"str","repeat":"","crontab":"00 00 * * *","once":false,"x":130,"y":840,"wires":[["b61f55fb.64fec8"]]},{"id":"45f21625.37a828","type":"switch","z":"aa1ac307.b2cbd","name":"diario","property":"medida_diaria","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","outputs":1,"x":510,"y":840,"wires":[["38466dc4.989882"]]},{"id":"ddd2cb39.396ab8","type":"inject","z":"aa1ac307.b2cbd","name":"activar lectura","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"58 23 * * *","once":false,"x":140,"y":900,"wires":[["5cd7c879.b78038"]]},{"id":"5cd7c879.b78038","type":"change","z":"aa1ac307.b2cbd","name":"","rules":[{"t":"set","p":"medida_diaria","pt":"flow","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":900,"wires":[[]]},{"id":"38466dc4.989882","type":"delay","z":"aa1ac307.b2cbd","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"3","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":680,"y":840,"wires":[["77efc366.c3715c"]]},{"id":"bce5d0c4.3de43","type":"change","z":"aa1ac307.b2cbd","name":"","rules":[{"t":"set","p":"medida_diaria","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":940,"wires":[[]]},{"id":"43ca2de7.2d53b4","type":"inject","z":"aa1ac307.b2cbd","name":"desactivar lectura","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"59 23 * * *","once":false,"x":150,"y":940,"wires":[["bce5d0c4.3de43"]]},{"id":"77efc366.c3715c","type":"function","z":"aa1ac307.b2cbd","name":"custom function","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar temp = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\ntemp = parseFloat(originalval/1000).toFixed(1) ;\n\n// output the originalval after deduction \nmsg.payload = temp;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":880,"y":840,"wires":[["14a0e538.be052b"]]},{"id":"20cfa3bd.47496c","type":"ui_gauge","z":"aa1ac307.b2cbd","name":"","group":"2ebc9347.9cd16c","order":0,"width":0,"height":0,"gtype":"gage","title":"Valor Promedio diario acumulado","label":"KWh","format":"{{value}}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1040,"y":900,"wires":[]},{"id":"14a0e538.be052b","type":"ui_chart","z":"aa1ac307.b2cbd","name":"consumo diario","group":"2ebc9347.9cd16c","order":0,"width":0,"height":0,"label":"Consumo diario","chartType":"bar","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","ymin":"0","ymax":"10","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"x":1100,"y":840,"wires":[[],[]]},{"id":"17e62a98.a36e75","type":"average","z":"aa1ac307.b2cbd","name":"","topic":"","x":320,"y":1100,"wires":[["3d3f567b.e5b2ba","e878bf3.b6b014"]]},{"id":"90ad3cc9.480cb","type":"inject","z":"aa1ac307.b2cbd","name":"","topic":"","payload":"msg.reset","payloadType":"str","repeat":"","crontab":"00 00 * * 1","once":false,"x":110,"y":1100,"wires":[["17e62a98.a36e75"]]},{"id":"3d3f567b.e5b2ba","type":"switch","z":"aa1ac307.b2cbd","name":"semanal","property":"medida_semanal","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","outputs":1,"x":500,"y":1100,"wires":[["726ecc07.83b394"]]},{"id":"490aeb72.305d24","type":"inject","z":"aa1ac307.b2cbd","name":"activar lectura","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"58 23 * * 0","once":false,"x":120,"y":1160,"wires":[["c2f62a95.03aa88"]]},{"id":"c2f62a95.03aa88","type":"change","z":"aa1ac307.b2cbd","name":"","rules":[{"t":"set","p":"medida_semanal","pt":"flow","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":1160,"wires":[[]]},{"id":"726ecc07.83b394","type":"delay","z":"aa1ac307.b2cbd","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"3","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":660,"y":1100,"wires":[["b639912b.e21e7"]]},{"id":"39ec2129.d64abe","type":"change","z":"aa1ac307.b2cbd","name":"","rules":[{"t":"set","p":"medida_semanal","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":1200,"wires":[[]]},{"id":"598c28e3.c78f58","type":"inject","z":"aa1ac307.b2cbd","name":"desactivar lectura","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"59 23 * * 0","once":false,"x":130,"y":1200,"wires":[["39ec2129.d64abe"]]},{"id":"b639912b.e21e7","type":"function","z":"aa1ac307.b2cbd","name":"custom function","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar temp = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\ntemp = parseFloat(originalval/1000).toFixed(1) ;\n\n// output the originalval after deduction \nmsg.payload = temp;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":860,"y":1100,"wires":[["a011351e.2d7538"]]},{"id":"c50efd08.607bc","type":"ui_gauge","z":"aa1ac307.b2cbd","name":"","group":"2ebc9347.9cd16c","order":0,"width":0,"height":0,"gtype":"gage","title":"Valor Promedio semanal acumulado","label":"KWh","format":"{{value}}","min":0,"max":"75","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1030,"y":1160,"wires":[]},{"id":"a011351e.2d7538","type":"ui_chart","z":"aa1ac307.b2cbd","name":"Consumo semanal","group":"2ebc9347.9cd16c","order":0,"width":0,"height":0,"label":"Consumo semanal","chartType":"bar","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","ymin":"0","ymax":"100","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"x":1090,"y":1100,"wires":[[],[]]},{"id":"576eebf2.e54cb4","type":"comment","z":"aa1ac307.b2cbd","name":"consumo diario","info":"","x":160,"y":780,"wires":[]},{"id":"21f3c894.e69c88","type":"comment","z":"aa1ac307.b2cbd","name":"consumo semanal","info":"","x":200,"y":1040,"wires":[]},{"id":"e878bf3.b6b014","type":"function","z":"aa1ac307.b2cbd","name":"custom function","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar temp = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\ntemp = parseFloat(originalval/1000).toFixed(1) ;\n\n// output the originalval after deduction \nmsg.payload = temp;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":740,"y":1160,"wires":[["c50efd08.607bc"]]},{"id":"db9084cf.a88288","type":"function","z":"aa1ac307.b2cbd","name":"custom function","func":"// declare place holder variables\nvar originalval = msg.payload;\nvar temp = \"\";\n\n\n// convert string of originalval to float with 1 decimal place\n// run originalval thru a simple minus operation to form the 'temp' number\ntemp = parseFloat(originalval/1000).toFixed(1) ;\n\n// output the originalval after deduction \nmsg.payload = temp;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":760,"y":900,"wires":[["20cfa3bd.47496c"]]},{"id":"2ebc9347.9cd16c","type":"ui_group","z":"","name":"Consumo","tab":"49f882f0.c51aec","order":1,"disp":true,"width":"6"},{"id":"49f882f0.c51aec","type":"ui_tab","z":"","name":"CONSUMO","icon":"fa-plug","order":6}]


Any sugegstion considering my knowledge is very limited is welcome.

Thanks in advance
Screen Shot 07-04-17 at 08.04 PM.PNG

David Caparrós

unread,
Jul 4, 2017, 2:12:40 PM7/4/17
to Node-RED

I just realized this is a bit stupid I have to move to a SQL or excel or will lose the data on every deploy.....I will have to study a bit to do something with more sense.

Thanks anyway

Mark Setrem

unread,
Jul 4, 2017, 2:47:38 PM7/4/17
to Node-RED
if you haven't already seen it, it might be worth taking a look at http://openenergymonitor.org their emoncms software works well with node-red

David Caparrós

unread,
Jul 4, 2017, 2:58:20 PM7/4/17
to Node-RED
Thanks Mark,

I read a lot about this but at the end I made my own power measurement module with a ESP module programmed with arduino and a clamp meter, total cost around 10$ including power supply and cable and I transmit the values trough MQTT, now I have only pending the part of storing and logging the data on long therms, I will have to study a bit about google spreadsheets or SQL.

I'm looking for some examples and tutorials now.

Regards

David Caparrós

unread,
Jul 4, 2017, 3:02:30 PM7/4/17
to Node-RED
Just some data management and integration with node-red I didn't know that, I'm going to investigate maybe I will save time for now and run away from SQL hahaha.

Thanks mate


El martes, 4 de julio de 2017, 20:47:38 (UTC+2), Mark Setrem escribió:

Colin Law

unread,
Jul 4, 2017, 3:07:54 PM7/4/17
to node...@googlegroups.com
If you want to record time series data and graph it then have a look
at influx db and grafana. They work very well using node red to put
the data into the db.

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/b5fb9272-0685-47ab-a5df-49977b0cd69c%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Petar Georgiev

unread,
Jul 5, 2017, 10:29:33 AM7/5/17
to Node-RED
Btw I'm currently logging all my feeds' data to MySql. I created a subflow that calculates SUM of all datapoints for "now() - 1 month". In my case I'm measuring watermeter's consumption. You can change it with AVG:

[{"id":"a4efb4b2.f8cd48","type":"function","z":"99c7790c.8a6f28","name":"Prepare SQL query","func":"\nvar d = new Date();\nvar m = d.getMonth();\nd.setMonth(d.getMonth() - 1);\n\n// If still in same month, set date to last day of \n// previous month\nif (d.getMonth() == m) d.setDate(0);\nd.setHours(0, 0, 0);\nd.setMilliseconds(0);\n\n\n\n\nmsg.key = msg.topic;\nmsg.topic = \"SELECT SUM(CAST(fd.`Value` as DECIMAL(10,2))) as value FROM `feeds` f INNER JOIN `feedsdata` fd on f.Id = fd.`FeedId` WHERE f.`Name` = '\" + msg.key + \"' AND fd.`DateTime` >= '\" + d.toISOString() + \"' \";\n//msg.payload = obj;\n\n\n\nreturn msg;","outputs":1,"noerr":0,"x":209,"y":192.60000944137573,"wires":[["c8554118.88a61"]]},{"id":"c8554118.88a61","type":"mysql","z":"99c7790c.8a6f28","mydb":"deb25814.dba388","name":"","x":200.0000762939453,"y":276.4000005722046,"wires":[["acf8e4cb.ed3ec8"]]},{"id":"acf8e4cb.ed3ec8","type":"function","z":"99c7790c.8a6f28","name":"Parse results","func":"msg.payload = msg.payload[0].value;\n\nreturn msg;","outputs":1,"noerr":0,"x":199.00006866455078,"y":359.2000513076782,"wires":[[]]},{"id":"deb25814.dba388","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"automation","tz":""}]

* The SQL tables and query need improvement: feed values are stored as string, and SQL query should use parameters.

David Caparrós

unread,
Jul 5, 2017, 1:52:07 PM7/5/17
to Node-RED

Thanks you guys I think I need to investigate a little bit more first, for the moment the question I have is.... how can I inject monthly?  The standard inject module allow only per day of the week as max.

Regards

Mark Setrem

unread,
Jul 5, 2017, 3:15:51 PM7/5/17
to Node-RED
What do you mean by monthly? is it every 4 weeks i.e 13 months in a year which would allow you to compare usage more effectively, or a calendar month?
either way you could set the inject node to trigger daily and then have a function node to check if it's the first day of the "month" and only pass on a message if it is.

Max Hadley

unread,
Jul 5, 2017, 4:45:00 PM7/5/17
to Node-RED
Use an inject node to send a message once per day, followed by a function node that checks if the current day == 1, and only passes the message on if it is

Max

David Caparrós

unread,
Jul 5, 2017, 5:00:40 PM7/5/17
to Node-RED

Thank you guys, I found the what for me was the easiest solution, there is a node that uses "cron" from linux, with this is really simple to schedule any inject on demand.

Regards
Reply all
Reply to author
Forward
0 new messages