val Number CORRECCION_TERMOMETRO = 1.2|"℃"
val Number CORRECCION_TERMOSTATO = 0.6|"℃"
val Number TEMPERATURA_CARGA_TERMOSTATO = 21.8|"℃"
rule "Encender el termostato a la 1:00, a las 13:00 y a las 9:30 para que se cargue y pille el cambio de temperatura - El termostato está retrasado 43 segundos "
when
Time cron "35 0 1 1/1 * ? *" or //A la 1:00 (1:00:35 teniendo en cuenta el retraso del termostato) T1
Time cron "0 0 7 1/1 * ? *" or // 7:00 T5
Time cron "35 30 9 1/1 * ? *" or // 9:30 T1
Time cron "0 30 11 1/1 * ? *" or // 11:30 T5
Time cron "35 0 13 1/1 * ? *" or // 13:00 T1
Time cron "0 0 16 1/1 * ? *" or // 16:00 T5
Time cron "0 33 11 1/1 * ? *"
then
Temperatura_Programada.sendCommand( Temperatura_TH10.state as Number + CORRECCION_TERMOSTATO )
end
The Item Temperatura_TH10 is defined via Paper UI
Type: Number
category: temperature
Dimension: Temperature
But the result that I got is not the expected. I got more than 200 ºC
rule "Corrección de la lectura del termómetro"
when
Item Temperatura_TH10 changed
then
Temperatura_Actual.sendCommand( (( Temperatura_TH10.state as Number ) - CORRECCION_TERMOMETRO ) )
end
Number:Temperature Temperatura_Actual "Temperatura actual [%.2f °C]"
or
Number:Temperature Temperatura_Actual "Temperatura actual [%.2f %unit%]"
On the other hand the calculation of the first rule looks a bit different from the second one (Brackets).
For Logging try this:
rule "Encender el termostato a la 1:00, a las 13:00 y a las 9:30 para que se cargue y pille el cambio de temperatura - El termostato está retrasado 43 segundos "
when
Time cron "35 0 1 1/1 * ? *" or //A la 1:00 (1:00:35 teniendo en cuenta el retraso del termostato) T1
Time cron "0 0 7 1/1 * ? *" or // 7:00 T5
Time cron "35 30 9 1/1 * ? *" or // 9:30 T1
Time cron "0 30 11 1/1 * ? *" or // 11:30 T5
Time cron "35 0 13 1/1 * ? *" or // 13:00 T1
Time cron "0 0 16 1/1 * ? *" or // 16:00 T5
Time cron "0 33 11 1/1 * ? *"
then
logInfo("Temperatura before","Temperatura_Programada: {} Temperatura_TH10 {}:", Temperatura_Programada.state, Temperatura_TH10.state)
Temperatura_Programada.sendCommand( Temperatura_TH10.state as Number + CORRECCION_TERMOSTATO )
logInfo("Temperatura after","Temperatura_Programada: {} Temperatura_TH10 {}:", Temperatura_Programada.state, Temperatura_TH10.state)
end
I will try to explain what happens.
When I use only Items with temperature unit, it all works as expected.
If I want to use some variable defined like this
var Number temperaturaComfort = 21.0|"℃"
val Number CORRECCION_TERMOMETRO = 1.2|"℃"
the pattern you’re using are not in the correct format. I don’t know what editor you’re using and the file type, but it should be a utf8 format.
So try this:
var Number temperaturaComfort = 21.0|"°C"
val Number CORRECCION_TERMOMETRO = 1.2|"°C"
The Pattern/Measurement-Signs are not the same as you are using, so the logger will show with your patterns 19.2 °C which is not correct.
I think the way you want to go is not purposeful in this case,. I made several tests and always got the problems with the measurement patterns in the rule. Maybe there is another problem, as you are using no binding in your items-file, which would use UoM.
I made some tests with the following setup:
test.rules
rule "test Temperatura_Programada"
when
Item Dummy4 changed to ON
then
val Number CORRECCION_TERMOMETRO = 1.2
val Number CORRECCION_TERMOSTATO = 0.6
val Number TEMPERATURA_CARGA_TERMOSTATO = 21.8
var Number Temp_OffSet = 0
Temperatura_Programada.sendCommand( TEMPERATURA_CARGA_TERMOSTATO)
Temperatura_Actual.sendCommand(23.0)
logInfo("Temperatura before","Temperatura_Programada: {} CORRECCION_TERMOSTATO: {} CORRECCION_TERMOMETRO: {}", Temperatura_Programada.state, CORRECCION_TERMOSTATO,CORRECCION_TERMOMETRO)
Temperatura_Programada.sendCommand( TEMPERATURA_CARGA_TERMOSTATO + CORRECCION_TERMOSTATO )
logInfo("Temperatura after","Temperatura_Programada: {} CORRECCION_TERMOSTATO {}:", Temperatura_Programada.state, CORRECCION_TERMOSTATO)
logInfo("Temperatura TH10/16", "Temperatura di Pedro: {}", Sonoff_Power_Strip_01_Temp.state )
Temp_OffSet = Sonoff_Power_Strip_01_Temp.state as Number - CORRECCION_TERMOMETRO
logInfo("Temperatura TH10/16", "Temperatura di Pedro OffSet: {}", Temp_OffSet )
end
Thanks for your help. I had also solved with something similar as you say, but I would like to know why variables don’t keep the UOM after an operation.
It has, as I see it, nothing to do with bindings, as the variable looses the UOM with operations that only involve variables and values.