Hardware: Raspberry Pi 3 Model B Rev 1.2 // 1GB RAM // 32GB SD
OS: Raspbian GNU/Linux 10 (buster) // Linux 4.19.75-v7+
Java Runtime Environment: openjdk version (build: 1.8.0_222)
openHAB version: openHAB 2.5.0-1 (openHABian)
Dear openHAB-community,
I would like to initialize value of an item to 0 when de system restarts but it does not work. The item I want to initialize is used as a setpoint item in my sitemap. Its purpose is to adjust the temperature reading of a Modbus RTU sensor later on. When the system restarts i would like it to be set to an offset of 0°C or even better to remember the value from before the restart.
This is what i did:
Declared it as an item(Modbus_Sensor.items):
Number Humidity_read "Relative humidity: [%.1f/100 %%]" {channel="modbus:data:slave01:SensorRead1:humidity1:number"}
Number Temperature_read "Temperature: [%.1f °C]" {channel="modbus:data:slave01:SensorRead1:temperature1:number"}
Number Temp_correct "Temperature correction: [%.1f °C]" // {channel="modbus:data:slave01:SensorWrite1:Temp_correct2:number"}
I want to send this temperature correction value to the sensor later on, therefore the commented part is there.
3) Tried to initialize it with this rule(HVAC.rules):
rule "Startup"
when
System started
then
Temp_correct = 0
end
I get this error:
==> /var/log/openhab2/openhab.log <==
2020-01-25 22:42:32.684 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2020-01-25 22:42:32.997 [INFO ] [ebuilder.internal.HomeBuilderServlet] - Started Home Builder at /homebuilder
2020-01-25 22:42:33.254 [INFO ] [openhab.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
==> /var/log/openhab2/events.log <==
2020-01-25 22:42:34.628 [vent.ItemStateChangedEvent] - Temperature_read changed from NULL to 25.6
2020-01-25 22:42:34.655 [vent.ItemStateChangedEvent] - Humidity_read changed from NULL to 42.8
2020-01-25 22:42:34.678 [vent.ItemStateChangedEvent] - Temperature_read changed from 25.6 to 25.5
2020-01-25 22:42:34.710 [vent.ItemStateChangedEvent] - Humidity_read changed from 42.8 to 42.2
2020-01-25 22:42:35.881 [vent.ItemStateChangedEvent] - Local_date_time changed from 2020-01-25T22:42:30.853+0100 to 2020-01-25T22:42:35.853+0100
==> /var/log/openhab2/openhab.log <==
2020-01-25 22:42:38.446 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Startup': Cannot assign a value in null context.
Any hints on what i am doing wrong? Oh and yes, I am a newbie and this my first project.
Thank you, both of you!!! That solved my problem and pointed to me to a part that i should read once more. I have read so much of the documentation the last days that it is getting a bit blurry in my head.
For just the last value and restoring the value when openHAB starts it is recommended to use the MAPDB persistence service: MapDB - Persistence Services | openHAB
Info: if you link that Item to a modbus data Thing with read capability ⊠the next read poll will overwrite your âinitializedâ Item state anyway.
A first poll will most likely have already run before your rule, and your rule will overwrite the polled data.
At the next poll after your rule has run, the polled data will overwrite your rule data again.
It is possible to make write-only modbus data Things, if that is what you have in mind.
A tweak to your rule that only âinitializesâ if no polled data is available yet
rule "Startup"
when
System started
then
if ( Temp_correct.state == NULL) {
Temp_correct.postUpdate(0)
}
end
I want to initialize a String item with the following rule:
rule "Startup"
when
System started
then
remoteCommand.postUpdate("init")
end
but i get the following error message
Error during the execution of startup rule âStartupâ: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.postUpdate(java.lang.String,java.lang.String) on instance: null