[SOLVED] Map item state from value delivered by Heatpump

Hello Guys,

i need help on the following:

From my heatpump, i get a json with all the values. There is one value, that delivers the state of different “items”, if they are on or not. Item B0 - B14. According to the manual of the heatpump, this is information is 16bit binary decoded.

83 as value for example, would be converted to binary 00000000 01010011.
That gives the information that the following items are on: B0, B1, B4, B6

My aim is of course, to have for every single item the information of the state, so that i can use them for persistence services.

I guess, i need to that with a rule, convert the Value to binary and then map the information to the items.
That is where i need help. What is the smartest way to do that? I guess in Java there are functions for the conversion, i also saw something regarding bittesting, but im a bit los.

So i would really appreciate if you could help me with an example or point me in another direction if im wrong with the rule.

Thanks and best regards

This is what you will need to use. There is nothing built into the Rules DSL for processing binary and shockingly the Rules DSL even lacks an XOR operator. So you will want to use the also inadequate Java libraries to parse and shift the binary to extract the bitpacked information. If you search for examples of processing binary in Java tutorials you should be able to apply those to a Rule.

Thanks for your quick reply. I feared that, since im a noob in Java :frowning:
There is a Stiebel-Eltron Binding available, from Kai Kreutzer i think. This is based on the modbus connection, maybe there is already some code for that available, that can be used, need to ask there.

OK

Very dirty code but it should work:

Number heatpump_info {binding}
rule "heatpump decoding"
when heatpump_info changed
then
    var Number heatpump = heatpump_info.state as Number
    if (Number > 16384) {
        heatpump = heatpump - 16384
        item_B14.postUpdate(ON)
    else item_B14.postUpdate(OFF)
    if (Number > 8192) {
        heatpump = heatpump - 8192
        item_B13.postUpdate(ON)
    else item_B13.postUpdate(OFF)
    if (Number > 4096) {
        heatpump = heatpump - 4096
        item_B12.postUpdate(ON)
    else item_B12.postUpdate(OFF)
    if (Number > 2048) {
        heatpump = heatpump - 2048
        item_B11.postUpdate(ON)
    else item_B11.postUpdate(OFF)
    if (Number > 1024) {
        heatpump = heatpump - 1024
        item_B10.postUpdate(ON)
    else item_B10.postUpdate(OFF)
    if (Number > 512) {
        heatpump = heatpump - 512
        item_B9.postUpdate(ON)
    else item_B9.postUpdate(OFF)
    if (Number > 256) {
        heatpump = heatpump - 256
        item_B8.postUpdate(ON)
    else item_B8.postUpdate(OFF)
    if (Number > 128) {
        heatpump = heatpump - 128
        item_B7 postUpdate(ON)
    else item_B7.postUpdate(OFF)
    if (Number > 64) {
        heatpump = heatpump - 64
        item_B6.postUpdate(ON)
    else item_B6.postUpdate(OFF)
    if (Number > 32) {
        heatpump = heatpump - 32
        item_B5.postUpdate(ON)
    else item_B5.postUpdate(OFF)
    if (Number > 16) {
        heatpump = heatpump - 16
        item_B4.postUpdate(ON)
    else item_B4.postUpdate(OFF)
    if (Number > 8) {
        heatpump = heatpump - 8
        item_B3.postUpdate(ON)
    else item_B3.postUpdate(OFF)
    if (Number > 4) {
        heatpump = heatpump - 4
        item_B2.postUpdate(ON)
    else item_B2.postUpdate(OFF)
    if (Number > 2) {
        heatpump = heatpump - 2
        item_B1.postUpdate(ON)
    else item_B1.postUpdate(OFF)
    if (Number = 1) item_B0.postUpdate(ON)
    else item_B0.postUpdate(OFF)
end
1 Like

Bro, thank you so much. With just some small corrections, it works like a charm. Just for the case someone has the same question in the future, here the working code

var Number heatpump = Status.state as Number

    if (heatpump > 16384) {
        heatpump = heatpump - 16384
        item_B14.postUpdate(ON) }
    else item_B14.postUpdate(OFF)
    if (heatpump > 8192) {
        heatpump = heatpump - 8192
        item_B13.postUpdate(ON) }
    else item_B13.postUpdate(OFF)
    if (heatpump > 4096) {
        heatpump = heatpump - 4096
        item_B12.postUpdate(ON) }
    else item_B12.postUpdate(OFF)
    if (heatpump > 2048) {
        heatpump = heatpump - 2048
        item_B11.postUpdate(ON) }
    else item_B11.postUpdate(OFF)
    if (heatpump > 1024) {
        heatpump = heatpump - 1024
        item_B10.postUpdate(ON) }
    else item_B10.postUpdate(OFF)
    if (heatpump > 512) {
        heatpump = heatpump - 512
        item_B9.postUpdate(ON) }
    else item_B9.postUpdate(OFF)
    if (heatpump > 256) {
        heatpump = heatpump - 256
        item_B8.postUpdate(ON) }
    else item_B8.postUpdate(OFF)
    if (heatpump > 128) {
        heatpump = heatpump - 128
        item_B7.postUpdate(ON) }
    else item_B7.postUpdate(OFF)
    if (heatpump > 64) {
        heatpump = heatpump - 64
        item_B6.postUpdate(ON) }
    else item_B6.postUpdate(OFF)
    if (heatpump > 32) {
        heatpump = heatpump - 32
        item_B5.postUpdate(ON) }
    else item_B5.postUpdate(OFF)
    if (heatpump > 16) {
        heatpump = heatpump - 16
        item_B4.postUpdate(ON) }
    else item_B4.postUpdate(OFF)
    if (heatpump > 8) {
        heatpump = heatpump - 8
        item_B3.postUpdate(ON) }
    else item_B3.postUpdate(OFF)
    if (heatpump > 4) {
        heatpump = heatpump - 4
        item_B2.postUpdate(ON) }
    else item_B2.postUpdate(OFF)
    if (heatpump > 2) {
        heatpump = heatpump - 2
        item_B1.postUpdate(ON) }
    else item_B1.postUpdate(OFF)
    if (heatpump == 1) item_B0.postUpdate(ON)
    else item_B0.postUpdate(OFF)

Just thinking about it…
Stupid mistake… Change your > for >= !!

1 Like

it worked without as well, but thanks for that hint, i updated my coding.

It wouldn’t have worked for a value of 2 for example or other powers of 2