Rule Error null ? But it was running all the time till reboot

  • Platform information:
    • Hardware: NUC
    • OS: Ubuntu LTS OH is under a Docker Container
    • openHAB version: 2.5

Hi I have an Alexa Echo Binding Rule which I can ask alexa if there are windows open - alexa check if open or not and say yes or no …it was running very good and i dont think i made a config change.

It could be that I upgraded the OH2 Docker container anytime but I dont changed anything in the config. It was running till yesterday - now I got NULL error.

I rebooted the system open and closed any window but still got the error.

rule:

rule "Alexa - Fenster offen"
when
    Member of Amazon_Echos changed to "sind noch fenster offen"
then
val currentEcho = Amazon_Echos.members.sortBy[lastUpdate].last
    val OffeneFenster = Fenster.members.filter[ i | i.state == OPEN ].map[ label ].reduce[ s, label | s + ", " + label ]
      if(Fenster.state == OPEN)   {
currentEcho.sendCommand("Ja, folgende Fenster sind geöffnet. " + OffeneFenster)
        }
      else {
currentEcho.sendCommand("Nein alle Fenster sind zu")
      }
end

items:

//HM-Sec-SCo Tür-/Fensterkontakt optisch
Contact KZ1_Fenster_State            "Hannes Fenster [MAP(window.map):%s]"                      <contact>   (KZ1,Windows,Fenster)     {channel="homematic:HM-Sec-SC-2:NEQ0477510:NEQ1114040:1#STATE"}

// Door Window Sensor WC

Contact Fenster_WC "WC Fenster [MAP(window.map):%s]" <window> (Fenster) { channel="mihome:sensor_magnet_aq2:158d0003120f89:isOpen" }
// minimum 30 seconds
// Number WindowSwitch_AlarmTimer <clock> { channel="mihome:sensor_magnet:<GwID>:<ID>:isOpenAlarmTimer" }
DateTime WindowSwitch_LastOpened "[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]" <clock-on> { channel="mihome:sensor_magnet:<GwID>:<ID>:lastOpened" }
// Number WindowSwitch_Battery <battery> { channel="mihome:sensor_magnet:<GwID>:<ID>:batteryLevel" }
// Switch WindowSwitch_BatteryLow <energy> { channel="mihome:sensor_magnet:<GwID>:<ID>:lowBattery" }

// Door Window Sensor Küche-Hof

Contact Fenster_Kueche_Hof "Kueche Fenster Hof [MAP(window.map):%s]" <window> (Fenster) { channel="mihome:sensor_magnet_aq2:158d0003132f34:isOpen" }
// minimum 30 seconds
// Number WindowSwitch_AlarmTimer <clock> { channel="mihome:sensor_magnet:<GwID>:<ID>:isOpenAlarmTimer" }
DateTime WindowSwitch_LastOpened "[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]" <clock-on> { channel="mihome:sensor_magnet:<GwID>:<ID>:lastOpened" }
// Number WindowSwitch_Battery <battery> { channel="mihome:sensor_magnet:<GwID>:<ID>:batteryLevel" }
// Switch WindowSwitch_BatteryLow <energy> { channel="mihome:sensor_magnet:<GwID>:<ID>:lowBattery" }

// Door Window Sensor Küche-Terrasse

Contact Fenster_Kueche_Ter "Kueche Fenster Terasse [MAP(window.map):%s]" <window> (Fenster) { channel="mihome:sensor_magnet_aq2:158d00031b3464:isOpen" }
// minimum 30 seconds
// Number WindowSwitch_AlarmTimer <clock> { channel="mihome:sensor_magnet:<GwID>:<ID>:isOpenAlarmTimer" }
DateTime WindowSwitch_LastOpened "[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]" <clock-on> { channel="mihome:sensor_magnet:<GwID>:<ID>:lastOpened" }
// Number WindowSwitch_Battery <battery> { channel="mihome:sensor_magnet:<GwID>:<ID>:batteryLevel" }
// Switch WindowSwitch_BatteryLow <energy> { channel="mihome:sensor_magnet:<GwID>:<ID>:lowBattery" }

// Door Window Sensor WZ-Hof

Contact Fenster_WZ_Hof "WZ Fenster Hof [MAP(window.map):%s]" <window> (Fenster) { channel="mihome:sensor_magnet_aq2:158d00032b874f:isOpen" }
// minimum 30 seconds
// Number WindowSwitch_AlarmTimer <clock> { channel="mihome:sensor_magnet:<GwID>:<ID>:isOpenAlarmTimer" }
DateTime WindowSwitch_LastOpened "[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]" <clock-on> { channel="mihome:sensor_magnet:<GwID>:<ID>:lastOpened" }
// Number WindowSwitch_Battery <battery> { channel="mihome:sensor_magnet:<GwID>:<ID>:batteryLevel" }
// Switch WindowSwitch_BatteryLow <energy> { channel="mihome:sensor_magnet:<GwID>:<ID>:lowBattery" }

// Door Window Sensor WZ-Schiebetür

