Refresh Rule

  • Platform information:
    • Hardware: Raspberry 3B
    • OS: raspios-buster
    • Java Runtime Environment:Zulu 8
    • openHAB version: 2.5.10
  • Issue of the topic: Refresh never stops.

When my Items are commanded from Alexa voice command, their switch is not refreshed and therefore the expire function does not work. So I wrote a simple rule for refreshing my items every time that an update occure:

rule "refresh"
when
    //Time cron "*/10 * * * * ? *" or
    Member of gLight received command
then
   Bathroom_Light.sendCommand("REFRESH")
   Entryway_Light.sendCommand("REFRESH")
   Hallway_Light.sendCommand("REFRESH")
   KidsRoom_Light1.sendCommand("REFRESH")
   KidsRoom_Light2.sendCommand("REFRESH")
   Kitchen_Light.sendCommand("REFRESH")
   LivingRoom_Light1.sendCommand("REFRESH")
   LivingRoom_Light2.sendCommand("REFRESH")
   LivingRoom_Light3.sendCommand("REFRESH")
   MasterBedroom_Light.sendCommand("REFRESH")
   Toilet_Light.sendCommand("REFRESH")
end

The problem is that with this rule items are never stopping to receive REFRESH and the expire never works.

Item 'Entryway_Light' received command REFRESH
21:54:39.529 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Hallway_Light' received command REFRESH
21:54:39.937 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KidsRoom_Light1' received command REFRESH
21:54:40.373 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Hallway_Light' received command REFRESH
21:54:40.832 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KidsRoom_Light2' received command REFRESH
21:54:41.243 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KidsRoom_Light1' received command REFRESH
21:54:41.993 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KidsRoom_Light1' received command REFRESH
21:54:42.344 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KidsRoom_Light2' received command REFRESH
21:54:42.945 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KidsRoom_Light1' received command REFRESH
21:54:43.344 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KidsRoom_Light1' received command REFRESH
21:54:43.833 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Kitchen_Light' received command REFRESH
21:54:44.196 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Kitchen_Light' received command REFRESH
21:54:44.552 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light1' received command REFRESH
21:54:44.952 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KidsRoom_Light2' received command REFRESH
21:54:45.386 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KidsRoom_Light2' received command REFRESH
21:54:45.781 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KidsRoom_Light2' received command REFRESH
21:54:46.244 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light2' received command REFRESH
21:54:46.508 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Kitchen_Light' received command REFRESH
21:54:46.889 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light1' received command REFRESH
21:54:47.253 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light2' received command REFRESH
21:54:47.592 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Kitchen_Light' received command REFRESH
21:54:47.951 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Kitchen_Light' received command REFRESH
21:54:48.379 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light1' received command REFRESH
21:54:48.750 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light1' received command REFRESH
21:54:49.107 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light1' received command REFRESH
21:54:49.500 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light3' received command REFRESH
21:54:49.962 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light2' received command REFRESH
21:54:50.486 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light3' received command REFRESH
21:54:50.928 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light2' received command REFRESH
21:54:51.369 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'MasterBedroom_Light' received command REFRESH
21:54:51.764 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light2' received command REFRESH
21:54:52.178 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light3' received command REFRESH
21:54:52.550 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Toilet_Light' received command REFRESH
21:54:52.990 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light3' received command REFRESH
21:54:53.396 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'MasterBedroom_Light' received command REFRESH
21:54:53.785 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoom_Light3' received command REFRESH
21:54:54.175 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'MasterBedroom_Light' received command REFRESH
21:54:54.485 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'MasterBedroom_Light' received command REFRESH
21:54:54.875 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Toilet_Light' received command REFRESH
21:54:55.261 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'MasterBedroom_Light' received command REFRESH
21:54:55.799 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Toilet_Light' received command REFRESH
21:54:56.182 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Toilet_Light' received command REFRESH
21:54:56.512 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Bathroom_Light' received command REFRESH
21:54:57.015 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Toilet_Light' received command REFRESH
21:54:57.410 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Entryway_Light' received command REFRESH
21:54:57.755 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Bathroom_Light' received command REFRESH

I tried also with the only cron value but the result is quite similar.
What am I ding wrong ?

It’s a good idea to post your items too, as it’s often difficult to tell what the problem is just by looking at the rule. However, I’m assuming that all of your lights are members of the gLight group. So, look at your rule again in plain language:

“When a member of gLight receives a command”
“Send a command to all these members of gLight”

If my assumption is correct, the rule is going to keep executing infinitely, because it’s designed to react to the very commands you’re sending, and then send more of those commands.

It’s also a little strange to me that you’re sending “REFRESH” to items that I’m guessing are ON/OFF switch types, but again, I don’t know what your items look like.

Putting the rule aside, if your items aren’t updating when you use Alexa commands, then something is wrong with the items. A rule is probably not the best solution, so let’s figure out where the actual issue is and solve that instead.

Presumably all of these Items are members of gLight. So:

  1. a member of gLight receives a command
  2. the rule triggers
  3. the rule sends a command to 11 members of gLight
  4. gLight receives 11 more commands
  5. the rule triggers 11 more times

and so on.

You need to cut this loop. There is not enough information to provide an optimal solution. Perhaps only trigger the rule when a member receives an ON or OFF command.

Also, any command you send to a Group Item will be sent to all of it’s members. So you can reduce this whole rule to just

gLight.sendCommand("REFRESH")

And in fact, that might reveal to you a little better why it’s looping.

2 Likes

Thanks for your quick answer.
I explain better my environment.
All items are lights belonghing to LivingNow and are imported to openhab with the following “travel”:
Legrand to Alexa --> Legrand Skill
Alexa to OH --> Alexa echocontrol Binding

All my items are not tagged {alexa=disable} because I need to aboid duplicate names in Alexa app via Alexa openhab skill.

When I make a command via Alexa, the OH switch in PaperUI are not refreshed and rules or expire function are not triggered.
Differently, If i switch the the Item from PaperUI, rules are well working and also the expire works.

Here is an example of one Item definition:

Switch          Kitchen_Light           "Luce Cucina"                  <light>           (Kitchen, gLight)           ["Lighting", "Switchable"]   {alexa="disable",channel="amazonechocontrol:smartHomeDevice:xxxxx:Kitchen_Light:powerState"}

Very clear. Thanks. Now at least I have understood the reason for the loop …
I need to find a different solution. Not very expert here …

Thanks again.

So if I understand correctly, the problem isn’t something with openHAB, but that your Legrand lights are attached to Alexa, and Alexa voice commands don’t pass on the updates to openHAB?

I didn’t know about sendCommand("REFRESH"), so that’s my lesson for today. :wink:

