Bi-directional transformation of dimmer type to decimal - possible?


right now i am programming a visu for my central ventilation system in our home.
i use homekit right now because habpanel is too much effort right now and i am pretty happy with it.

i used the “fan” item which is closest to what i am handling. now my “issue”:

the fan item has a dimmer (0 - 100 %) and my ventilation system accepts only 0 1 2 3 as a valid input.

i created a rule:

rule "Homekit Prozent zu Lüftungsstufen"
                Item Haus_Lueftung_Prozent changed 
                switch (Haus_Lueftung_Prozent.state as Number)
                        case Haus_Lueftung_Prozent.state == 0 :{Haus_Lueftung_Stufe.sendCommand(0)}
                        case Haus_Lueftung_Prozent.state <=33 :{Haus_Lueftung_Stufe.sendCommand(1)}
                        case Haus_Lueftung_Prozent.state <=66 :{Haus_Lueftung_Stufe.sendCommand(2)}
                        case Haus_Lueftung_Prozent.state >66 : {Haus_Lueftung_Stufe.sendCommand(3)}

It works great - in one direction.
I have also programmed an automated ventilation (reading CO2 values, humidity and temperatures etc.) that is active when i selected the “auto” option.

It would be great if the dimmer could show the current state when in “auto” mode.

→ 0 % when it’s off, 33 % for 1, 66 % for 2, 100 % for 3.

Do you have any idea how i could achieve this?

I thought about another rule similar to this one but i am pretty sure it would result in an infinite loop …

May we know where this ‘current state’ appears, and what form it takes?

Have you seen the SCALE transformation intended for e.g. converting range 0-100 to 1-25 etc. Probably not needed for just 4 steps though.

It would be usual for your rule to respond to commands, rather than state changes, if it is intended for “do something” instructions.
Careful management of command vs state is usually the way to avoid loops.

1 Like

Thanks a lot rossko!
i totally forgot about “command” as i am not controlling a lot only from OH directly.
I will give it a try!

so for the first rule (the one i postet) it would be “received command” and for the second (to display the current value) it would be triggering when the state changes (externally), right?

to answer your question:
the external state is handled by a knx logic-module.
It would of course also be possible to do this in OH but i thought it would be more “robust” when handling that in my knx installation directly …

EDIT: It’s not that easy :wink:
The second rule triggers immediately (of course) when scrolling. I’ll try to dig deeper into this.

I meant more, what Item is reflecting what state.

I’ve no idea of your data flow or what comes in from Homekit. You can only utilize commands if commands there be.

Don’t forget autoupdate can be disabled on any Item to uncouple commands from state.

1 Like


Haus_Lueftung_Prozent is just the slider on the with no physical thing.
Haus_Lueftung_Stufe is the item that will be sent to the knx bus (0 1 2 3) to control the vent.

I just tried the transformation service but i cannot wrap my head around it.
i can see how it works in the example when you receive a value and then it will be converted. but when i manually change the percentage with the slider it just takes the percentage value and it is not transformed.

I’ll read further into “autoupdate”.
thanks a lot!

Like all transformation services, SCALE is a separately installable add-on. It’s likely of little benefit here, except if you want to use it where a channel allows a transform.

1 Like

ok. thanks. i definitely have to read more into transformation.

i got it working now by disabling autoupdate on the item that represents the functional state (0 1 2 3).
When i change it via knx it fires the rule.

here my rule (in case anyone cares :wink: )

rule "Homekit Prozent zu Lüftungsstufen"
                Item Haus_Lueftung_Prozent received command 
                switch (Haus_Lueftung_Prozent.state as Number)
                        case Haus_Lueftung_Prozent.state == 0 : {Haus_Lueftung_Stufe.sendCommand(0)}
                        case Haus_Lueftung_Prozent.state <=33 : {Haus_Lueftung_Stufe.sendCommand(1)}
                        case Haus_Lueftung_Prozent.state <=66 : {Haus_Lueftung_Stufe.sendCommand(2)}
                        case Haus_Lueftung_Prozent.state >66  : {Haus_Lueftung_Stufe.sendCommand(3)}

rule "Lüftungsstufen zu Homekit Prozent (Sliderfeedback)"
                Item Haus_Lueftung_Stufe changed 
                switch (Haus_Lueftung_Stufe.state as Number)
                        case Haus_Lueftung_Stufe.state == 0.0 : {Haus_Lueftung_Prozent.sendCommand(0)
                        case Haus_Lueftung_Stufe.state == 1.0 : {Haus_Lueftung_Prozent.sendCommand(33) 
                        case Haus_Lueftung_Stufe.state == 2.0 : {Haus_Lueftung_Prozent.sendCommand(66)
                        case Haus_Lueftung_Stufe.state == 3.0  : {Haus_Lueftung_Prozent.sendCommand(100)


and the items:

Group     Haus_Lueftung                                                                                     {homekit="Fan"}
Number    Haus_Lueftung_Prozent               "Lüftungsstufe in Prozent"        <fan>    (Haus_Lueftung)    {homekit="Fan.RotationSpeed"}
Switch    Haus_Lueftung_Betriebsstatus        "Lüftung Betriebsstatus"          <fan>    (Haus_Lueftung)    {homekit="Fan.ActiveStatus", channel="knx:device:bridge:knx_device:Haus_Lueftung_Betriebsstatus"}
Switch    Haus_Lueftung_Automatik_Schalter    "Lüftung Automatik (Schalter)"    <fan>    (Haus_Lueftung)    {channel="knx:device:bridge:knx_device:Haus_Lueftung_Automatik"}
Number    Haus_Lueftung_Automatik             "Lüftung Automatik (Nummer)"      <fan>    (Haus_Lueftung)    {homekit="Fan.TargetFanState"}

Number    Haus_Lueftung_Stufe                 "Lüftungsstufe"                   <fan>                       {influxdb="Stufe Lüftungsanlage" [floor="KG", type="Betriebsart"], channel="knx:device:bridge:knx_device:Haus_Lueftung_Stufe", autoupdate="false"}

thanks a lot!