Rule if error

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

   "Temperature_8302000000000000": {
     "class": "org.eclipse.smarthome.core.items.ManagedItemProvider $ PersistedItem",
     "value": {
       "groupNames": [
         "gHome"
       ],
       "itemType": "Number",
       "tags": [],
       "label": "Bedroom",
       "category": "temperature"
     }
   },
   "Humidity_8302000000000000": {
     "class": "org.eclipse.smarthome.core.items.ManagedItemProvider $ PersistedItem",
     "value": {
       "groupNames": [
         "gHome"
       ],
       "itemType": "Number",
       "tags": [],
       "label": "Humidity Bedroom [% .1f]",
       "category": "Humidity"
     }
   },

I have little bindings, I use REST

I don’t know what you are referring to here. PaperUI? HABmin? Something else?

This label includes a [ format ] with bad syntax, an unwanted space. That wasn’t there three posts before.

Just use as Number. It still costs nothing.
if ( (Humidity_8302000000000000.state as Number) < 40) {

Are we just trolling now?

PaperUI

no trolling, I’m trying to figure out what not to use conversion to a number in the rule for all the items.

Made a test on the humidity sensor, corrected the parameters of the item:

   "Humidity_8302000000000000": {
     "class": "org.eclipse.smarthome.core.items.ManagedItemProvider $ PersistedItem",
     "value": {
       "groupNames": [
         "gHome"
       ],
       "itemType": "Number",
       "tags": [],
       "label": "Humidity Bedroom",
       "category": "Humidity"
     }
   },

rule:

  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/events.log <==
2019-07-08 15: 13: 40.611 [vent.ItemStateChangedEvent] - Mobile1_LastUpdate changed from 2019-07-08T15: 13: 38.523 + 0300 to 2019-07-08T15: 13: 40.609 + 0300

==> /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

==> /var/log/openhab2/events.log <==
2019-07-08 15: 13: 40.685 [vent.ItemStateChangedEvent] - Mobile1_LastUpdate changed from 2019-07-08T15: 13: 40.609 + 0300 to 2019-07-08T15: 13: 40.682 + 0300

Leave the “as Number” in the if-statement for Humidity so that it looks like your Temperature-If.

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

Lazy boy :wink: If you want to see your Humidity in the if-statement, please use greater than ( >) as it is 48.7

fyi : Comparision-possibilities for Quantity-Items (UoM)

.Item

Number:Length        localHourlyForecast3RainVolume          "in 03 Stunden Niederschlagsmenge [%.1f %unit%]"                        <rain>        (gOWM)  { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#rain" }

.rules

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

So now have fun.

Cheers,
Peter

1 Like

Lazy to read. Above, I wrote that I wanted to bring all settings to the ability to work in rules without dimension for all items.

Sorry, your’re right. I missed to read in your last post that you changed the operator :upside_down_face:

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.

1 Like

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:

  1. Return state as integer:
    if ((Humidity_8302000000000000.state as Number).intValue() <40)
  2. Return state as float:
    if ((Humidity_8302000000000000.state as Number).floatValue() <40.0)

I got it, thanks.

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

Number:Dimensionless basically means that the unit is one :slight_smile:

Dimensionless numbers don’t have a named unit, as hPa for pressure, m for distance, kWh for power consumption etc…

Special such type Number: Dimensionless =))

You didn’t ask for a dimension. Try

Number:Dimensionless PPM_8501000000000000 "Children’s CO2 [%.0f %%]"

and look at the REST again.