Contact Fenster_WZ_Schiebetuer "WZ Fenster Schiebetuer [MAP(window.map):%s]" <window> (Fenster) { channel="mihome:sensor_magnet_aq2:158d00032b7432:isOpen" }
// minimum 30 seconds
// Number WindowSwitch_AlarmTimer <clock> { channel="mihome:sensor_magnet:<GwID>:<ID>:isOpenAlarmTimer" }
DateTime WindowSwitch_LastOpened "[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]" <clock-on> { channel="mihome:sensor_magnet:<GwID>:<ID>:lastOpened" }
// Number WindowSwitch_Battery <battery> { channel="mihome:sensor_magnet:<GwID>:<ID>:batteryLevel" }
// Switch WindowSwitch_BatteryLow <energy> { channel="mihome:sensor_magnet:<GwID>:<ID>:lowBattery" }

// Door Window Sensor WZ-Tür

Contact Fenster_WZ_Tuer "WZ Fenster Tuer [MAP(window.map):%s]" <window> (Fenster) { channel="mihome:sensor_magnet_aq2:158d000309ba5c:isOpen" }
// minimum 30 seconds
// Number WindowSwitch_AlarmTimer <clock> { channel="mihome:sensor_magnet:<GwID>:<ID>:isOpenAlarmTimer" }
DateTime WindowSwitch_LastOpened "[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]" <clock-on> { channel="mihome:sensor_magnet:<GwID>:<ID>:lastOpened" }
// Number WindowSwitch_Battery <battery> { channel="mihome:sensor_magnet:<GwID>:<ID>:batteryLevel" }
// Switch WindowSwitch_BatteryLow <energy> { channel="mihome:sensor_magnet:<GwID>:<ID>:lowBattery" }


// Door Window Sensor Hannes Fenster Hof
 
Contact Fenster_Hof_Hannes "Hannes Fenster Hof [MAP(window.map):%s]" <window> (hannesfenster,Fenster) { channel="mihome:sensor_magnet_aq2:158d00031344fc:isOpen" }
// minimum 30 seconds
// Number WindowSwitch_AlarmTimer <clock> { channel="mihome:sensor_magnet:<GwID>:<ID>:isOpenAlarmTimer" }
DateTime WindowSwitch_LastOpened "[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]" <clock-on> { channel="mihome:sensor_magnet:<GwID>:<ID>:lastOpened" }
// Number WindowSwitch_Battery <battery> { channel="mihome:sensor_magnet:<GwID>:<ID>:batteryLevel" }
// Switch WindowSwitch_BatteryLow <energy> { channel="mihome:sensor_magnet:<GwID>:<ID>:lowBattery" }

// MAX! Fensterkontakt

Contact maxFensterLuis "Luis Fenster [MAP(window.map):%s]" <window> (Fenster,gMaxLuis,gMaxWindow)                                      {channel="max:shuttercontact:NEQ1540669:OEQ0906849:contact_state"}

window.map:

CLOSED=geschlossen
OPEN=offen
NULL=unbekannt
UNDEF=unbekannt
-=unbekannt

persistence:

Strategies {

everyMinute : “0 * * * * ?”
everyhour : “0 0 0/1 1/1 * ? *”
every15min : “0 0/15 0 ? * * *”
}

Items {

Amazon_Echos* : strategy = restoreOnStartup, everyChange
}

Could anyone help me out or could say how to debug ?

It’s probably not going to help much more, but it would be good practice to show us the actual error. I guess you are finding this in your openhab.log?

Okay, some basics.

When openHAB starts up and creates Items, they all get a state of NULL.
That’s the way they stay until something changes them - a restore, or an update from a binding, etc.

So in the normal course of events, Items linked to battery window sensors may stay at NULL state for a long time after a reboot, until the window is opened and an update happens.

Obviously there are things you can’t do with NULL in rules, like simply adding up for example.

note that Item state NULL is not like null, the empty or void variable value in rules. Pay attention to error messages.

I can’t see an obvious problem in your rule. It filters group members by state==OPEN, so you might end up with an empty list, but that should be dealt with.

My next suspect would be that [lastUpdate]
Is there (yet) a last update to find? Is there a configured default persistence service - you’re relying on that.

If the mystery error message is not forthcoming about where in the rule the problem arises, you can diagnostically add logInfo() to follow rule progess step by step.

1 Like

What Persistence are you using I use mapdb and influxdb

map is for restore at startup

Strategies {
	default = everyChange
}
Items {
	* : strategy = everyChange, restoreOnStartup
}

The exact erro message ist following:

    2020-10-14 11:52:40.479 [vent.ItemStateChangedEvent] - Echo_Kitchen_LastVoiceCommand changed from sind noch fenster offen to alexa
2020-10-14 11:52:45.798 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Alexa - Fenster offen': null
2020-10-14 11:52:45.780 [vent.ItemStateChangedEvent] - Echo_Kitchen_LastVoiceCommand changed from alexa to sind noch fenster offen

My presistance is a mariadb with jdbc.persist file

Strategies {
	everyMinute : "0 * * * * ?"
	everyhour   : "0 0 0/1 1/1 * ? *"
	every15min  : "0 0/15 0 ? * * *"
}

