Problems with Setpoint Start Values

  • Platform information: Raspberry 3
  • OS: Openhabian 2.3.0-1
  • openHAB version: 2

Setting start values for setpoint items does not work

RolladenAutomatikZeitAuf, RolladenAutomatikZeitZu are number items.
(Minutes of Day)

rule "Init virtual Items" when System started then logInfo("home.rules","System started")
  PV_Gesamtleistung_avg.postUpdate(1)

  Wassertemperatur_Pool_Soll.postUpdate(28.0)
  PoolPumpeAutoStart.postUpdate(9)            //  9 Uhr  **works**
  PoolPumpeAutoStop.postUpdate(18)            // 18 Uhr **works**
  PoolPumpeAuto.postUpdate(OFF)
  PoolWaermepumpeAuto.postUpdate(OFF)

  Rolladenautomatik.postUpdate(OFF) 
  RolladenAutomatikZeitAuf.postUpdate(540)      //  9 Uhr **does not work**
  RolladenAutomatikZeitZu.postUpdate(1260)      // 21 Uhr **does not workt**

  logInfo("home.rules",RolladenAutomatikZeitAuf.state.toString() )
  logInfo("home.rules",RolladenAutomatikZeitZu.state.toString() )

end

> 2019-06-16 17:14:34.793 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.rules' > > 2019-06-16 17:14:47.882 [INFO ] [se.smarthome.model.script.home.rules] - System started > > 2019-06-16 17:15:00.013 [INFO ] [se.smarthome.model.script.home.rules] - Rolladenautomatik: auf : RolladenAutomatikZeitAuf (Type=NumberItem, State=NULL, Label=Rolladen automatisch auf, Category=null) > > 2019-06-16 17:15:00.018 [INFO ] [se.smarthome.model.script.home.rules] - Rolladenautomatik: ab : RolladenAutomatikZeitZu (Type=NumberItem, State=NULL, Label=Rolladen automatisch zu, Category=null)

Look in your events.log to see that your updates do take place.

Thanks for your quick answers.
What is the proper way to set a startvalue for a virtual item?
For example a setpoint item which represents the time for opening or closing a shutter.
After a start or restart of openhab ths sitemap should show this value.

You may have misunderstood the situation.

postUpdate works just fine.
But if you use it in a rule, do not expect it to have been completed before the rule moves on to the next line. It will complete in a few milliseconds, but not as quick as that.

myItem.postUpdate(xxx)      //  puts an update request on openHABs event bus
  // does not wait for update to complete
logInfo("test",myItem.state.toString)   // invariably displays OLD value
Thread::sleep(100) // let's wait
logInfo("test",myItem.state.toString)   // magic, displays NEW value

That sounds like something you might want to persist and then restore on startup, so that the system remembers your settings across a reboot.

You’d probably still want a first-time rule to get an initial value.

if (myItem.state == NULL) {
      // if not yet initialized or restored
   myItem.postUpdate(xxx)   // send a default value
}

Yes, that’s what I want to do.
Now I understand that asking the new value in the rule does not work. My problem is, that

RolladenAutomatikZeitAuf.postUpdate(540) RolladenAutomatikZeitZu.postUpdate(1260) never updates.

Please show us your Item definitions and the relevant openhab.log and events.log sections.
Yes I know there won’t be logs of things not happening but your rule does other things that we can see :smiley:

I defined using Paper UI:

RolladenAutomatik : Switch
RolladenAutomatikZeitAuf : Number (representing Minutes from 0:00)
RolladenAutomatikZeitZu : Number

home.sitemap:

Frame label=“Rolladenautomatik” {
Default item=RolladenAutomatik
Text label="" icon=""
Setpoint item=RolladenAutomatikZeitAuf label=“Rolladen automatisch auf Uhrzeit [JS(numberToClock.js):%s]” minValue=0 maxValue=1425 step=15 icon=“time”
Setpoint item=RolladenAutomatikZeitZu label=“Rolladen automatisch zu Uhrzeit [JS(numberToClock.js):%s]” minValue=0 maxValue=1425 step=15 icon=“time”
}

numberToClock.js:

(function(i) {
var hours = Math.floor(i / 60);
var minutes = i % 60;

hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;

return hours + ":" + minutes;

})(input)

After restarting Openhab the sitemap shows NaN:NaN for
RolladenAutomatikZeitAuf and RolladenAutomatikZeitZu

Changing the values on the sitemap works.

I wonder what the logs say.

openhab.log (58.5 KB)

lastevents.log (104.2 KB)

You’ve got errors in some xxx.things files and some xxx.sitemap files, but they’re not related to this.

home.rules loads okay, but there is no logging from your rule rule “Init virtual Items” that you first showed us.

There are some events logged

2019-06-20 14:52:01.375 [vent.ItemStateChangedEvent] - Wassertemperatur_Pool_Soll changed from NULL to 25.0
2019-06-20 14:52:01.387 [vent.ItemStateChangedEvent] - PoolPumpeAutoStart changed from NULL to 8
2019-06-20 14:52:01.393 [vent.ItemStateChangedEvent] - PoolPumpeAutoStop changed from NULL to 20
2019-06-20 14:52:01.397 [vent.ItemStateChangedEvent] - PoolPumpeAuto changed from NULL to OFF
2019-06-20 14:52:01.401 [vent.ItemStateChangedEvent] - PoolWaermepumpeAuto changed from NULL to OFF

these look like they probably were caused by your “Init virtual Items” rule - except the values do not match exactly.
If you haven’t changed your rule from what you showed before … maybe you are editing a wrong copy of rules file?

The important thing is that there is no evidence of any update to RolladenAutomatikZeitAuf (so we’d expect it to stay NULL)

Looking in openhab.log, home.rules seems to be loaded OK, no errors such as unknown Item or suchlike.
I think your postUpdates for the rolladen Items simply aren’t in your rule at the moment.

Perhaps we should see the current version of the rule?

I think I found the Problem:

Rolladenautomatik.postUpdate(OFF)

must be

RolladenAutomatik.postUpdate(OFF)

I don’t know why the next two lines are not executed.
Thank You very much for your help!

Okay, the typo would cause a “not found” style error, and stop your rule. It’s not usually sensible to continue after an error.

Now, why did we not see the error report in openhab.log? (It would point directly to the problem)

Wait - did you change that name along the way? First post shows logs of item with little ‘a’ working ok.
Don’t forget to check sitemap names too.

I’ve tried a lot of things, but I don’t think I’ve changed the name. Since this value is a switch on the sitemap, it was probably not noticed that the start value was not set.