[SOLVED] NULL | UNDEF | null | uninitialized

OHv2.3.0

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. :smiley:

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?

Hi @Max_G
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"
when
    system started
then
    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)
        ]
    ])
end

Regards

2 Likes

Thanks… I migrated, but did not copy any persistence file… in hindsight a mistake. :frowning:

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.

1 Like

Shouldn’t this be
== NULL instead of == 'NULL'
unless it’s about a string item?!

2 Likes

Yes corrected above
Thanks