Items {

Amazon_Echos*, Fenster*: strategy = restoreOnStartup, everyChange

@denominator

what do you mean with your link exactly ? doesnt understand it exactly :smiley:

You have a NULL error on one of your items so the rule will not run correctly because it doesn’t have a valid sortBy[lastUpdate].last time.

In your items you have listed the same item multiple times https://www.openhab.org/docs/configuration/items.html#name

Add WindowSwitch to your data that is persisted.

Items {

Amazon_Echos*, WindowSwitch* : strategy = restoreOnStartup, everyChange
}

This info is spot on and my link was so you could find more information about doing this.

Change your rule to add a warning in the log if you get a null state like

rule "Alexa - Fenster offen"
when
    Member of Amazon_Echos changed to "sind noch fenster offen"
then
val currentEcho = Amazon_Echos.members.sortBy[lastUpdate].last
    val OffeneFenster = Fenster.members.filter[ i | i.state == OPEN ].map[ label ].reduce[ s, label | s + ", " + label ]
      if(OffeneFenster == null) logWarn("FILE", "Something is amiss, no Item has a valid lastUpdate!")
      if(Fenster.state == OPEN)   {
currentEcho.sendCommand("Ja, folgende Fenster sind geöffnet. " + OffeneFenster)
        }
      else {
currentEcho.sendCommand("Nein alle Fenster sind zu")
      }
end

You nearly there

thank you for the answer:

as you can see here in my persistence “FENSTER” is like your WINDOWSWITCH

So under group Fenster are all windowswitch contacts

Your issue is not with your contact’s is it?

I thought you had an issue with your datetime items that do not have unique item names and are not persisted because the item is not in any group.

Are your items different to the ones listed in the OP.

Changed to your rule with additional log info - but get any additional log entry:

2020-10-15 10:25:35.639 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'echofenster.rules', using it anyway:

2020-10-15 10:25:35.670 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'echofenster.rules'

2020-10-15 10:26:01.253 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Alexa - Fenster offen': null

2020-10-15 10:26:01.140 [vent.ItemStateChangedEvent] - Echo_Kitchen_LastVoiceCommand changed from alexa to sind noch fenster offen

2020-10-15 10:26:54.874 [vent.ItemStateChangedEvent] - Echo_Kitchen_LastVoiceCommand changed from sind noch fenster offen to alexa

2020-10-15 10:27:05.417 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Alexa - Fenster offen': null

2020-10-15 10:27:05.400 [vent.ItemStateChangedEvent] - Echo_Kitchen_LastVoiceCommand changed from alexa to sind noch fenster offen

2020-10-15 10:27:29.797 [vent.ItemStateChangedEvent] - Echo_Kitchen_LastVoiceCommand changed from sind noch fenster offen to alexa

2020-10-15 10:27:40.584 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Alexa - Fenster offen': null

2020-10-15 10:27:40.576 [vent.ItemStateChangedEvent] - Echo_Kitchen_LastVoiceCommand changed from alexa to sind noch fenster offen

I have 3 different window switches the most are the contacts from xiaomi , than 1 from homematic and one from homematic ip

it has worked before it is not a problem that it never would have done in the configuration.

when i look into mysql for the presistence of the group windows - all members have OPEN or CLOSED in them

In your items list you have

DateTime WindowSwitch_LastOpened

Listed multipal times wich is not persisted in any group.

What are you using for persistance?

ah i see what you mean - never thinked about that. i dont use anything of “DateTIme” i just use for example:

Contact Fenster_WZ_Tuer “WZ Fenster Tuer [MAP(window.map):%s]” (Fenster) { channel=“mihome:sensor_magnet_aq2:158d000309ba5c:isOpen” }

and (Fenster) is my window group which i have in the persistance

Items {

Amazon_Echos*, Fenster*: strategy = restoreOnStartup, everyChange

Ahh ok I got ya now. My fault.

Your rules are executing before the items have been populated causing the error. Ignore it, delay the rule start or touch all of your rules files after openhab has fully started.

What you mean with touch oder delay ?

Mind to share the Amazon_Echos group definition ?
I’m curious how to trigger upon a German phrase that you can define yourself.

This remains relevant and unanswered.

1 Like

really ? as i said i have an mariaDB with the pesistence service " JDBC Persistence "

Group Fenster (which all my windowcontact are under) is configured for pesistence in PHPmyAdmin i see for alle contact OPEN or CLOSED DB entrys

i use last voice command to trigger that rule

Use mapdb for restoreOnStartup and remove that from mariaDB persistence.

Trouble probably is the item isn’t restored when the rule executes.
You should also check for the item to be NULL in your “filter” line to be more failsafe.

1 Like

Old link same problem

ok - sorry for my noobish :smiley: but could you be more detail what i should change ? i never worked with mapdb oder somethin like that - also im new to persistences as well

copy mariadb.persist into mapdb.persist and remove all strategies but restoreOnStartup. Remove restoreOnStartup from mariadb.persist.
And read up in the docs how to enable mapdb persistence in the first place.
And as @rossko57 said check and make mariadb your default persistence.

can you show the item definition please

And Alexa takes any literal input even if she doesn’t understand it semantically ?