In the item settings interface, you can not set the Dimension, it is allowed. Here is the result of this setup from /var/lib/openhab2/jsondb/org.eclipse.smarthome.core.items.Item.json
if ((Humidity_8302000000000000.state as Number) <40) {
logInfo ("Records when device mobile1 was last seen", "Humidity_8302000000000000.state =" + Humidity_830200000000000000.state + "IF")
}
There is no output in the logs with “IF”, again a dead end.
Just try without the if-statement to see what the loginfo shows. What you also can do is to look for the item-state, is to use the console (openhab-cli console) and the enter something like this:
At first, the value is displayed without conditions, then after the condition has been triggered. And there are neither% nor other dimensions.
All rule:
rule "Records when device mobile1 was last seen"
when
Item Temperature_83020000000000 received update or
Item Humidity_8302000000000000 received update or
Item Voltage_8302000000000000 received update
then
logInfo ("Records when device mobile1 was last seen", "BEGIN")
logInfo ("Records when device mobile1 was last seen", "Temperature_8302000000000000.state =" + Temperature_830200000000000000.state)
logInfo ("Records when device mobile1 was last seen", "Humidity_8302000000000000.state =" + Humidity_830200000000000000.state)
postUpdate (Mobile1_LastUpdate, new DateTimeType ())
if (Temperature_8302000000000000.state <40) {
logInfo ("Records when device mobile1 was last seen", "Temperature_8302000000000000.state =" + Temperature_830200000000000000.state + "IF")
}
if ((Humidity_8302000000000000.state as Number) <40) {
logInfo ("Records when device mobile1 was last seen", "Humidity_8302000000000000.state =" + Humidity_830200000000000000.state + "IF")
}
/ **
if (Temperature_8302000000000000.state <40 | ° C) {
logInfo ("Records when device mobile1 was last seen", "Temperature_8302000000000000.state =" + Temperature_830200000000000000.state + "IF ° C")
}
* /
logInfo ("Records when device mobile1 was last seen", "END")
end
Log:
==> /var/log/openhab2/openhab.log <==
2019-07-08 15: 13: 40.608 [INFO] [ds when device mobile1 was last seen] - BEGIN
2019-07-08 15: 13: 40.608 [INFO] [ds when device mobile1 was last seen] - Temperature_83020000000000.state = 26.7
2019-07-08 15: 13: 40.609 [INFO] [ds when the device mobile1 was last seen] - Humidity_83020000000000.state = 48.3
==> /var/log/openhab2/openhab.log <==
2019-07-08 15: 13: 40.612 [INFO] [ds when the device mobile1 was last seen] - Temperature_8302000000000000.state = 26.7 IF
2019-07-08 15: 13: 40.613 [INFO] [ds when device mobile1 was last seen] - END
2019-07-08 15: 13: 40.681 [INFO] [ds when device mobile1 was last seen] - BEGIN
2019-07-08 15: 13: 40.681 [INFO] [ds when the device mobile1 was last seen] - Temperature_8302000000000000.state = 26.7
2019-07-08 15: 13: 40.682 [INFO] [ds when device mobile1 was last seen] - Humidity_83020000000000.state = 48.3
2019-07-08 15: 13: 40.683 [INFO] [ds when the device mobile1 was last seen] - Temperature_8302000000000000.state = 26.7 IF
2019-07-08 15: 13: 40.684 [INFO] [ds when device mobile1 was last seen] - END
rule "Records when device mobile1 was last seen"
when
Item Temperature_8302000000000000 received update or
Item Humidity_8302000000000000 received update or
Item Voltage_8302000000000000 received update
then
logInfo("Records when device mobile1 was last seen", "BEGIN")
logInfo("Records when device mobile1 was last seen", "Temperature_8302000000000000.state=" + Temperature_8302000000000000.state)
logInfo("Records when device mobile1 was last seen", "Humidity_8302000000000000.state=" + Humidity_8302000000000000.state)
postUpdate(Mobile1_LastUpdate, new DateTimeType())
if (Temperature_8302000000000000.state < 40){
logInfo("Records when device mobile1 was last seen", "Temperature_8302000000000000.state=" + Temperature_8302000000000000.state + " IF")
}
if (Humidity_8302000000000000.state < 40){
logInfo("Records when device mobile1 was last seen", "Humidity_8302000000000000.state=" + Humidity_8302000000000000.state + " IF")
}
/**
if (Temperature_8302000000000000.state < 40|°C){
logInfo("Records when device mobile1 was last seen", "Temperature_8302000000000000.state=" + Temperature_8302000000000000.state + " IF °C")
}
*/
logInfo("Records when device mobile1 was last seen", "END")
end
rule "Records when device mobile2 was last seen"
when
Item Temperature_8303000000000000 received update or
Item Humidity_8303000000000000 received update or
Item Voltage_8303000000000000 received update
then
postUpdate(Mobile2_LastUpdate, new DateTimeType())
end
Log:
==> /var/log/openhab2/openhab.log <==
2019-07-08 15:28:46.858 [INFO ] [ds when device mobile1 was last seen] - BEGIN
2019-07-08 15:28:46.859 [INFO ] [ds when device mobile1 was last seen] - Temperature_8302000000000000.state=26.8
2019-07-08 15:28:46.860 [INFO ] [ds when device mobile1 was last seen] - Humidity_8302000000000000.state=48.7
2019-07-08 15:28:46.861 [INFO ] [ds when device mobile1 was last seen] - Temperature_8302000000000000.state=26.8 IF
2019-07-08 15:28:46.862 [INFO ] [ds when device mobile1 was last seen] - END
==> /var/log/openhab2/events.log <==
2019-07-08 15:28:46.863 [vent.ItemStateChangedEvent] - Mobile1_LastUpdate changed from 2019-07-08T15:28:46.776+0300 to 2019-07-08T15:28:46.860+0300
my mistake, the condition will always be a lie, changed the sign to the opposite, it worked. I will change OH2 configs by analogy:
rule "Records when device mobile1 was last seen"
when
Item Temperature_83020000000000 received update or
Item Humidity_8302000000000000 received update or
Item Voltage_8302000000000000 received update
then
logInfo ("Records when device mobile1 was last seen", "BEGIN")
logInfo ("Records when device mobile1 was last seen", "Temperature_8302000000000000.state =" + Temperature_830200000000000000.state)
logInfo ("Records when device mobile1 was last seen", "Humidity_8302000000000000.state =" + Humidity_830200000000000000.state)
postUpdate (Mobile1_LastUpdate, new DateTimeType ())
if (Temperature_8302000000000000.state <40) {
logInfo ("Records when device mobile1 was last seen", "Temperature_8302000000000000.state =" + Temperature_830200000000000000.state + "IF")
}
if (Humidity_8302000000000000.state> 40) {
logInfo ("Records when device mobile1 was last seen", "Humidity_8302000000000000.state =" + Humidity_830200000000000000.state + "IF")
}
/ **
if (Temperature_8302000000000000.state <40 | ° C) {
logInfo ("Records when device mobile1 was last seen", "Temperature_8302000000000000.state =" + Temperature_830200000000000000.state + "IF ° C")
}
* /
logInfo ("Records when device mobile1 was last seen", "END")
end
rule "Rain warning"
when
Item localHourlyForecast3RainVolume changed
then
if(localHourlyForecast3RainVolume.state >0.01 | "mm") {
logInfo("RainVolume","RainVolume with Pattern: " + localHourlyForecast3RainVolume)
} // works
if( (localHourlyForecast3RainVolume.state as Number).floatValue > 0.01) {
logInfo("RainVolume","RainVolume as Float for comparison: " + localHourlyForecast3RainVolume)
} // works
var vRainVol = (localHourlyForecast3RainVolume.state as Number).floatValue
if( vRainVol > 4) {
logInfo("RainVolume","RainVolume with changed Variable: " + vRainVol)
} // works
end
This is not possible. Some bindings, including OpenWeatherMap, require the use of Items with a Unit of Measure. If the binding requires a Number:Temperature or Number:Dimensionless, then you must use them like Peter demonstrated. There is no way around that.
The only way to avoid using UoM in Rules is to use Items that are not defined with UoM (i.e. Number). The only way you can use Items that are not defined with UoM is if the binding allows that.
Thanks for the answer.
How correctly in the rules to convert the value of the item to a number?
In the subject there were two options:
1. if (localHourlyForecast3RainVolume.state> 0.01 | "mm")
2. if ((Humidity_8302000000000000.state as Number) <40)
When using as Number conversion, it basically means that you’re asking OpenHAB to expose all <Number>value() event state conversion methods to your rule at that place in your code. You’re now only one step away from getting what you want: all you need to do, is cast the as Number to the Number type you need.
For your application, I suppose you’ll either want integer or normal-precision floating-point numbers, so you’d either use one of:
Return state as integer: if ((Humidity_8302000000000000.state as Number).intValue() <40)
Return state as float: if ((Humidity_8302000000000000.state as Number).floatValue() <40.0)
The last question, where or how to see information on the dimension of the item “as it is now”?
Peter offered through the “openhab-cli console”, maybe there is another option.
I tried through “/rest/items?recursive=false”, there is a dimension for everything except “type”: “Number: Dimensionless”. You just need to remember about this type?
Example my rest responce:
“link”: “http://123/rest/items/PPM_8501000000000000”,
“state”: “399.0”,
“editable”: true,
“type”: “Number:Dimensionless”,
“name”: “PPM_8501000000000000”,
“label”: “Children’s CO2 [%.0f]”,
“category”: “carbondioxide”,
“tags”: [],
“groupNames”: [
“gHome”
]
},
{
“link”: “http://123/rest/items/Work_Pressure_mmHg”,
“state”: “0.0 hPa”,
“editable”: true,
“type”: “Number:Pressure”,
“name”: “Work_Pressure_mmHg”,
“label”: “Work_Pressure [%.2f mm Hg]”,
“category”: “Pressure”,
“tags”: [],
“groupNames”: []
}, indent preformatted text by 4 spaces