Convert from int to Numberitem OH2 (and general conversion)?

Hello Guys…
I have defined a item:

Numberitem weekday

and in a rule wanna have the result from

weekday = now.getDayOfWeek

Then the Smarthome Designer isn’t happy about the result from now.getDayOfWeek is format int, and the other is Numberitem…

I can’t find a way to convert it so it’ll be happy? as far as i can read, the NumberItem can be int, float and so on…

I think it’s very hard to figure out how to manage all the datatypes which basically only is numbers… But i think often i delal with a lot of problems, where it says the number is BigDecimal and can’t convert to NumberItem - but i can’t see anywhere how to deal with this?

Basically it’s the same like the first problem, where it can’t convert int to NumberItem…

Please explain someone :slight_smile:

Hi Rasmus,

You need to define a variable above the start of the rule

var int weekdayint

In the rule:


That’s about it!


Shouldn’t it be just

Number weekday


1 Like

Defined in the item file?
What’s the difference of number and numberitem?

The item can be defined only like this, example:

Switch Item_name01
Number Item_name02
String Item_name03
Contact Item_name04

You don’t write Numberitem, just Number!


1 Like

Hmm i understand, but can’t see why - also still problem:

In Items file

Number Heatpump_actual_day	

In my Rule:

rule "Opdater aktuel dag"
	Time is midnight
		if (Heatpump_actual_day != now.getDayOfWeek)
			var int weekint
			weekint = now.getDayOfWeek
			Heatpump_actual_day = weekint 

The Designer wouldn’t accept the "Heatpump_actual_day = weekint " since it can’t convert from Int to Number


It’s Number, because it represents item type, and item types are defined somewhere (OH core, ESH core), the same way you can’t use, for example, MyInteger as type in C++ instead of int.

At the first glance, there are two problems in your rule:

  1. You must use Item.state != Value instead of Item != Value (Heatpump_actual_day.state != now.getDayOfWeek)
  2. You can’t assign value to an item. You must use sendCommand or postUpdate. In your case, you should use postUpdate(Heatpump_actual_day, weekint) or Heatpump_actual_day.postUpdate(weekint)

Best regards,

Okay, meaning when an item is defined as etc. “Number” i simply can’t assign Number = 5.0, i must use the postUpdate(Item, intvalue).?

Yes i know about the .state - was just trying different things since nothing worked for me :slight_smile: sorry for that…


As far as I know, you have to use postUpdate/sendCommand. Maybe someone involved in ESH can explain it more thoroughly. I just saw that as an error, so I thought I should warn you about it. You don’t have to be sorry, we are all here to help each other.

Best regards,

Thanks a lot - Great to be better - i’ll test that :slight_smile:

You use sendCommand when you want to command something to change, like turning a light ON or setting a thermostat setpoint to a new numeric value. You use postUpdate when you want the state of an item to change to a new value, like the current weather conditions.

Bindings are typically doing postUpdates internally, and listening for commands to interpret and forward to the connected systems, but of course you can do either/both in your own custom rules or over the API.