I migrated form OH1 to OH2; quite a few rules are not working, mainly due to unitialised items.
Now Rich (@rlkoshak) knocked me on the head already by saying along the lines "now is an opportune time to initialise your items properly.
Well, off I went… (what a pain)
As it seems switches are NULL if uninitialised.
My comparison, like: blah.state === null did not yield the proper result.
Is it then safe to day that switches are string items with two states called ON|OFF?
Is there a way that I could loop through all my items and check, whether they are uninitialised?
E.g. on the console with something like smarthome:status * === UNDEF
Or loop through all contacts and set them to closed
Is there a way to use one test to get them all? E.g. UNDEF being uninitialised and NULL and null?
Is it a good idea to put all ‘initialisations’ into one rules file?
Have you considered restoreOnStartup with MapDB persistence?
This should reinitialise most of your items automagically.
You could add all your contacts items in a group, let’s call it gAllContacts
Then a rule:
rule "Initialise all contacts"
createTimer(now.plusMinutes(2), [ | //Give the system time to load up
gAllContacts.members.forEach[ i |
if (i.state == NULL || i.state == UNDEF) i.postUpdate(CLOSED)
NULL is not the same as null. I hate that they used the same term. Your comparison should be if blah.state == NULL.
Note the use of ==.=== should only be used when comparing to null.
Not really. ALL items can be set to NULL (uninitialized) or UNDEF (undefined). Switch items can additionally be set to ON or OFF, which are enumerations, not Strings. The big thing from a practical perspective is you find need to use " around them.
All of this has not changed since oh 1.x except NULL used to be called Uninitialized IIRC.