Switch Channel States and BigDecimal -> long failure

Hi Community, i have to questions, at first:

How can i differentiate between the two states of a switch in my handle command? So i want to have something be done, when the switch turns “on” and something else when the switch turns “off”. Actually i just understand how to differentiate between the channels itself, but not the states.

The second Question is about a problem with getting a number from the configuration into the handling.


long pollingTime = (long) getThing().getConfiguration().getuvr2BindingConstants.CONFIG_PARAMETER_POLLING_TIME);

At this point i get the following exception:

java.math.BigDecimal cannot be cast to java.lang.long

The parameter type in the thingtypes.xml is “integer”.

Thanks for all the help :slight_smile:

Ok i solved the second question by myself.
Instead of using:

long pollingTime = (long) getThing().getConfiguration().get(uvr2BindingConstants.CONFIG_PARAMETER_POLLING_TIME); 

I use now:

Integer pollingTime = ((Number) this.getConfig().get(uvr2BindingConstants.CONFIG_PARAMETER_POLLING_TIME).intValue();

That worked out for me! :blush:

But the first question is still unsolved for me :wink:

Not sure if I correctly got your question, but I will try:
Within the handleCommand() method you can simply do:

if(command.equals(OnOffType.ON)) {
   // do something
} else if(command.equals(OnOffType.OFF)) {
   // do something else

Does this help?

Thank you Kai, that was too easy for me :wink: I tried it this way before, but it don’t worked out. Now i copied your code and it works. I don’t know why, but thanks :blush: