[{"id":"dc70049.c7886f8","type":"change","z":"ab22dd27.5356f","name":"查询12个月电费数据","rules":[{"t":"set","p":"topic","pt":"msg","to":"SELECT DATE_FORMAT(last_updated, '%Y-%m') months, MAX(state+0) FROM (SELECT * FROM states WHERE entity_id='sensor.ddsd720_l_total_cost' AND DATE_FORMAT(last_updated, "%H") = 15) a GROUP BY DATE_FORMAT(last_updated, '%Y-%m');","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":1640,"wires":[["92be10.53cda1f"]]},{"id":"92be10.53cda1f","type":"mysql","z":"ab22dd27.5356f","mydb":"f1a53946.8f9908","name":"","x":470,"y":1640,"wires":[["1b79c901.821db7"]]},{"id":"1b79c901.821db7","type":"function","z":"ab22dd27.5356f","name":"字段翻译","func":"// 日期格式化 Function \nDate.prototype.Format = function (fmt) {\n var o = {\n "y+": this.getFullYear(),\n "M+": this.getMonth() + 1, //月份\n "d+": this.getDate(), //日\n "h+": this.getHours(), //小时\n "m+": this.getMinutes(), //分\n "s+": this.getSeconds(), //秒\n "q+": Math.floor((this.getMonth() + 3) / 3), //季度\n "S+": this.getMilliseconds() //毫秒\n };\n for (var k in o) {\n if (new RegExp("(" + k + ")").test(fmt)){\n if(k == "y+"){\n fmt = fmt.replace(RegExp.$1, ("" + o[k]).substr(4 - RegExp.$1.length));\n }\n else if(k=="S+"){\n var lens = RegExp.$1.length;\n lens = lens==1?3:lens;\n fmt = fmt.replace(RegExp.$1, ("00" + o[k]).substr(("" + o[k]).length - 1,lens));\n }\n else{\n fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));\n }\n }\n }\n return fmt;\n}\n\nvar arr=msg.payload\nvar time=[]\nvar states=[]\nfor (var i in arr){\n var date=new Date(Date.parse(arr[i].months))\n time.push(date.getTime())\n states.push(arr[i]['MAX(state+0)'])\n}\nmsg.payload={\n "attributes":{"time":time,"states":states},\n "status":"ok"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1640,"wires":[["5d68f0b7.91c6b"]]},{"id":"db027ecb.9ee06","type":"http in","z":"ab22dd27.5356f","name":"获取12个月电费","url":"/get_12m_cost","method":"get","upload":false,"swaggerDoc":"","x":80,"y":1640,"wires":[["dc70049.c7886f8"]]},{"id":"5d68f0b7.91c6b","type":"http response","z":"ab22dd27.5356f","name":"","statusCode":"200","headers":{},"x":800,"y":1640,"wires":[]},{"id":"f1a53946.8f9908","type":"MySQLdatabase","name":"HASS","host":"core-mariadb","port":"3306","db":"homeassistant","tz":"UTC"}]