Even if you fixed the rule, the problem remains that if Alexa doesn’t send any updates to openHAB when it receives voice commands, you don’t have a trigger to act on. I don’t know much about the Echo Control Binding, but maybe this will work:

  1. Create a proxy item (with no channel) that’s exposed to Alexa as a switch.
  2. Set up an Alexa rule: whenever any of the gLight switches are toggled, it also toggles the proxy item to `ON’.
  3. Set up an OH rule that triggers whenever the proxy item changes to ON, and have it do two things:
    a. refresh your gLights group as @rlkoshak recommended
    b. toggle the proxy item to OFF

When OH queries Alexa for the updated status, it won’t change the states of the lights. And so, the proxy item should not change to ON and the OH rule should not by triggered.

The downside is that you have to have an extra item in Alexa, but that’s better than 11 duplicates.

1 Like

OK. A bit more complex and tricky but it looks promising.
I will apply … it will take some time for me to try :).
Thanks to all for the time being.

Not all bindings implement it. But it’s a way to ask the binding to go out and query of the state of the device. Of course both the binding and the technology itself needs to support such an operation.

2 Likes

So now at least I am outside of the loop but the problem remains: OH switch in Sitemap or PaperUI are not updated if commanded from real world and therefore the rule does not fire.
If commanded from OH it fires and update.

rule "refresh"
when
        Item sw_alexa_refresh changed from OFF to ON
then
   //gLight.sendCommand("REFRESH")
   Bathroom_Light.sendCommand("REFRESH")
   Entryway_Light.sendCommand("REFRESH")
   Hallway_Light.sendCommand("REFRESH")
   KidsRoom_Light1.sendCommand("REFRESH")
   KidsRoom_Light2.sendCommand("REFRESH")
   Kitchen_Light.sendCommand("REFRESH")
   LivingRoom_Light1.sendCommand("REFRESH")
   LivingRoom_Light2.sendCommand("REFRESH")
   LivingRoom_Light3.sendCommand("REFRESH")
   MasterBedroom_Light.sendCommand("REFRESH")
   Toilet_Light.sendCommand("REFRESH")
   sw_alexa_refresh.sendCommand(OFF)
end

rule " Alexa refresh trigger"
when
    //Member of gLight received update
    Member of gLight changed

then
   sw_alexa_refresh.sendCommand(ON)
end

gLight.sendCommand("REFRESH") gives me an error … I do not understand where is the error.

At the end I came back at the beginning, as you said there is something not working in the Light Items.

I do not know if this can help in uderstanding but I have a Plug (SonOff Tasmota) which is configured via MQTT and this receives status update very quicky both from Alexa command and Real World.

Below is how Items are configured : The first not updating status and the secon updatig.

Switch          LivingRoom_Light2       "Luce Destra"             <light>           (LivingRoom, gLight)             ["Lighting", "Switchable"]   {alexa="disable",channel="amazonechocontrol:smartHomeDevice:sssxxxsx:LivingRoom_Light2:powerState"}

Switch          LivingRoom_Power4       "Switch Albero di Natale"      <poweroutlet>     (LivingRoom, gPower)        ["Switch", "Switchable"]     {alexa="disable",channel="mqtt:topic:Raspberry:sonoff_natale:power"}

Perhaps if you shared the error…

The problem lies in the Amazon Control Binding. And it’s entirely possible that the Amazone Control Binding simply cannot not tell openHAB when the device is manually controlled. Not all APIs and technologies can do so. You need to research the binding settings and potential limitations to find out. I don’t use this binding so will not be of any further help.

In the Visual Studio Editor it’s red underlined and the error state the method of filed gLight is undefined

I’m realizing this as well after hours of trys and switch on/off by voice,by hands and by my wife :slight_smile:
My be I can post a query on that in the right section even if it seems strange this issue is not common to everyone using Alexa Control Binding. I still believe there is something wrong in my environment.

rule " Alexa refresh trigger"
when
//Member of gLight received update
Member of gLight changed
then
sw_alexa_refresh.sendCommand(ON)
end

I think my instructions were not clear.

Having this rule in openHAB does nothing, because we already knew that your voice commands to Alexa weren’t passing updates to openHAB. So what I meant is that you should create a rule in Alexa (NOT openHAB) that forces the proxy item to update. But I’m realizing now that maybe you can’t create rules in Alexa? If so, that was a bad assumption by me (I don’t use Alexa).

The explanation appears to be in the Smart Home Devices section of the documentation.

The polling interval configured in the Account Thing to get the state is specified in minutes and has a minimum of 10. This means it takes up to 10 minutes to see the state of a channel. The reason for this low interval is, that the polling causes a big server load for the Smart Home Skills.

So, this isn’t a problem with your environment, but a setting that you probably shouldn’t change. If that’s the case and you can’t create simple rules with Alexa, the solution would be to either have duplicate items in Alexa (and use the OH-provided ones) or find out if your lamps can be connected directly to OH.

Your instruction was very clear but I could not figure out how to set-up an Alexa rule.
This is the reason why at the end I am still stick with my issue.

I have read that document carefully but the item is not updating also after 10 minutes despite it is stated that the Binding will receive the current state of the lights.

I can imagine to duplicate all my items in Alexa but this will create an orrible issue with the vocal input: Alexa goes in confusionand does not know which of the two devices you would lice to command.

Unlikely there is not yet a Binding for the BTicino Live now Gateway K4500 … this would be the preferred solution as I have done with MQTT divices that are in Alexa as SmartHome devices but in OH as MQTT.
This issue remains open and maybe somene will find the right trick …
Meanwhile I will continue to think about a possible solution (the refresh was a not a totally bad idea).

Can you give the original Alexa items different names, so that it won’t get confused?

I’m really trying to understand this but it seems that the names I will put will be used also by OH in the PaperUI (may be not in Sitemap).
Also I am trying to configure all duplicates as Alexa wall plug. In this way they will go in an area that will not disturb so much. I will make some tries and if I find a good workaround I will post my solution. Thanks for your time.
Meanwhile , it seems there is a bug in the echocontrol binding that should be fixed now. In 2.5.11-SNAPSHOT (thanks to @J-N-K Amazon Echocontrol - SmartHomeDevices not updated)

Edit:
For who will read this comment I confirm that 2.5.11 solves the issue and no more need of refresh.

1 Like