I’m starting to wonder why I’m trying to write my own smart apps. Seems like every time I do something different it goes south. Anyway, here is my current issue.
I am looking at a temperature sensor and subscribing to the temperature. In the handler I compare to numbers to either turn on or turn off a heat light. I get an error of java.lang.ClassCastException. Here is my handler code.
evt.value is passed as a String, and if you didn’t specify onTemperature to be type: number or type: decimal, it will be a String also. If both are strings a “<” operator won’t work. And if you DO use those, I think you get a BigDecimal - and comparing a String to a BigDecimal is a no-no.
You could use evt.doubleValue to ensure you’re using a number, but you need to verify it has a value or you’ll get a different error (some temperature devices can return a null response, or “unavailable” or “err” for temperature values, so doing some checking might be necessary).
I’ve probably read that a number of times and it just didn’t click. Read it again and it made perfect sense. Sometimes I think I’m getting too old to learn new programming, going on 70, but I enjoy doing it. I’ve done programming most of my life but every language is different. And for the past 20 years about all I did was PLC programming which is totally different. Still I’m having fun doing it as a hobby now.