I’m trying to get the amount of kWh
consumed by my smart plug, my database is MySQL, I’m sending to my zabbix server (which uses MySQLdatabase) the power consumption in watts every minute.
ex:
SELECT FROM_UNIXTIME(clock) as ts, value FROM history WHERE itemid=54339
2024-03-17 21:36:40 261
2024-03-17 21:37:39 271
2024-03-17 21:38:40 271
2024-03-17 21:39:40 268
2024-03-17 21:40:39 264
So if i wanted to calculate the kWh
- consumption per hour
- consumption per day
- consumption per month
- consumption per year
How could i achieve this with MySQL queries?
2
Answers
Consumption per hour:
Per month you will have to concat year and month or select in separated columns:
Totals by several periods WITH ROLLUP.
See example
Output like this
demo