Rules for transform

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

It is not worked…

rule “Street_Temperature”
when
    Item BME_Temperature received update
then
    BME_Temperature.postUpdate(BME_Temperature.state / 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!

:frowning:

Items:
Number BME_Temperature "Температура на улице [%d °C]" <temperature> (gBME280) {modbus="slave5:0"}

Sitemaps:
Text label=“Weather”
{
Text item=BME_Temperature label=“Temperature”
}

Remove ALL this:

# 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

STOP!!

That will not work. We’ll create an infinite loop

You need to create another item:

Number BME_Temperature100 (gBME280) {modbus="slave5:0"}
Number BME_Temperature "Температура на улице [%.1f °C]" <temperature>
rule "Street_Temperature"
when
    Item BME_Temperature100 changed
then
    BME_Temperature.postUpdate(BME_Temperature100.state / 100)
end

2019-02-18_14-59-05
I’m in the hell… :slight_smile:

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.

Sorry, but this not worked… On the site “Temperature” is empty…

What didn’t work?
Post your items now and you rule file

#more rules/home.rules

rule "Street_Temperature"

when
    Item BME_Temperature100 changed
then
    BME_Temperature.postUpdate(BME_Temperature100.state/100)
end

Items:

Number BME_Temperature100 (gBME280) {modbus=“slave5:0”}
Number BME_Temperature “Температура на улице [%.1f °C]”

In log:

Rule ‘Street_Temperature’: Unknown variable or command ‘/’; line 6, column 32, length 28

    BME_Temperature.postUpdate((BME_Temperature100.state as Number) / 100)

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

What’s in the log?

1 Like

Sorry, all worked! I’m wrong… :slight_smile:

THX!!!