[{"id":"38074e40.591192","type":"tab","label":"流程4","disabled":false,"info":""},{"id":"8f371818.f4c0e8","type":"api-current-state","z":"38074e40.591192","name":"获取月度用电","server":"a21ccefa.edc7e","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.monthelectricity","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_month","override_data":"msg","blockInputOverrides":false,"x":320,"y":300,"wires":[["a1d9172b.9e23e8"]]},{"id":"a1d9172b.9e23e8","type":"api-current-state","z":"38074e40.591192","name":"获取年度用电","server":"a21ccefa.edc7e","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.yearelectricity","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_year","override_data":"msg","blockInputOverrides":false,"x":580,"y":300,"wires":[["b22ce339.d3c9c"]]},{"id":"b22ce339.d3c9c","type":"function","z":"38074e40.591192","name":"计算阶梯用电","func":"let fup = 0;\nlet sup = 0;\nlet tu = 0;\nlet month_used = msg.data_month.attributes.f+msg.data_month.attributes.g;\nif(msg.data_year.attributes.firstused==msg.data_year.attributes.firsttotal){\n fup = 100;\n}else if((msg.data_year.attributes.firstused+month_used)>=msg.data_year.attributes.firsttotal){\n fup = 100;\n month_used = msg.data_year.attributes.firsttotal-Number(msg.data_year.attributes.firstused);\n}else{\n fup = (msg.data_year.attributes.firstused+month_used)/msg.data_year.attributes.firsttotal;\n month_used = 0;\n}\n\nif(msg.data_year.attributes.secondused==msg.data_year.attributes.secondtotal){\n sup = 100;\n}else if((msg.data_year.attributes.secondused+month_used)>=msg.data_year.attributes.secondtotal){\n sup = 100;\n month_used = msg.data_year.attributes.secondtotal-msg.data_year.attributes.secondused;\n}else{\n sup = (((msg.data_year.attributes.secondused+month_used))/Number(msg.data_year.attributes.secondtotal));\n month_used = 0;\n}\n\nif(month_used>0){\n tu = month_used;\n}\n\nmsg.fup = fup;\nmsg.sup = sup;\nmsg.tu = tu;\n\n\n\nmsg.payload = null;\n\nreturn msg;","outputs":1,"noerr":0,"x":960,"y":300,"wires":[["3631a5d7.06c3da","6c3024de.9a75fc","42863031.ccb23"]]},{"id":"b11f9546.23b168","type":"inject","z":"38074e40.591192","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"02 07 * * *","once":false,"onceDelay":0.1,"x":100,"y":300,"wires":[["8f371818.f4c0e8"]]},{"id":"6c3024de.9a75fc","type":"ha-entity","z":"38074e40.591192","name":"第一阶梯用电","server":"a21ccefa.edc7e","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"electricity_first"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"%"}],"state":"fup","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1340,"y":300,"wires":[[]]},{"id":"3631a5d7.06c3da","type":"ha-entity","z":"38074e40.591192","name":"第二阶梯用电","server":"a21ccefa.edc7e","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"electricity_second"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"%"}],"state":"sup","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1340,"y":360,"wires":[[]]},{"id":"42863031.ccb23","type":"ha-entity","z":"38074e40.591192","name":"第三阶梯用电","server":"a21ccefa.edc7e","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"electricity_third"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"度"}],"state":"tu","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1340,"y":420,"wires":[[]]},{"id":"a21ccefa.edc7e","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]