sendCommand is not updating the value

  • Platform information:
    • Hardware: NAS with Intel CPU and 16GB
    • OS: OpenHab Container image
    • Java Runtime Environment: OpenHab Container image
    • openHAB version: 4.1.2

Dear all,

I have a rule which updates an item via senCommand. Afterwards it uses the item to compile a http request. Unfortunately not every time the value is updated on time, as I can see it also in the logs.

The rule:

if (WR_VoltageBulk_timer === null) {            
	        WR_VoltageBulk_timer = createTimer(now.plusSeconds(300)) [|
                if (WR1_Bat_Voltage_Number >= Set_Bat_Voltage_Number) {
                    Set_Bat_Voltage_Number = Set_Bat_Voltage_Number + 0.3
  	                Set_Bat_Spannung.sendCommand(Set_Bat_Voltage_Number)
                    Set_Bat_Spannung.sendCommand(Set_Bat_Voltage_Number)
                    logInfo("Rules", "Bat Spannung "+Set_Bat_Spannung.state.format("%.1f").toString)
                    sendHttpPostRequest("http://192.168.249.44/befehl.steuerung.php?befehl=PCVV"+Set_Bat_Spannung.state.format("%.1f").toString+"&id=1")
                    sendHttpPostRequest("http://192.168.249.44/befehl.steuerung.php?befehl=PBFT"+Set_Bat_Spannung.state.format("%.1f").toString+"&id=1")
                    telegramAction.sendTelegram("Batteriespannung automatisch erhöht auf "+Set_Bat_Spannung.state.format("%.1f").toString+"V.")
                    logInfo("Rules", "Bat Spannung "+Set_Bat_Spannung.state.format("%.1f").toString)
                }
	            WR_VoltageBulk_timer = null
            ]
	    }

I write before and after the http requests are send the values to the log files. Sometimes I can oberve the value is not updated. E.g.

2024-05-18 09:34:02.504 [INFO ] [org.openhab.core.model.script.Rules ] - Bat Spannung 51.0
2024-05-18 09:34:02.588 [INFO ] [org.openhab.core.model.script.Rules ] - Bat Spannung 51.3

What can I do, to prevent this?

Thank you!

Many bindings have clearly separated two direction communications structure as follows…

  1. Writing to (commanding) the device: OH pushes a new state value to the remote physical device via (say) an HTTP POST request.
  2. Reading from (polling) the device: OH pulls the current state value from the remote physical device via (say) an HTTP GET request.

Your sendCommand will probably cause a write command (1.) to the device. But you probably need to wait for the next read command (2.) before the new value is updated.

As a general rule, a write command does NOT automatically cause a subsequent read command.

However SOME bindings may short circuit to the new state by ASSUMING that the new state is indeed the value that was commanded (however that is only an assumption, and may very well be wrong).

And SOME bindings may indeed trigger a read command (2.) after a write command (1.) is sent. However even this may take some time, so the value will probably not be evident from within the running time of your rule.

1 Like

Try use the variable ’ Set_Bat_Voltage_Number’ to send your http request and telegram message…

sendHttpPostRequest("http://192.168.249.44/befehl.steuerung.php?befehl=PCVV"+Set_Bat_Voltage_Number.toString+"&id=1")
telegramAction.sendTelegram("Batteriespannung automatisch erhöht auf "+Set_Bat_Voltage_Number.toString+"V.")

Greets