CommentStreams:Dca7417f135684cc8f8674f25160e1c2

For Geeworm UPS HAT:

Here is my flow in node-red for reading the battery voltage and capacity as well as fan speed and power status.

Required nodes:

node-red-contrib-buffer-parser

node-red-contrib-i2c

node-red-node-pi-gpio

[{"id":"b6e375dca488451c","type":"rpi-gpio in","z":"4f0f7e9b873ed151","name":"GPIO6 AC-Power","pin":"6","intype":"tri","debounce":"25","read":false,"bcm":true,"x":230,"y":1290,"wires":[["2e6d1c8dd9466d21"]]},{"id":"9153e12fa19c8a01","type":"comment","z":"4f0f7e9b873ed151","name":"Raspi4 GPIO6 Power-Status","info":"","x":190,"y":1240,"wires":[]},{"id":"2e6d1c8dd9466d21","type":"change","z":"4f0f7e9b873ed151","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"Stromausfall","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"Power OK","tot":"str"},{"t":"move","p":"payload","pt":"msg","to":"statustext","tot":"msg"},{"t":"set","p":"location","pt":"msg","to":"Raspi 4 ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":1290,"wires":[["b161f6101e10d6e1","b9e74652d1f4361e"]]},{"id":"74050275ae9b637f","type":"i2c scan","z":"4f0f7e9b873ed151","name":"","busno":"1","x":410,"y":1170,"wires":[[],["c89c48fb592feec1"]]},{"id":"5e202a022d0a2c9b","type":"inject","z":"4f0f7e9b873ed151","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":1170,"wires":[["74050275ae9b637f"]]},{"id":"c89c48fb592feec1","type":"debug","z":"4f0f7e9b873ed151","name":"I2C-Scan","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":570,"y":1170,"wires":[]},{"id":"59b8bddf8ad93388","type":"rpi-gpio in","z":"4f0f7e9b873ed151","name":"GPIO16","pin":"16","intype":"tri","debounce":"25","read":false,"bcm":true,"x":210,"y":1570,"wires":[["d23af81852163f35"]]},{"id":"ff66b95250fe7ee3","type":"comment","z":"4f0f7e9b873ed151","name":"Raspi4 GPIO16 fan speed: 1 => fast, 0 => slow ","info":"","x":250,"y":1520,"wires":[]},{"id":"c2201db341984359","type":"i2c in","z":"4f0f7e9b873ed151","name":"","busno":"1","address":"54","command":"","count":"2","x":510,"y":1430,"wires":[["62a377fb8b7c616f"]]},{"id":"62a377fb8b7c616f","type":"buffer-parser","z":"4f0f7e9b873ed151","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint16le","name":"result","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"swap16","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":660,"y":1430,"wires":[["93c23bb720a9407c"]]},{"id":"93c23bb720a9407c","type":"function","z":"4f0f7e9b873ed151","name":"","func":"var result = Number (msg.payload.result);\n\nmsg.payload = {};\nif (msg.command == 2) {\n    msg.payload.voltage = Number ((result * 78.125 / 1000000).toFixed(2));\n    node.status({fill:\"green\",shape:\"dot\",text: \"voltage: \" + msg.payload.voltage + \" V,\"})\n}\n\nif (msg.command == 4) {\n    msg.payload.capacity = Number((result /256).toFixed(1));\n    if (msg.payload.capacity > 100){\n        msg.payload.capacity = 100\n    }\n    node.status({fill:\"green\",shape:\"dot\",text: \"capacity: \" + msg.payload.capacity + \" %\"})\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":1430,"wires":[["1a9cac3985983151"]]},{"id":"dc01f23d42cf45bd","type":"inject","z":"4f0f7e9b873ed151","name":"voltage: msg.command = > 2","props":[{"p":"command","v":"2","vt":"num"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":290,"y":1410,"wires":[["c2201db341984359"]]},{"id":"ae2b5963a5f78976","type":"inject","z":"4f0f7e9b873ed151","name":"capacity: msg.command => 4","props":[{"p":"command","v":"4","vt":"num"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":300,"y":1450,"wires":[["c2201db341984359"]]},{"id":"1a9cac3985983151","type":"debug","z":"4f0f7e9b873ed151","name":"battery","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":960,"y":1430,"wires":[]},{"id":"d23af81852163f35","type":"function","z":"4f0f7e9b873ed151","name":"","func":"if (msg.payload == 1) {\n    msg.payload = \"fan speed: fast\"\n    node.status({fill:\"red\",shape:\"dot\",text: msg.payload})\n}\n\nif (msg.payload == 0) {\n    msg.payload = \"fan speed: slow\"\n    node.status({fill:\"green\",shape:\"dot\",text: msg.payload})\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":1570,"wires":[["6c72a981c041ee07"]]},{"id":"85351224cc71914a","type":"comment","z":"4f0f7e9b873ed151","name":"Raspi4 read votage/capacity","info":"","x":190,"y":1360,"wires":[]},{"id":"e8bb816803904e9e","type":"comment","z":"4f0f7e9b873ed151","name":"I2C Bus scan","info":"","x":140,"y":1120,"wires":[]},{"id":"6c72a981c041ee07","type":"debug","z":"4f0f7e9b873ed151","name":"fan speed","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":520,"y":1570,"wires":[]},{"id":"b9e74652d1f4361e","type":"debug","z":"4f0f7e9b873ed151","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"statustext","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":1290,"wires":[]}]<!-- migrated from Comments; original IP: 185.5.46.73 -->