rule "calculate percent from cm"
when
Item EspsonicCiterne changed
then
EspsonicCiterne_percent.postUpdate(100 - ((((EspsonicCiterne.state as DecimalType) -25)*(100))/(180-25)))
end
Ok so here is what i do , i use the dedicate Transformation service to solve this case, again thanks all for your help.
I use the scale Transformation services,
i create i file named “CiterneCmToPourcent.scale” inside i write this:
[…18]=100 //[…18 ]for cm and 100 for pourcent
]18…20]=99
]20…22]=98
]22…24]=97
]24…26]=96
]26…28]=95
]28…30]=94
]30…32]=93
]32…34]=92
exc… to 0
Then i a item file i create a new Item type String.
Here is the original value from the sensor:
Number EspsonicCiterne “Niveau citerne eau de Pluie [%s cm]” {channel=“mqtt:topic:OpenhabDht22:Espsonic”}
There is the new item converted to pourcent value with the profile transform:SCALE:
String EspsonicCiterneRestant "Citerne en % restant " { channel=“mqtt:topic:OpenhabDht22:Espsonic”[profile=“transform:SCALE”, function=“CiterneCmToPourcent.scale”]}
then in sitemap:
Default item=EspsonicCiterneRestant label=“Niveau Citerne restant [%d %%]” labelcolor=[“green”] //the labelcolor need to be chose when state is below…75% ou 50% for exemple…i don’t know how actually