Configuration rules

Hello community.
I Need that slider back to value 0 before Item “Volumen” receive update and to execute two (executeCommandLine), for that reason I have created a rule that execute the next code, at the end it send command 0, but I present the issue that this command(Volumen.sendCommand(0) execute indefinitely, it never stop.

2018-12-20 22:39:17.143 [ome.event.ItemCommandEvent] - Item 'Volumen' received command 0

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

2018-12-20 22:39:17.512 [INFO ] [.eclipse.smarthome.model.script.mqtt] - 

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

2018-12-20 22:39:17.518 [ome.event.ItemCommandEvent] - Item 'Volumen' received command 0

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

2018-12-20 22:39:17.885 [INFO ] [.eclipse.smarthome.model.script.mqtt] - 

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

2018-12-20 22:39:17.891 [ome.event.ItemCommandEvent] - Item 'Volumen' received command 0

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

2018-12-20 22:39:18.265 [INFO ] [.eclipse.smarthome.model.script.mqtt] - 

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

2018-12-20 22:39:18.270 [ome.event.ItemCommandEvent] - Item 'Volumen' received command 0

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

2018-12-20 22:39:18.634 [INFO ] [.eclipse.smarthome.model.script.mqtt] - 

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

2018-12-20 22:39:18.641 [ome.event.ItemCommandEvent] - Item 'Volumen' received command 0

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

2018-12-20 22:39:19.020 [INFO ] [.eclipse.smarthome.model.script.mqtt] - 

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

2018-12-20 22:39:19.032 [ome.event.ItemCommandEvent] - Item 'Volumen' received command 0

This is the Item

Number Volumen "Televisor [%d]"
This is the rule
rule "vol+"
when
Item Volumen received update
then
val eject=executeCommandLine("mosquitto_pub -u openhabian -P 7121799422 -t broadlink/televisor/boton/volsubir -m play-34ea346ff7ac" ,100000)
val eject1=executeCommandLine("mosquitto_pub -u openhabian -P 7121799422 -t broadlink/televisor/boton/volsubir -m play-34ea346ff7ac" ,100000)
 logInfo("mqtt", eject, eject1)
Volumen.sendCommand(0)
end

This is the Sitemap

Slider item=Volumen

Someone could help me show me what might be the error in this rule???

Hi, i don’t exactly what you want to do, but as understand your rule is a dead-end rule, as you send an update- Command to your Trigger-Item (Volumen), with Volumen.sendCommand(0).

1 Like

Peter has definitely identified one of the problems for sure.

To elaborate.

  1. Volumen receives an update
  2. Execute the two command lines
  3. I’m surprised you don’t get an error on the logInfo since it is incorrect syntax.
  4. You send a command to Volumen
  5. Volumen receives and update, return to step 2.

And so around and around you go never stopping.

That’s your first problem. The second problem is I believe the Slider can send more than one command based on one movement of the slider (I could be wrong on that point, I don’t use Sliders). This will cause the Rule to execute multiple times.

You need to use a Design Pattern: Proxy Item that gets displayed on your sitemap. This triggers a Rule that sends a command to Volumen. Then you need to send the 0 command back to the Proxy Item, which will break the infinite loop.

Hello fibu and Rich.
I just test this rule and it works fine, the mainly problem was I dont understood the difference between “received update” and “changed status”.

rule "vol+"
when
Item Volumen changed
then
val eject=executeCommandLine("mosquitto_pub -u openhabian -P 7121799422 -t broadlink/televisor/boton/volsubir -m play-34ea346ff7ac" ,100000)
val eject1=executeCommandLine("mosquitto_pub -u openhabian -P 7121799422 -t broadlink/televisor/boton/volsubir -m play-34ea346ff7ac" ,100000)
val eject2=executeCommandLine("mosquitto_pub -u openhabian -P 7121799422 -t broadlink/televisor/boton/volsubir -m play-34ea346ff7ac" ,100000)
 logInfo("mqtt", eject, eject1, eject2)
Volumen.sendCommand(0)
end

I wiil read the recomendation of Rich about Design Pattern: Proxy Item and I will use it in my proyect.

Thanks

Look at the docs for Rules which describes all the Rules triggers. The tl;dr is:

  • received command: triggers the Rule immediately only when an Item receives a command
  • changed: triggers the Rule when an Item changes state. The Item may change state as a result of a command or an update
  • received update: triggers when the Item receives an update. An update may not actually indicate that an Item changed state. A command to an Item will also cause that Item to update as well.
1 Like

Thanks rikoshak for your explanation about this concepts, from now to future that is very clear for me.

Thanks