Map a string (channel) to a switch (item)

Hello,

i got a channel, that has “on” and “off” as string output.
But i would like to link a switch item to this channel.
Therefore i linked the switch item to the channel and created a .map file (and linked it to the item):

on=ON
off=OFF

The problem is, that when i toggle the switch, the channel doesnt get an update.

What is the best practice to solve this?

Thanks,
Alex

You might look in your logs to see what is happening.
openhab.log might contain relevant error messages.
events.log might show what is happening to your Item.

MAP transformation is an optional, installable add-on.
You’ll have to install it before it works.

How did you do that exactly, may we see?
Possibilities include as a parameter to the channel, which belongs to some mystery binding.
Or as a transformation profile.
Or as state presentation modifier in the ‘pattern’ metadata

Can you clarify, this is some physical action external to openHAB, or you are using UH GUI, or?

You might look in your logs to see what is happening.
openhab.log might contain relevant error messages.
events.log might show what is happening to your Item.

I had a look on the events at console with log:tail, also i tested the commands with the rest-api.
The channels seems to need off and on (tested with sting item at rest api), and the switch item needs ON an OFF.

MAP transformation is an optional, installable add-on.
You’ll have to install it before it works.

Yes, it is installed.

How did you do that exactly, may we see?
Possibilities include as a parameter to the channel, which belongs to some mystery binding.
Or as a transformation profile.
Or as state presentation modifier in the ‘pattern’ metadata

I created a file named miele.map at transformations folder with the following content:

on=ON
off=OFF
ON=on
OFF=off

This is the configuration of the switch item:

This is the configuration of the channel link:

Can you clarify, this is some physical action external to openHAB, or you are using UH GUI, or?
I tried it with the mainUI and rest-api.

Okay, that all seems to be working. When your string Item is ‘off’ your Switch type Item is OFF.

Are you trying to command your device from openHAB? (The profile and MAP will not be used in that “outbound” case)

I don’t know why the miele binding author chose to present an on-off function as a string type channel, but you’ve got you got.
I’d make a ‘dummy’ Switch type Item, for use in your user-facing UI.
And connect that with a ‘real’ String type Item linked to the binding by using two rules. One rule triggers from state updates to the real Item and postUpdates to the dummy. The other rule triggers from commands to dummy Item and resends as commands to the real Item. Both rules can take care of on/ON conversion.

Thank you for your help!

I hoped, it would be better to use the map transformation instead of a rule - but i followed your advise and created a rule for it:

The rule is working file, i just get the following message to the log - could you have a look at it?

Script execution of rule with UID 'miele-2' failed: An error occurred during the script execution: index=1, size=1 in miele
// Dummy item to Channel item
rule "Control Miele CM6 Power"
when
    Item MieleKaffeevollautomatCM6560_Power_SW changed
then
    if (MieleKaffeevollautomatCM6560_Power_SW.state == ON) {
        Miele_CM6560_Power.sendCommand('on')
    }
    if (MieleKaffeevollautomatCM6560_Power_SW.state == OFF) {
        Miele_CM6560_Power.sendCommand('off')
    }
end

// Channel item to Dummy item

rule "Update Miele CM6 Power Dummy item"
when
    Item Miele_CM6560_Power changed
then
    if (Miele_CM6560_Power.state == "on") {
        MieleKaffeevollautomatCM6560_Power_SW sendCommand(ON)
    }
    if (Miele_CM6560_Power.state == "off") {
        MieleKaffeevollautomatCM6560_Power_SW .sendCommand(OFF)
    }
end

Bad syntax, missing “.

I’d work the rules a little differently, paying attention to the difference between commands and states.

// passing command from dummy to device
rule "Control Miele CM6 Power"
when
    Item MieleKaffeevollautomatCM6560_Power_SW received command
         // don't trigger from state if interested in commands
then
    if (receivedCommand == ON) {
         // don't look at state if interested in commands
        Miele_CM6560_Power.sendCommand('on')
    }
    else if (receivedCommand == OFF) {
        Miele_CM6560_Power.sendCommand('off')
    }
end

// passing device state to dummy
rule "Update Miele CM6 Power Dummy item"
when
    Item Miele_CM6560_Power received update
then
    if (Miele_CM6560_Power.state == "on") {
        MieleKaffeevollautomatCM6560_Power_SW.postUpdate(ON)
          // if you want to update, then update - don't command
    }
    else if (Miele_CM6560_Power.state == "off") {
        MieleKaffeevollautomatCM6560_Power_SW.postUpdate(OFF)
    }
end
1 Like

Thank you for your help!