Unable to add temperatures

So I’m trying to make a rule, with a Temperature, just a change on my setpoint Temperature for my heating.

I have the following calefaccion.items

Number:Temperature Temperatura_Programada "Temp. programada [%.2f ºC]" <temperature> (gGraficas, gDatosGraficas, gCaldera_Essen) [ "TargetTemperature" ]

And the following calefaccion.rules

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

What am I doing wrong?

What is the unit on Temperatura_TH10? Have you sent that to the log so you can see what it is?

I don’t know how to send it to the log, but on my sitemap it shows correct.

The weirdest thing is that I have another rule with this Temperatura_TH10 and it shows also OK

Also contained on calefaccion.items

Number:Temperature Temperatura_Actual "Temperatura actual [%.2f ºC]" <temperature> (gGraficas, gDatosGraficas, gCaldera_Essen, gTemp_Actual) [ "CurrentTemperature" ]

Also contained on my calefaccion.rules


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 

Have you seen that the Measurement Sign of

Number:Temperature Temperatura_Actual "Temperatura actual [%.2f ºC]" <temperature> (gGraficas, gDatosGraficas, gCaldera_Essen, gTemp_Actual) [ "CurrentTemperature" ]
and
Number:Temperature Temperatura_Programada "Temp. programada [%.2f ºC]" <temperature> (gGraficas, gDatosGraficas, gCaldera_Essen) [ "TargetTemperature" ]

is not the same as in your variables ?

I think it should look like:

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 

and look what the logger says.

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|"℃"

And I make some operation like

temperaturaComfort = Temperatura_TH10.state - CORRECCION_TERMOMETRO

and I log it. I have this:

Temperatura_TH10.state: 19.2 °C temperaturaComfort:  18.0 CORRECCION_TERMOMETRO: 1.2 °C

So, if i make some operation on the variable, I loose the Units

If I log the variable before the operation, the units are shown.

What should I do?

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.

Looks like he’s using Unicode U+2103, “Degrees Celcius”, which is a single character.

It needs to be “degrees” then “Capital C”.

Thank you all for trying to help.

temperaturaHisteresis = Temperatura_Programada.state as Number
logInfo("RADIADORES", "AntesdeOp TempActual: {} TempProgramada:  {} HISTERESIS: {}", Temperatura_Actual.state , Temperatura_Programada.state, temperaturaHisteresis)
temperaturaHisteresis = temperaturaHisteresis - HISTERESIS
logInfo("RADIADORES", "DespuesdeOp TempActual: {} TempProgramada:  {} HISTERESIS: {}", Temperatura_Actual.state , Temperatura_Programada.state, temperaturaHisteresis)

I tried with

val Number HISTERESIS = 0.6|"℃"
var Number temperaturaHisteresis = 0.0|"℃"

and I got this on my editor (Notepad ++, now I have it changed to UTF8 format)

2019-03-06 08:23:21.398 [INFO ] [se.smarthome.model.script.RADIADORES] - AntesdeOp TempActual: 18.9 °C TempProgramada:  19.000000000000007 °C HISTERESIS: 19.000000000000007 °C
2019-03-06 08:23:21.408 [INFO ] [se.smarthome.model.script.RADIADORES] - DespuesdeOp - TempActual: 18.9 °C TempProgramada:  19.000000000000007 °C HISTERESIS: 18.400000000000007

And I also tried with

val Number HISTERESIS = 0.6|"°C"
var Number temperaturaHisteresis = 0.0|"°C"

with this log

2019-03-06 08:36:17.680 [INFO ] [se.smarthome.model.script.RADIADORES] - AntesdeOp TempActual: 19.1 °C TempProgramada:  19.200000000000006 °C HISTERESIS: 19.200000000000006 °C
2019-03-06 08:36:17.700 [INFO ] [se.smarthome.model.script.RADIADORES] - DespuesdeOp - TempActual: 19.1 °C TempProgramada:  19.200000000000006 °C HISTERESIS: 18.600000000000006

Why do I loose the Unit of Measure after the operation?

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

test.items

Switch             Dummy4                       "Testschalter Dummy4 [%s]"                            (gPower)
Number             Temperatura_Programada       "Temp. programada [%.2f C]"             <temperature> (Chart_Sys_Temp) [ "TargetTemperature" ]
Number:Temperature Temperatura_Actual           "Temperatura actual [%.2f ºC]"          <temperature> (Chart_Sys_Temp) [ "CurrentTemperature" ]
Number             Sonoff_Power_Strip_01_Temp  "Steckdosenleiste 1 Temperatur[%.1f °C]" <temperature> (Chart_Sys_Temp,EG_Kind1,gRtIstI)  mqtt="<[peter:tele/th16_01/SENSOR:state:JSONPATH($.AM2301.Temperature)]" }


and the logger shows then

2019-03-07 13:10:22.858 [INFO ] [home.model.script.Temperatura before] - Temperatura_Programada: 22.4 CORRECCION_TERMOSTATO: 0.6   CORRECCION_TERMOMETRO: 1.2
2019-03-07 13:10:22.868 [INFO ] [thome.model.script.Temperatura after] - Temperatura_Programada: 21.8 CORRECCION_TERMOSTATO 0.6:
2019-03-07 13:10:22.873 [INFO ] [ome.model.script.Temperatura TH10/16] - Temperatura di Pedro: 19.8
2019-03-07 13:10:22.878 [INFO ] [ome.model.script.Temperatura TH10/16] - Temperatura di Pedro OffSet: 18.6

And the result in my basic UI looks like


As you can see the Output looks quite ok, even not always using ºC, but only C in the .items-file.

So IMHO the best way would be not using the Measurement-signs (pattern/units) in your rule. As you don’t need them in the rule.
Cheers,
Peter

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.

I found this in the docs. Maybe it can help you.

Cheers,
Peter