First flow on all my RPIs

another update:
I added sunrise and sunset as well as day and night duration.
The data is stored in global variables at 2 min past midnight
If you are going to use it don't forget to change the coordinates in CronPlus

[{"id":"6d124ca2da58ee9f","type":"group","z":"5d5731ac89f86d92","name":"sunrise-sunset-day-night","style":{"label":true,"fill":"#ffefbf","fill-opacity":"0.18"},"nodes":["ddc204b9b74b46ab","87cd74d6b567985e","ecbdde3890befc33","846b05c9700bf24b","490e7c5b1133637b","a23687c1594a4c34","f44f87a774ff5190","b05d8fc1eba5f1aa","19c90b73105bc945","309f9dc9691ecaba","8e8a6a45d83c3474","7f6c8e7146fbc56e","6fbdf85639ef4f85"],"x":74,"y":1539,"w":1642,"h":162},{"id":"ddc204b9b74b46ab","type":"inject","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"at 00:02","props":[{"p":"payload"}],"repeat":"","crontab":"01 00 * * *","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":180,"y":1620,"wires":[["87cd74d6b567985e"]]},{"id":"87cd74d6b567985e","type":"function","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"solarEvents","func":"msg.payload = {\"command\":\"describe\",\n               \"location\":\"48.38157356491496 10.437845885753632\",\n               \"timeZone\":\"Europe/Berlin\",\n               \"expressionType\":\"solar\",\n               \"solarType\":\"selected\",\n               \"solarEvents\":\"sunrise,sunset\"\n              };\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":1620,"wires":[["846b05c9700bf24b"]]},{"id":"ecbdde3890befc33","type":"switch","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"","property":"payload.command.command","propertyType":"msg","rules":[{"t":"eq","v":"describe","vt":"str"},{"t":"eq","v":"status-all","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":710,"y":1620,"wires":[["490e7c5b1133637b"],[]]},{"id":"846b05c9700bf24b","type":"cronplus","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"sunrise-sunset-day-night","outputField":"payload","timeZone":"","storeName":"","commandResponseMsgOutput":"output1","defaultLocation":"48.38157356491496 10.437845885753632","defaultLocationType":"default","outputs":1,"options":[],"x":530,"y":1620,"wires":[["ecbdde3890befc33"]]},{"id":"490e7c5b1133637b","type":"function","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"get sr + ss items","func":"\nvar sunrise = msg.payload.result.eventTimes.find(e => {\n    return e.event == \"sunrise\"\n})\n\nvar sunset = msg.payload.result.eventTimes.find(e => {\n    return e.event == \"sunset\"\n})\n\nmsg.payload = {\n    sunrise : sunrise.time,\n    sunset : sunset.time\n}\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":860,"y":1620,"wires":[["a23687c1594a4c34","b05d8fc1eba5f1aa","19c90b73105bc945"]]},{"id":"a23687c1594a4c34","type":"change","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"sunrise-sunset difference","rules":[{"t":"set","p":"payload","pt":"msg","to":"  $moment($$.payload.sunset).diff($moment($$.payload.sunrise), \"seconds\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":1660,"wires":[["f44f87a774ff5190"]]},{"id":"f44f87a774ff5190","type":"function","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"day & night duration","func":"const day = 60*60*24;\nlet tag = msg.payload;\nlet nacht = day - tag;\nlet nacht_total = duration_str(nacht);\nlet tag_total = duration_str(tag);\n//msg.payload = \"Tag: \" + tag_total + \" / \" + \"Nacht: \" + nacht_total;\nglobal.set('day', tag_total );\nglobal.set('night', nacht_total);\nreturn {payload: Date.now()};\n\n//------------------------------------------------------------------\n\nfunction duration_str(sec) {\n    const t = sec;\n    const h = (Math.floor(t / 3600)).toString();\n    const m = (Math.floor(t % 3600 / 60)).toString();\n//    let s = (Math.floor(t % 3600 % 60)).toString();\n//    let r = h + \":\" + (\"0\" + m).slice(-2) + \":\" + (\"0\" + s).slice(-2);\n    return (h + \":\" + (\"0\" + m).slice(-2));\n}\n\n//------------------------------------------------------------------","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1360,"y":1660,"wires":[["309f9dc9691ecaba"]]},{"id":"b05d8fc1eba5f1aa","type":"function","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"sunrise","func":"let sunrise = date_time_string(msg.payload.sunrise);\nglobal.set('sunrise', sunrise);\nreturn{payload:msg.payload.sunrise}\n\nfunction date_time_string(t) {\n    const date = new Date(t);\n    const day = date.getDate().toString().padStart(2, '0');\n    const month = (date.getMonth() + 1).toString().padStart(2, '0');\n    const year = date.getFullYear().toString();\n    const hours = date.getHours().toString().padStart(2, '0');\n    const minutes = date.getMinutes().toString().padStart(2, '0');\n    const seconds = date.getSeconds().toString().padStart(2, '0');\n    return `${hours}:${minutes}`;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1080,"y":1580,"wires":[["7f6c8e7146fbc56e"]]},{"id":"19c90b73105bc945","type":"function","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"sunset","func":"let sunset = date_time_string(msg.payload.sunset);\nglobal.set('sunset', sunset);\nreturn{payload:msg.payload.sunset};\n\nfunction date_time_string(t) {\n    const date = new Date(t);\n    const day = date.getDate().toString().padStart(2, '0');\n    const month = (date.getMonth() + 1).toString().padStart(2, '0');\n    const year = date.getFullYear().toString();\n    const hours = date.getHours().toString().padStart(2, '0');\n    const minutes = date.getMinutes().toString().padStart(2, '0');\n    const seconds = date.getSeconds().toString().padStart(2, '0');\n    return `${hours}:${minutes}`;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1070,"y":1620,"wires":[["6fbdf85639ef4f85"]]},{"id":"309f9dc9691ecaba","type":"delay","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1560,"y":1660,"wires":[["8e8a6a45d83c3474"]]},{"id":"8e8a6a45d83c3474","type":"link out","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"sun-data-out","mode":"link","links":["950da9e6221c062b"],"x":1675,"y":1660,"wires":[]},{"id":"7f6c8e7146fbc56e","type":"link out","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"sunrise-out","mode":"link","links":[],"x":1175,"y":1580,"wires":[]},{"id":"6fbdf85639ef4f85","type":"link out","z":"5d5731ac89f86d92","g":"6d124ca2da58ee9f","name":"sunset-out","mode":"link","links":[],"x":1175,"y":1620,"wires":[]}]
1 Like

I found a better way to read the temperature of an RPI.
It does not use an exec-node which means no extra process to start
image

[{"id":"315e79e764cc2acc","type":"file in","z":"2fa67f563face78f","g":"11cf27f032a07d3c","name":"temp","filename":"/sys/class/thermal/thermal_zone0/temp","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":330,"y":2520,"wires":[["d92dde09b7d986bd"]]},{"id":"b51971924d6309ed","type":"inject","z":"2fa67f563face78f","g":"11cf27f032a07d3c","name":"jede Minute","props":[{"p":"payload"}],"repeat":"60","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":190,"y":2520,"wires":[["315e79e764cc2acc"]]},{"id":"d92dde09b7d986bd","type":"function","z":"2fa67f563face78f","g":"11cf27f032a07d3c","name":"function 66","func":"let temp = parseInt(msg.payload) / 1000;\nstatus(temp);\nreturn null;\n\nfunction status(data){\n    let time = new Date(Date.now()).toLocaleTimeString('de-DE');\n    node.status({ fill: \"green\", shape: \"dot\", text: (time + \" | \" + data + \"°C\") }); \n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":2520,"wires":[[]]}]

You could also use this node:

It offers lots of information.

It looks great but this is overkill for what I wanted to achieve in my first flow..

It is just a file read to get the temp. Very light and efficient small code.

You can tell the node which items you want to get. So if you only want temperature you can get it. Here is an example:

[{"id":"4b03b0a59a8e4025","type":"debug","z":"67bc9adc42873b77","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":100,"wires":[]}]

The node gives you options to get other information without having to write the code in a function node.

But you can choose to do it any way you want. Happy New Year!

Started as a small project [...], it now has > 15,000 lines of code, > 600 versions published, up to 8 mio downloads per month, > 220 mio downloads overall. #1 NPM ranking for backend packages .

I don't need 15000 lines of code to get the temperature. :wink:

I wish you a happy new year as well and let's stay in touch in this awesome forum.

Hannes