Please use code fences, otherwise it’s impossible to understand your rule
And after that: What exactly are you trying?
I’ve understood that you want to have a rule that shall display different content on a certain value of your variable “contatore_pagina_display” correct?
Where shall the above code run? Is it a rule, is it a script? What is calling that script?
Are you running on openHAB 2 or openHAB 3?
Which userinterface (MainUI, BasicUI, Habpanel) are you using on your display?
I am using oh3 with mainUI the display is connected to an esp32 with tasmota firmware and communicates with openhab through MQTT. On the display at the moment I was able to see a page with two sensor temperatures. With the following code:
val mqttActions = getActions("mqtt","mqtt:broker:fe55cd989c")
mqttActions.publishMQTT("cmnd/T-display/displaytext","[C65535Ozf1]Temperatura Esterna:[C63488c1l2f2s2p-4]"+ PrevisioniMeteo_OutdoorTemperature.state.toFullString)
mqttActions.publishMQTT("cmnd/T-display/displaytext","[C65535Oc1l10df1]Temperatura Cucina:[C63488c1l4f2s2p-4]"+ sonoffTH16TempumidCucinaSwitchSensor_TH16TempumidCucinaSI7021Temperature.state.toFullString)
Now My aim now is to press a button on esp32 that activates the rule and increments the variable “counter_pagina_display” in order to display more pages and more data.
The idea was to activate the rule every change of the phisical button in order to enter the rule and increase the variable “Contatore_pagina_display” by 1
Ah, but every time you start the rule you create a new Contatore_pagina_display empty variable.
In a DSL rules file,you might use a global variable. But you can’t do that in a UI DSL rule.
You could use an Item of course, which survive between runs of the rule.
I net try i convert rules simple (1page) in to script (1page)
rule "Gestione T-display"
when
Item Tdisplay1TasmotaSwitchSensor_state changed to OPEN
then
val mqttActions = getActions("mqtt","mqtt:broker:fe55cd989c")
mqttActions.publishMQTT("cmnd/T-display/displaytext","[C65535Ozf1]Temperatura Esterna:[C63488c1l2f2s2p-4]"+ PrevisioniMeteo_OutdoorTemperature.state.toFullString)
mqttActions.publishMQTT("cmnd/T-display/displaytext","[C65535Oc1l10df1]Temperatura Cucina:[C63488c1l4f2s2p-4]"+ sonoffTH16TempumidCucinaSwitchSensor_TH16TempumidCucinaSI7021Temperature.state.toFullString)
end
In this way dont work
I try to simplyfy code in
rule "Gestione T-display"
when
Item Tdisplay1TasmotaSwitchSensor_state changed to OPEN
then
val mqttActions = getActions("mqtt","mqtt:broker:fe55cd989c")
mqttActions.publishMQTT("cmnd/T-display/displaytext","Temperatura Esterna:")
end
DONT WORK
IT IS MEANS THAT mqttActions.publishMQTT dont work in script-??? work only in rules page .
HELP
If in the script page i remove all and write only:
val mqttActions = getActions("mqtt","mqtt:broker:fe55cd989c")
mqttActions.publishMQTT("cmnd/T-display/displaytext","Temperatura Esterna:")
Why, what does it do? Show an error in your openhab.log? Publish a message that you didn’t expect? Is your rule ever triggered? You could add a log message to find out. Is your rules file even loaded? Again, your openhab.log will tell you. Did you put it in the right folder? It’s a rule, not a script.
2021-04-17 17:53:25.898 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'f3300ba980' failed: rule "Gestione T-display"
when
Item Tdisplay1TasmotaSwitchSensor_state changed to OPEN
then
val actions = getActions("mqtt","mqtt:broker:fe55cd989c")
actions.publishMQTT("cmnd/T-display/displaytext","[C65535Ozf1]Temperatura Esterna:[C63488c1l2f2s2p-4]"+ PrevisioniMeteo_OutdoorTemperature.state.toFullString)
actions.publishMQTT("cmnd/T-display/displaytext","[C65535Oc1l10df1]Temperatura Cucina:[C63488c1l4f2s2p-4]"+ sonoffTH16TempumidCucinaSwitchSensor_TH16TempumidCucinaSI7021Temperature.state.toFullString)
end)
other
2021-04-17 17:55:13.303 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'f3300ba980' failed: ___ rule ___ "Gestione T-display"
when
Item Tdisplay1TasmotaSwitchSensor_st ___ ate c ___ hanged to OPEN
then
val actions = getActions("mqtt","mqtt:broker:fe55cd989c")
actions.publishMQTT("cmnd/T-display/displaytext","[C65535Ozf1]Temperatura Esterna:[C63488c1l2f2s2p-4]"+ PrevisioniMeteo_OutdoorTemperature.state.toFullString)
actions.publishMQTT("cmnd/T-display/displaytext","[C65535Oc1l10df1]Temperatura Cucina:[C63488c1l4f2s2p-4]"+ sonoffTH16TempumidCucinaSwitchSensor_TH16TempumidCucinaSI7021Temperature.state.toFullString)
end
1. The method or field rule is undefined; line 1, column 0, length 4
2. The method or field when is undefined; line 2, column 31, length 4
3. The method or field changed is undefined; line 3, column 84, length 7
4. The method or field to is undefined; line 3, column 92, length 2
5. The method or field then is undefined; line 4, column 104, length 4
6. The method or field end is undefined; line 8, column 557, length 3
7. This expression is not allowed in this context, since it doesn't cause any side effects.; line 1, column 5, length 20
8. This expression is not allowed in this context, since it doesn't cause any side effects.; line 3, column 44, length 4
9. This expression is not allowed in this context, since it doesn't cause any side effects.; line 3, column 49, length 34
10. This expression is not allowed in this context, since it doesn't cause any side effects.; line 3, column 95, length 4
You have to put rules in a rules file named whatever.rules, and you have to put the file in a folder /rules that should already exist and hold a readme.txt file.
If this is all too complicated, stay with your UI rule but use an Item as your long-lived counter.