«
Rule languages supports extensions to PercentType
java_import org.openhab.core.library.types.PercentType
logger.info("PercentType inspected: #{PercentType.new(10).inspect}")
java_import org.openhab.core.library.types.PercentType
state = PercentType.new(<state>)
logger.info("PercentType is up: #{state.up?}")
logger.info("PercentType is down: #{state.down?}")
logger.info("PercentType is on: #{state.on?}")
logger.info("PercentType is off: #{state.off?}")
state | up | down | on | off | |
---|---|---|---|---|---|
0 | true | false | false | true | |
50 | false | false | true | false | |
100 | false | true | true | false |
java_import org.openhab.core.library.types.PercentType
state = PercentType.new(<state>)
logger.info("Value scaled is: #{state.scale(<range>)}.")
state | range | result | |
---|---|---|---|
0 | 0..255 | 0 | |
100 | 0..255 | 255 | |
100 | 0...256 | 255 | |
0 | 25..75 | 25 | |
50 | 25..75 | 50 | |
100 | 25..75 | 75 | |
50 | -50..10.0 | -20.0 | |
100 | -50..10.0 | 10.0 |
java_import org.openhab.core.library.types.PercentType
state = PercentType.new(50)
logger.info("Value as byte is #{state.to_byte}")