[SOLVED] Type mismatch

Raspi 3B
Installation: Openhabian
openHAB 2.4.0 Build # 1381
Aeotec Z-Stick Gen5 Platform information:

Ask for help, I have read a lot and tried, but I can not get further:

var Number soll1EinWZ

soll1EinWZ = (Uhr1_H_Ein_WZ.state as Number) * 60 + (Uhr1_M_Ein_WZ.state as Number)

it does not work

logInfo("time1_Ein_WZ","Einschaltzeit 1 {}",now.withTimeAtStartOfDay.plusMinutes(soll1EinWZ).getAsText)

is working

logInfo("time1_Ein_WZ","Einschaltzeit 1 {}",now.withTimeAtStartOfDay.plusMinutes(5).getAsText)

how can I convert that?

Try with this

var Number soll1EinWZ = (Uhr1_H_Ein_WZ.state as Number) * 60 + (Uhr1_M_Ein_WZ.state as Number)

1 Like

The plusMinutes() etc. methods are unusual in wanting an integer value, xxx.plusMinutes( soll1EinWZ.intValue )

error message:

{
	"resource": "/etc/openhab2/rules/Thermostat.rules",
	"owner": "_generated_diagnostic_collection_name_#0",
	"code": "org.eclipse.xtext.xbase.validation.IssueCodes.incompatible_types",
	"severity": 8,
	"message": "Type mismatch: cannot convert from Number to int",
	"startLineNumber": 181,
	"startColumn": 83,
	"endLineNumber": 181,
	"endColumn": 93
}```

Val Integer soll1EinWZ

	val int soll1EinWZ = (Uhr1_H_Ein_WZ.state as Number) * 60 + (Uhr1_M_Ein_WZ.state as Number)

{
	"resource": "/etc/openhab2/rules/Thermostat.rules",
	"owner": "_generated_diagnostic_collection_name_#0",
	"code": "org.eclipse.xtext.xbase.validation.IssueCodes.incompatible_types",
	"severity": 8,
	"message": "Type mismatch: cannot convert from BigDecimal to Integer",
	"startLineNumber": 178,
	"startColumn": 27,
	"endLineNumber": 178,
	"endColumn": 97
}
var temp1 = Uhr1_H_Ein_WZ.state as Number
var temp2 = Uhr1_M_Ein_WZ.state as Number

var soll1EinWZ = ((temp1) * 60) + (temp2)

No, I want the time from the item Uhr1_H_Ein_WZ (hour) und Uhr1_M_Ein_WZ (minutes * 60)

soll1EinWZ = (Uhr1_H_Ein_WZ.state as Number) * 60 + (Uhr1_M_Ein_WZ.state as Number)

with

logInfo("time1_Ein_WZ","Einschaltzeit 1 {}",now.withTimeAtStartOfDay.plusMinutes(soll1EinWZ).getAsText)

report

For some reason I was thinking temp.:roll_eyes:

You just want the number to plugin, if you move the brackets for the math does it work?

1 Like

I’ve already tried that
I test since yesterday, but always the error is always similar

	"resource": "/etc/openhab2/rules/Thermostat.rules",
	"owner": "_generated_diagnostic_collection_name_#0",
	"code": "org.eclipse.xtext.xbase.validation.IssueCodes.incompatible_types",
	"severity": 8,
	"message": "Type mismatch: cannot convert from BigDecimal to int",
	"startLineNumber": 183,
	"startColumn": 83,
	"endLineNumber": 183,
	"endColumn": 93
}
{
	"resource": "/etc/openhab2/rules/Thermostat.rules",
	"owner": "_generated_diagnostic_collection_name_#0",
	"code": "org.eclipse.xtext.diagnostics.Diagnostic.Linking",
	"severity": 8,
	"message": "The method or field getAsText is undefined for the type DateTime",
	"startLineNumber": 183,
	"startColumn": 95,
	"endLineNumber": 183,
	"endColumn": 104
}``

I do not understand that it works with “5” but not with the var number.


logInfo("time1_Ein_WZ","Einschaltzeit 1 {}",now.withTimeAtStartOfDay.plusMinutes(5).getAsText)``

I’m not at my OH server so hard to test but using val integer soll1EinWZ = Uhr1_H_Ein_WZ.state as Number should cast this into an integer. Try changing the var to val on time1 and time2 and add logging after each to see if the val is being created and what it is.

1 Like

The mistake comes here too:

time1_Ein_WZ = createTimer(now.withTimeAtStartOfDay.plusMinutes(soll1EinWZ)

{
	"resource": "/etc/openhab2/rules/Thermostat.rules",
	"owner": "_generated_diagnostic_collection_name_#0",
	"code": "org.eclipse.xtext.xbase.validation.IssueCodes.incompatible_types",
	"severity": 8,
	"message": "Type mismatch: cannot convert from BigDecimal to int",
	"startLineNumber": 210,
	"startColumn": 69,
	"endLineNumber": 210,
	"endColumn": 79
}

Try it this way

1 Like

Thanks, that’s it! Do you get that in a line?
I have 36 times to work.
similar:


	val int soll1EinWZ = (Uhr1_H_Ein_WZ.state as DecimalTyp) * 60 + (Uhr1_M_Ein_WZ.state as DecimalType)

Are you asking if this can be on a single line?

If so, try this:

val interger soll1EinWZ = ((Uhr1_M_Ein_WZ.state as DecimalType).intValue * 60) + (Uhr1_H_Ein_WZ.state as DecimalType).intValue