I have 3 rules running in order to calculate Gas, Energy Consumption and Energy Production. These rules worked fine in OH3 until 3.1.0M3 and M4. I had to downgrade back to M2 in order to get the rules working again. The Openhab log shows the following errors:
2021-05-05 16:10:00.130 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-05 16:10:00.185 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-05 16:10:00.186 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'PowerConsumptionPerDay-2' failed: The argument 'state' must not be null. in PowerConsumptionPerDay
2021-05-05 16:10:00.885 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-05 16:10:00.887 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Gasusage-2' failed: The argument 'state' must not be null. in Gasusage
2021-05-05 16:11:00.169 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-05 16:11:00.203 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-05 16:11:00.204 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'PowerConsumptionPerDay-2' failed: The argument 'state' must not be null. in PowerConsumptionPerDay
2021-05-05 16:11:00.884 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-05 16:11:00.886 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Gasusage-2' failed: The argument 'state' must not be null. in Gasusage
2021-05-05 16:12:00.126 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-05 16:12:00.161 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-05 16:12:00.162 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'PowerConsumptionPerDay-2' failed: The argument 'state' must not be null. in PowerConsumptionPerDay
2021-05-05 16:12:00.928 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-05 16:12:00.929 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Gasusage-2' failed: The argument 'state' must not be null. in Gasusage
The rules I use are:
Gasusage:
rule "Update Gas Usage"
when
Time cron "0 0 0 * * ? *"
then
// logInfo('logGas', 'Rule Update GasUsage executing. DSMRM3GasMeter_Delivery = {}', DSMRM3GasMeter_Delivery.state)
DSMRM3GasMeter_Delivery.postUpdate(DSMRM3GasMeter_Delivery.state as Number)
GasUsageYesterday.postUpdate(DSMRM3GasMeter_Delivery.deltaSince(now.minusDays(1)))
GasUsageWeek.postUpdate(DSMRM3GasMeter_Delivery.deltaSince(now.minusWeeks(1)))
GasUsageMonth.postUpdate(DSMRM3GasMeter_Delivery.deltaSince(now.minusMonths(1)))
GasUsageYear.postUpdate(DSMRM3GasMeter_Delivery.deltaSince(now.minusYears(1)))
end
rule "Update Gas Usage Today"
when
// Item DSMRM3GasMeter_Delivery changed
Time cron "0 * * ? * *"
then
DSMRM3GasMeter_Delivery.postUpdate(DSMRM3GasMeter_Delivery.state as Number)
GasUsageToday.postUpdate( DSMRM3GasMeter_Delivery.deltaSince(now.with(LocalTime.of(0,0,0,0))))
val EnergyContractDate = ZonedDateTime.parse("2020-08-15T00:00:00.000Z").withZoneSameInstant(ZoneId.systemDefault())
GasUsageContract.postUpdate( DSMRM3GasMeter_Delivery.deltaSince(EnergyContractDate))
end
PowerProduction:
rule "PowerProduction per Day"
when
Time cron "0 0 0 * * ? *"
then
Total_Power_Production_Group.postUpdate(Total_Power_Production_Group.state as Number)
PowerProductionYesterday.postUpdate(Total_Power_Production_Group.deltaSince(now.minusDays(1))*-1)
PowerProductionWeek.postUpdate(Total_Power_Production_Group.deltaSince(now.minusWeeks(1))*-1)
PowerProductionMonth.postUpdate(Total_Power_Production_Group.deltaSince(now.minusMonths(1))*-1)
PowerProductionYear.postUpdate(Total_Power_Production_Group.deltaSince(now.minusYears(1))*-1)
end
rule "Update PowerProductionToday"
when
// Item Energie_verbruik_levering changed
Time cron "0 * * ? * *"
then
Total_Power_Production_Group.postUpdate(Total_Power_Production_Group.state as Number)
PowerProductionToday.postUpdate( Total_Power_Production_Group.deltaSince(now.with(LocalTime.of(0,0,0,0)) )*-1)
val EnergyContractDate = ZonedDateTime.parse("2020-08-15T00:00:00.000Z").withZoneSameInstant(ZoneId.systemDefault())
PowerProductionContract.postUpdate( Total_Power_Production_Group.deltaSince(EnergyContractDate)*-1)
end
And PowerConsumption:
rule "PowerConsumption per Day"
when
Time cron "0 0 0 * * ? *"
then
Total_Power_Delivery_Group.postUpdate(Total_Power_Delivery_Group.state as Number)
PowerConsumtionYesterday.postUpdate(Total_Power_Delivery_Group.deltaSince(now.minusDays(1)))
PowerConsumtionWeek.postUpdate(Total_Power_Delivery_Group.deltaSince(now.minusWeeks(1)))
PowerConsumtionMonth.postUpdate(Total_Power_Delivery_Group.deltaSince(now.minusMonths(1)))
PowerConsumtionYear.postUpdate(Total_Power_Delivery_Group.deltaSince(now.minusYears(1)))
end
rule "Update PowerUsageToday"
when
// Item Energie_verbruik_levering changed
Time cron "0 * * ? * *"
then
Total_Power_Delivery_Group.postUpdate(Total_Power_Delivery_Group.state as Number)
PowerConsumtionToday.postUpdate( Total_Power_Delivery_Group.deltaSince(now.with(LocalTime.of(0,0,0,0))))
val EnergyContractDate = ZonedDateTime.parse("2020-08-15T00:00:00.000Z").withZoneSameInstant(ZoneId.systemDefault())
PowerConsumtionContract.postUpdate( Total_Power_Delivery_Group.deltaSince(EnergyContractDate))
end
I canāt figure out what has changed in M3 and higher why a state should be null. As soon as I downgrade to 3.1.0M2 everything runs fine again.
Shall we look at Gas only for now? If we can fix this issue, I can fix them all.
DSMRM3GasMeter_Delivery ā Number
GasUsageToday ā Number
GasUsageContract ā Number
GasUsageYesterday ā Number
GasUsageWeek ā Number
GasUsageMonth ā Number
GasUsageYear ā Number
So all items are number values. Not something like Number:Volume.
The numers should have been successfully persisted (I suppose) because if I downgrade, I get rid of all the errors and the numbers are more or less the same compared to the reports I get from my Energy supplier.
I donāt know if that is what you expected,or if it is a problem.
We might get more info from a simpler query.
var fred = DSMRM3GasMeter_Delivery.historicState(now.minusDays(1))
if (fred !==null) {
logInfo("test", "historic item {}", fred)
} else {
logInfo("test", "Null return")
}
Youāre relying on your system default persistence setting, but it is influxdb complaining so that would appear to be how it is set.
As an aside, what is the purpose of these ālook up your own backsideā statements? DSMRM3GasMeter_Delivery.postUpdate(DSMRM3GasMeter_Delivery.state as Number)
As expected your script returns a FAILED in the Openhab logging.
2021-05-06 10:02:01.598 [INFO ] [org.openhab.core.model.script.test ] - historic item [FAILED toString()]
2021-05-06 10:02:01.633 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-06 10:02:01.635 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Gasusage-2' failed: The argument 'state' must not be null. in Gasusage
2021-05-06 10:03:00.089 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-06 10:03:00.123 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
I donāt know if that is what you expected,or if it is a problem
Itās a problem since it doesnāt update my GasUsageToday value anymore. Which is a value I use in Habpanel.
As an aside, what is the purpose of these ālook up your own backsideā statements? DSMRM3GasMeter_Delivery.postUpdate(DSMRM3GasMeter_Delivery.state as Number)
This is a piece of legacy from my issue when upgrading to OH3. Before the upgrade I used Number:Volume but I ran into issues. Now all the values are just Number values which makes this line obsolete. I removed the line from the rule.
After the upgrade I removed the Influx Persistance from MainUI and reinstalled it again. I checked if Influx is configured as Default persistance service and this is the case (in fact, there is only one persistance configuration configured).
Thatās the persistence service telling us it is choking on all this, which we kind of knew anyway.
Aha, youāve changed the Item type. influxdb will choke if you change say a String to a Number of course, you have to drop old data and start
over.
I think you are in the same boat.
Iād be inclined to overcome whatever issue you had with Number:Volume really.
I understand what you are saying, but of course I would like to do anything in order to keep my historic data. First of all because I would like to know my overcapacity from the Solar panels and second because Iām isolating my house piece by piece and I would like to monitor gas consumption over the year. There is more than 2 years of historic data in Influx.
The part above has nothing to do with the issue I face. I find it strange that after a patch update Influx seems to stop reacting. The data in Influx is no different than before. Iām not downgrading Influx, just down and upgrading Openhab in order to run these tests.
Iād be inclined to overcome whatever issue you had with Number:Volume really.
Iāve had some issues with calculations in the past. Thatās why I always change the Item settings back to just Number values if I perform calculations or compare values.
Well, itās up to you. Youāre looking at data recorded for one Item type and trying to shoehorn it into a different Item type.
The same data gets recorded into influxdb for a Number or Number:Volume type, but gets handled differently by the persistence service on update or retrieval.
This seems like a pretty good fit to your problem, you could verify that by experimenting with just one Item.
Canāt help with secret calculations, you can always extract pure numeric values from Quantity type Items in rules scaled to the units of your choice,or calculate directly with Quantities.
Do you know if Number values should be stored as Integers in Influx? (They are float as I just found out). I have a script found on the internet which āconvertsā values to Integers. I could try that before deleting the whole series and measurements.
#!/bin/bash
MEASUREMENTS=$(cat << EOF
DSMRM3GasMeter_Delivery
EOF
)
command="SELECT value::integer INTO temp FROM measurement; DROP MEASUREMENT measurement; SELECT value::integer INTO measurement FROM temp; DROP MEASUREMENT temp;"
for m in $MEASUREMENTS; do
echo "Updating $m..."
influx -database 'openhab_db' -username 'admin' -password '<password>' -execute "$(sed "s#measurement#$m#g" <<< $command)"
done
Hi, Sorry maybe I bother you with stupid things, but in order to test things, I tried to edit your testrule with an item which I never changed since Iām running Openhab (last 3 years).
var fred = LocalSun_StartTime.historicState(now.minusDays(1))
if (fred !==null) {
logInfo("test", "historic item today {}", fred)
} else {
logInfo("test", "Null return")
}
I thought, letās check if I can read the sunrise event from yesterday. But the logs show exactly the same.
2021-05-06 15:14:27.231 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Gasusage.rules'
2021-05-06 15:15:00.062 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-06 15:15:00.112 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
2021-05-06 15:15:00.114 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'PowerConsumptionPerDay-2' failed: The argument 'state' must not be null. in PowerConsumptionPerDay
2021-05-06 15:15:01.237 [INFO ] [org.openhab.core.model.script.test ] - historic item today [FAILED toString()]
2021-05-06 15:15:01.260 [INFO ] [b.internal.InfluxDBStateConvertUtils] - Could not find item 'null' in registry
Influx data (just to prove there is something in the database: