Updating (virtual) String item with postupdate fails [SOLVED]

Hi SIFUs

Bascially I’m just starting with Openhab and my various Z-wave items in the house. So far it works all fine as expected but with my virtual tem I struggle.

Basically what I want to archive:
I want an virtual text item to track the status of my washing machine/Laundry area.
Based on the power consumption of my washing machine (available via Z-wave binding) and the status of the laundry door (available via Z-Wave binding) I estimate If I might have forgotten my washing in the machine and should pick it up.

Item (Virtual)

String V_Washing_status " [MAP(washing.map):]"

washing.map

WS1=In Progress
WS2=Ready to collect
WS3=empty

To be updated with rules

rule "Washing_progress"
when
Item WashingmachineWatts changed
then
logInfo(“Kitchen”,"Washing status was updated to " + WashingmachineWatts.state)
if (WashingmachineWatts.state>100)
postUpdate(V_Washing_status,“WS1”)
if (WashingmachineWatts.state<100)
if (V_Washing_status.state = “WS1”)
postUpdate(V_Washing_status,“WS2”)
end

rule "Washing_collect"
when
Item DoorlaundryTripped changed to open
then
if (WashingmachineWatts.state<100)
if (V_Washing_status.state = “WS2”)
postUpdate(V_Washing_status,“WS3”)

OK in theory that should work, but it seems the postUpdate is not working. Instead I receive below log:

16:37:29.522 ERROR o.o.c.s.ScriptExecutionThread[:50]- Error during the execution of rule ‘Washing_progress’: Could not invoke method: org.openhab.core.items.GenericItem.setState(org.openhab.core.types.State) on instance: V_Washing_status (Type=StringItem, State=WS1)

I believe I did all the reading I could find and currently I’m stuck. Can someone point me in the right direction? What do I need to tweak to make it working?

Your help is highly appreciated
Thanks

EDIT: solution found:

  1. in the if-clauses it has to be a == to do a comparison. Otherwise it assigns a value and does not what was intended.
  2. keep it simple: avoid string and go for numbers only. Simplifying help to find the issue
  3. I had defined the display of my item via the sitemap and therefore changes on my item itself had no effect. --> keep finger away from sitemap unless it’s working :slight_smile:
  4. postupdate has two ways of usage. Above one seems to be dodgy while e.g. V_Washing_status.postUpdate(“WS1”) works better
  5. logging: play around with logging to really see at which step the script stops/executes. Above was not enough for me and I ended up logging nearly after each line of code. From there I knew where my issue actually is

As the action isn’t reliable, please try the method:

V_Washing_status.postUpdate("WS1")

Thanks Udo,

unfortunately: I tried it before and it returns also an error. I just tried it again and below the related log:

25.04.2016 18:44:54.655 INFO o.openhab.model.script.Kitchen[:53]- Washing status was updated to 0
25.04.2016 18:44:54.696 ERROR o.o.c.s.ScriptExecutionThread[:50]- Error during the execution of rule ‘Washing_progress’: Could not invoke method: org.openhab.core.items.GenericItem.setState(org.openhab.core.types.State) on instance: V_Washing_status (Type=StringItem, State=Uninitialized)

any other idea?

And to ensure I haven’t screwed up the script with a typo the modified script:

rule "Washing_progress"
when
Item WashingmachineWatts changed
then
logInfo(“Kitchen”,"Washing status was updated to " + WashingmachineWatts.state)
if (WashingmachineWatts.state>100)
V_Washing_status.postUpdate(“WS1”)
if (WashingmachineWatts.state<100)
if (V_Washing_status.state = “WS1”)
V_Washing_status.postUpdate(“WS2”)
end

I think you are missing the “%s” in the label.

String V_Washing_Status "[MAP(washing.map):%s]"

Question, if you are dealing with Strings anyway, why bother with the MAP and just set the Item to what you want it to read in the first place?

Look at your logs. Are you seeing any errors when it loads your Items file? Are you seeing any errors from your sitemap? The rule seems to be acting like V_Washing_status doesn’t exist.

You need two equals signs to do a comparison. A single equals sign assigns “WS1” to the .state member of V_Washing_status, or at least tries to. This is the error with setState in the log.

Hi Rich,

thanks

The %s is indeed missing and will be added, however this is (as far as I understand) a cosmetic thing and should not affect the script performance. Anyway it will be changed :slight_smile:
For the “why using a MAP”. It’s fairly simple: I like to divide code and frontend as much as possible. Therefore I like a machine code and a separate definition what that might mean for the user. It’s probably silly but that’s me :wink:
Also: I might explore the option of going bilingual as it would increase the “wife acceptance factor”. Anyway this is left for the future development and I haven’t explored if that is actually possible. My hope is one day I can handle that with e.g. different map files per sitemap or similar :slight_smile:

For the LOG: I have a couple of errors to deal with but nothing really pointing towards items (beside the ones I posted). Anyway removing the warnings/error is currently my focus and this rule is one of them. The error for the persistence are unrelated I believe.

It is often a really good idea to simplify when debugging problems. Since the map right now adds nothing functionally yet adds complexity I would remove it. If you need it, add it back in later.

It is very possible and actually likely that one error such as a typo or other problem in your Items file to generate warnings and errors all over the place. I would not immediately assume they are unrelated.

Alright. Thanks so much each of you.

So my issue is resolved. The main helper was actually the == in the if statement. However the entire discussion helped me a lot. I’m yet to fully discover rules but it feels a lot better already :slight_smile:
One detail not mentioned here which made it extra hard for me: I defined the way of displaying the item via the sitemap and not in the item itself. Therefore a couple of item declaration changes been without effect which took me a while to figure out. Now I know: let the fingers away from defining it in the sitemap when it’s actually meant to be in the item itself :blush:

And especially for Rich: of course you are right. Keep it simple is a good idea. I was quite confident to be on top of this and get it right. But above proved me wrong and breaking it down in small bites actually helped to pin point the silly sitemap definition nonsense I created. So yes: a credit to you: you’ve been right and I was wrong. I promise I learned out of it!

Thanks again everyone for your time and thoughts on my issue