Temperature get value site web

Good morning I’m trying to assign a numeric temperature value to uu items by collecting the data on a web page but I can’t assign it

ITEMS
Number TempTermostato < temperature >

RULES

rule “Stato Temperatura”
when
Time cron “0/10 * * * * ?”
then
var int Temp = sendHttpGetRequest(“http://192.168.1.80/tempT.php?idx=44”)
logInfo( “myRule” , "TemperaturaT is " + Temp)
TempTermostato.state = Temp
logInfo( “myRule” , "TemperaturaT is " + TempTermostato.state)
end

ERROR
2020-04-03 12:35:40.448 [INFO ] [clipse.smarthome.model.script.myRule] - TemperaturaT is 19
Error during the execution of rule ‘Stato Temperatura’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.core.library.items.NumberItem.setState(org.eclipse.smarthome.core.types.State) on instance: TempTermostato (Type=NumberItem, State=NULL, Label=null, Category=temperature)

Why?
Thanks

I believe state ist write protected
You need to use

TempTermostato.sendCommand(Temp)

or

TempTermostato.sendUpdate(Temp)
1 Like

Don’t forget your Temp is a string variable, your Item is a Number type.
TempTermostato.postUpdate(Temp)
will do its best to parse that string into a number.

I strongly advise adding a timeout to your http action.

Thanks another error, rules change with TempTermostato.postUpdate(Temp)

ERROR
2020-04-03 12:49:20.395 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘Stato Temperatura’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.postUpdate(org.eclipse.smarthome.core.items.Item,java.lang.Number) on instance: null

So, what does Temp contain? Your rule includes a logInfo() to tell you, may we see as well?

LOG

2020-04-03 13:00:20.336 [INFO ] [clipse.smarthome.model.script.myRule] - TemperaturaT is 19

2020-04-03 13:00:20.343 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘Stato Temperatura’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.Number) on instance: null

Solve change in

TempTermostato.postUpdate(Float::parseFloat(Temp))

Thanks

Don’t forget to address that timeout issue before you move on.

If you do not, your http request may wait forever and you rule will “hang up”.
When enough instances of your rule have hung up waiting, no other rules will be able to start.