Help with rule

Hi everyone hoping someone can fix one of my rules it used too work perfectly but stopped working quite awhile ago

it may have been when i updated too OH3 i remember some time based things needed editing

the rule starts but gives an error now instead of changing the lights too the state it was 7 days ago

TIA


rule "Sentry Mode All Lights"
when
    Time cron "	0 0/1 * 1/1 * ? *" // Every 1 Min
then
if( Away_from_home.state == ON && DisableCentury.state == OFF ) {
if( SentryMode.state == ON ) {
	logInfo("Sentry Mode Lights", "Changed lights to value of this time last week")
    Ghouselights.members.forEach[light | light.sendCommand(light.historicState(now.minusDays(7)).state)]
}
end



==> /var/log/openhab/openhab.log <==

2021-08-28 00:35:00.952 [INFO ] [core.model.script.Sentry Mode Lights] - Changed lights to value of this time last week

2021-08-28 00:35:00.957 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Sentry Mode-2' failed: Could not invoke method: org.openhab.core.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,java.lang.String) on instance: null in Sentry Mode

==> /var/log/openhab/events.log <==

That’s the part that isn’t working. Is light a real Item? Is persistence working? Is it returning something that can be used as a command?
Open it up and find out.

    Ghouselights.members.forEach[light | 
         logInfo("Sentry Mode Lights", "Working with Item " + light.name)
         var p = light.historicState(now.minusDays(7))
         logInfo("Sentry Mode Lights", "Retrieved record {}", p)
         light.sendCommand(p.state)]
     ]

Note that states are not commands, even if they look alike e.g. command ON is not state ON.
The simplest fix is usually just make sendCommand parse whatever it wants from a string
light.sendCommand(p.state.toString)]

1 Like

Hi again Rossko i have been working on other issues but have come back too try and fix this now I could really do with getting this running again either fix this rule or scrap it and implement it a new way

light isn’t an item its a call for the items that are part of the ghouselight group

Item Ghouselights | 60.00000000
Members:
Item KitchenMainLight1_Brightness | 0
Item LivingRoomMain_Color | 38,87,0
Item BoilerRoomLight_Brightness | 0
Item MasterBedroomMainLight_Brightness | 0
Item AmeliasMainLight_Brightness | 0
Item TylersMainLight_Brightness | 0
Item LivingRoomLamp_Brightness | 60
Item BackDoorLight_Brightness | 0
Item LivingRoomClosetLight_Brightness | 0
Item FrontDoorLight_Brightness | 0
Item LandingLight_Brightness | 0
Item KitchenMainLight2_Brightness | 0
rule "Sentry Mode All Lights"
when
    Time cron "	0 0/1 * 1/1 * ? *" // Every 1 Min
then
//if( Away_from_home.state == ON && DisableCentury.state == OFF ) {
if( SentryMode.state == ON ) {
//Ghouselights.members.forEach[light | light.sendCommand(light.historicState(now.minusMinutes(1)).state)]
    Ghouselights.members.forEach[light | 
         logInfo("Sentry Mode Lights", "Working with Item " + light.name)
         var p = light.historicState(now.minusDays(7))
         logInfo("Sentry Mode Lights", "Retrieved record {}", p)
         light.sendCommand(p.state)]
}
end
2022-01-17 16:55:00.491 [INFO ] [core.model.script.Sentry Mode Lights] - Working with Item KitchenMainLight1_Brightness

2022-01-17 16:55:00.496 [INFO ] [core.model.script.Sentry Mode Lights] - Retrieved record [FAILED toString()]

2022-01-17 16:55:00.496 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'SentryMode-2' failed: Could not invoke method: org.openhab.core.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,java.lang.String) on instance: null in SentryMode

This sends a command to an Item.

States are not commands, even when the state is derived from a historic persistence request.

The simplest fix is usually just make sendCommand parse whatever it wants from a string.
light.sendCommand(p.state.toString)

But we don’t get far, because the persistence retrieval has failed

(That’s a message from the persistence service)
So you have a persistence issue to fix first.

1 Like

This makes sense I had a feeling my persistence got damaged when I moved house items and things changed location’s names etc do you have any tips for troubleshooting the persistence?

I have my OH server running in hyper-v i have just took a snapshot so can run any commands or try anything you recommend if it doesn’t work can always restore the system too now

i have previously looked into the persistence thinking it was the issue but couldn’t find the problem and fix the issue

i added all the light items too a new group tried too run the rule with that same issue

deleted and reinstalled influx still the same so i came too a bit of a loss there

it was probably mistakes on my end so could do with some tips from someone more experienced

i’m running a few different persistence services influx,mapdb,rrd4j

It’s just a case of plodding through.
You’re requesting from default service - which is that? Have you configured what to store?
Use API explorer to see if it holds data for the Item.
Changing Item types will break it.

in the persist file?

Strategies {
    everyMinute : "0 * * * * ?"
}

Items {
    // persist items on every change and every minute
    * : strategy = everyChange, everyMinute
}

Results were too big too upload directly i think i did it right

//http://192.168.0.34:8080/rest/persistence/items/Ghouselights
ghouselights.txt (103.5 KB)
//http://192.168.0.34:8080/rest/persistence/items/LivingRoomLamp_Brightness
livingroom.txt (97.1 KB)

//http://192.168.0.34:8080/rest/persistence/items?serviceId=influxdb
returns

{"error":{"message":"Authentication required","http-code":401}}

i don’t think anything changed types

i dont know why this error was happening but it looks like theres not a problem with the persistence service

yes i didnt see the part you added on the end my bad sentry mode is now fixed 5 months later my bad again lol

thanks for your help on this and the other thing yesterday i would not have fixed these problems without your tips i really appretiate that

rule "Sentry Mode All Lights"
when
    Time cron "	0 0/1 * 1/1 * ? *" // Every 1 Min
then
if( SentryMode.state == ON && DisableCentury.state == OFF ) {
//Ghouselights.members.forEach[light | light.sendCommand(light.historicState(now.minusMinutes(1)).state)]
    Ghouselights.members.forEach[light | 
        var p = light.historicState(now.minusDays(7))
        light.sendCommand(p.state.toString)]
        logInfo("Sentry Mode", "Sentry Mode Ran Lights changed too historical state")
    }
end
1 Like

Curious. Looks like
logInfo("Sentry Mode Lights", "Retrieved record {}", p)
doesn’t work with an historic record

Underscore in Item name.

Coupled with influxdb, you should look at -

and the workaround