Hi.
OpenHAB received temperature from modbus, like “temperature*100”. (Temperature 23.45 I’m received as 2345)
How I must write rules for transrorm this items to back?
rule “Street_Temperature”
when
Item BME_Temperature received update
then
BME_Temperature = BME_Temperature/100
end
# more home.rules
org.eclipse.smarthome.core.items
org.eclipse.smarthome.core.persistence
org.eclipse.smarthome.core.library.types
org.eclipse.smarthome.core.library.items
org.eclipse.smarthome.model.script.actions
rule "Street_Temperature"
when
Item BME_Temperature received update
then
BME_Temperature.postUpdate(BME_Temperature.state/100)
end
Loading model ‘home.rules’
Configuration model ‘home.rules’ is either empty or cannot be parsed correctly!
Items: Number BME_Temperature "Температура на улице [%d °C]" <temperature> (gBME280) {modbus="slave5:0"}
Sitemaps:
Text label=“Weather”
{
Text item=BME_Temperature label=“Temperature”
}
For modbus incoming data, you can put the transform directly in the data thing. No rule or extra Item needed.
There are examples in the modbus documentation.
Rule ‘Street_Temperature’: An error occurred during the script execution: Could not access field: HomeRules.BME_Temperature on instance: null
Refreshing model ‘home.rules’
Rule ‘Street_Temperature’: Could not cast NULL to java.lang.Number; line 5, column 31, length 31
rule "Street_Temperature"
when
Item BME_Temperature100 changed
then
logInfo("BME_Temperature100:", BME_Temperature100.state.toString)
BME_Temperature.postUpdate((BME_Temperature100.state as Number) / 100)
end