Hi. I have energy meter Eastron SDM220. I want to build graphs of electricity consumption in day and night time.
Write rule.
rule "Energy by hour"
when
Time cron "0 0 * * * ?"
then
var hour = CounterkWh.state as DecimalType - CounterkWh.historicState(now.minusHours(1), "mysql":).state as DecimalType
//the designated time bands
if(now.getHourOfDay > 7 && now.getHourOfDay < 23)
{
logInfo("TEST","sdm220_hourcounter_day = "+hour)
postUpdate(sdm220_hourcounter_day, hour)
}
else
{
//on the border ranges to add zero values in chart
//as in table as primary key timestamp is used between additions of the data in the same table it's worth pausing one second
if(now.getHourOfDay==7)
{
postUpdate(sdm220_hourcounter_night, hour)
Thread::sleep(2000)
postUpdate(sdm220_hourcounter_night, 0)
Thread::sleep(2000)
postUpdate(sdm220_hourcounter_day, 0)
Thread::sleep(2000)
postUpdate(sdm220_hourcounter_day, hour)
}
else if(now.getHourOfDay==23)
{
postUpdate(sdm220_hourcounter_day, hour)
Thread::sleep(2000)
postUpdate(sdm220_hourcounter_day, 0)
Thread::sleep(2000)
postUpdate(sdm220_hourcounter_night, 0)
Thread::sleep(2000)
postUpdate(sdm220_hourcounter_night, hour)
}
else
{
postUpdate(sdm220_hourcounter_night, hour)
}
}
postUpdate(sdm220_hourcounter, hour)
end
But it works incorrect. The graph should look like this
I have this
In database following values from sdm220_hourcounter_day are written
| 2017-06-19 23:00:00 | 0.27203369140625 |
| 2017-06-19 23:00:02 | 0 |
| 2017-06-20 07:00:06 | 0.21600341796875 |
| 2017-06-20 08:00:00 | 0.2760009765625 |
| 2017-06-20 09:00:00 | 0.2869873046875 |
| 2017-06-20 10:00:00 | 0.26800537109375 |
| 2017-06-20 11:00:00 | 0.281982421875 |
| 2017-06-20 12:00:00 | 0.60797119140625 |
| 2017-06-20 13:00:00 | 0.2740478515625 |
| 2017-06-20 14:00:00 | 0.60296630859375 |
| 2017-06-20 15:00:01 | 0.2540283203125 |
| 2017-06-20 16:00:00 | 0.23199462890625 |
| 2017-06-20 17:00:00 | 0.22198486328125 |
| 2017-06-20 18:00:00 | 0.22900390625 |
| 2017-06-20 19:00:00 | 0.2540283203125 |
| 2017-06-20 20:00:00 | 0.30596923828125 |
| 2017-06-20 21:00:00 | 0.2769775390625 |
| 2017-06-20 22:00:00 | 0.26104736328125 |
| 2017-06-20 23:00:00 | 0.27294921875 |
| 2017-06-20 23:00:02 | 0 |
| 2017-06-21 07:00:06 | 0.2969970703125 |
And from sdm220_hourcounter_night value
| 2017-06-19 07:00:00 | 0.19097900390625 |
| 2017-06-19 07:00:02 | 0 |
| 2017-06-19 23:00:06 | 0.27203369140625 |
| 2017-06-20 00:00:00 | 0.2650146484375 |
| 2017-06-20 01:00:00 | 0.23297119140625 |
| 2017-06-20 02:00:00 | 0.2239990234375 |
| 2017-06-20 03:00:00 | 0.218994140625 |
| 2017-06-20 04:00:00 | 0.2120361328125 |
| 2017-06-20 05:00:00 | 0.24896240234375 |
| 2017-06-20 06:00:00 | 0.23004150390625 |
| 2017-06-20 07:00:00 | 0.21600341796875 |
| 2017-06-20 07:00:02 | 0 |
| 2017-06-20 23:00:06 | 0.27294921875 |
At 7 a.m. and 23 p.m. there should be one more zero value.
What am I doing wrong?