本帖最后由 hunterfox 于 2021-1-6 17:22 编辑
[{"id":"f9c98469.a771e8","type":"api-current-state","z":"a54dc4ab.4344e8","name":"小米zigbee插座","server":"2b887588.e131fa","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.plug_158d00039beb7f","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":340,"y":340,"wires":[["86e23958.5f5d48"]]},{"id":"d4d8b443.fe0948","type":"inject","z":"a54dc4ab.4344e8","name":"每日零点","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"01 00 * * *","once":false,"onceDelay":0.1,"x":150,"y":340,"wires":[["f9c98469.a771e8"]]},{"id":"86e23958.5f5d48","type":"function","z":"a54dc4ab.4344e8","name":"数据整定","func":"var time=new Date();\nvar day = time.getDate()\n//月零点冻结\n\n//当前电量\nvar nowpowr=msg.data.attributes.power_consumed;\n\nif (day==1)\n{global.set('monthpowr',nowpowr);}\n\n\n//昨日冻结数\nvar lastpower=global.get('lingdianpower'); \n//赋值 昨日电量=当前电量-昨日零点电量\nvar yespor=Number(nowpowr)-Number(lastpower);\nglobal.set('poweryestoday',yespor);\n//将今日数据写入零点数据。\nglobal.set('lingdianpower',nowpowr);\n\n// 昨日电量 poweryestoday,今日零点示数:lingdianpower\nvar msg1={};\nmsg1.payload={};\n\nmsg1.payload.poweryestoday=global.get('poweryestoday');\nmsg1.payload.lingdianpower=global.get('lingdianpower');\nmsg1.payload.monthpowr=global.get('monthpowr');\nreturn msg1;","outputs":1,"noerr":0,"x":500,"y":340,"wires":[[]]},{"id":"fe09ff50.d6902","type":"api-current-state","z":"a54dc4ab.4344e8","name":"小米zigbee插座","server":"2b887588.e131fa","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.plug_158d00039beb7f","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":280,"y":400,"wires":[["5084a563.4f113c"]]},{"id":"5084a563.4f113c","type":"function","z":"a54dc4ab.4344e8","name":"数据整定","func":"\n//当日电量\nvar nowpowr=msg.data.attributes.power_consumed-global.get('lingdianpower');\n//当月电量\nvar nowmonthpowr=msg.data.attributes.power_consumed-global.get('monthpowr');\n//昨日电量\n\nvar msg1={}; //当日\nmsg1.payload=nowpowr/1000;\nmsg1.topic=\"a/sensor/xiaomi_kwh_today/home/state\";\nvar msg2={}; //当月\nmsg2.payload=nowmonthpowr/1000;\nmsg2.topic=\"a/sensor/xiaomi_kwh_month/home/state\";\nvar msg3={}; //昨日\nvar ss=Number(global.get('poweryestoday'));\nmsg3.payload=ss/1000;\nmsg3.topic=\"a/sensor/xiaomi_kwh/home/state\";\nreturn [msg1,msg2,msg3];","outputs":3,"noerr":0,"x":440,"y":400,"wires":[["a56ac618.2a2c18"],["a56ac618.2a2c18"],["a56ac618.2a2c18"]]},{"id":"a56ac618.2a2c18","type":"mqtt out","z":"a54dc4ab.4344e8","name":"","topic":"","qos":"","retain":"","broker":"37541fbf.c8804","x":600,"y":400,"wires":[]},{"id":"e14b6a29.699b98","type":"inject","z":"a54dc4ab.4344e8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":420,"wires":[["fe09ff50.d6902"]]},{"id":"2b887588.e131fa","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"37541fbf.c8804","type":"mqtt-broker","z":"","name":"MY_MQTT","broker":"192.168.1.188","port":"1883","clientid":"Node_RED","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}] |