For the first error I think you just need to call toString() on the QuantityType. Using the Python str() function might work too.
The second error I think has to do with the fact that Python 2.7 doesn’t support UTF by default. I can’t remember if I ever tried to log a Temperature like that back when I was using Python.
Wait, instead of renaming your Items, why not be clever here. You could create a library function that you can call with a state. That function will convert the state to a string no matter what type of state you pass to it. In the function determine if the state is a QuantityType and handle that differently. Then you can use that function everywhere and know it will work and work the same way no matter what type of state it is.
Brilliant. I like it. I’ve been burned on other Items as well … scratched my head a bit on being forced into having to do this:
rThermostat_SetPoint.log.info("Thermostat temp manually set to " + HeatOverrideTemp.toString() + " for " + str(int(str(items["ThermostatCT101_HeatOverrideMinutes"])) * MINUTES))
Had to convert the items["ThermostatCT101_HeatOverrideMinutes"]) to a string first, then to an int() to do the arithmetic and then to a str() to display it … I didn’t spend too much time on it so I’m sure (I hope) there’s an explanation (the Item is defined as a Number)
Edit: using this:
rThermostat_SetPoint.log.info("Thermostat temp manually set to " + HeatOverrideTemp.toString() + " for " + str(items["ThermostatCT101_HeatOverrideMinutes"].intValue() * MINUTES))
A Number Item’s state is of type DecimalType. A DecimalType in turn is of type Number. But neither a DecimalType nor a Number is nor is it compatible with a Python int. To do math all the operands have to be compatible. So you either need to convert your Python int to a java.lang.Number or you need to convert your DecimalType to be a Python int.
items["ThermostatCT101_HeatOverrideMinutes"] * new BigDecimal(MINUTES)
Notice how BigDecimal inherits from Number. That’s why I know that if I create a BigDecimal it will be compatible with the DecimalType that is the state of the Item since DecimalType also inherits from Number.
Thanks Rich … embarrassed to admit that my software transitions over the last 40 (wait, 50) years was:
Basic->Z80/8086 assembly->Fortran->C->more assembly->Perl->Python with a little JaveScript and various other languages I was forced to hack in … I guess it’s time to graduate into the 21st century.