Create new item with custom mapping

Hello,

I’m trying to get my Garage door show up in Google Home (Google Assistant, to be able to control it via voice commands).
The garage door controller is locally managed via a Tuya addon, but since it is a string item (open,stop,close) I can not natively set it up with Google Assitant’s “garage” metadata.
Garage metadata only accepts on and off commands so I was wondering if I can create a switch item pointing to the same tuya controlled channel with special mappings as on=“OPEN”, off=“Close”

I was trying to do it in items-file but I get error. Then I’m trying to create an item via the ui and add the custom code as mapping but it does not accept that.

Is it even possible?

The reason for me trying to do this is even though I have the Tuya connection via Google Assistant, it always requires a PIN code and I can not add it to be able to use it without PIN code.

Any suggestions? :slight_smile:

You could but you’ll get errors for “stop” if you only map those two states. Also case matters so it needs to be “ON” and “OFF”. But all of that really is moot because the Map transformation can only work in the direction from the Channel to the Item, not for commands from the Item to the Channel.

Instead you’ll need to use a Script Transformation Profile which lets you set a separate transform for both directions. You can do something relatively simple like an inline transform.

Assuming the ECMAScript 11 transform the This to Item Transformation would be:

|return {"NULL": "NULL", "UNDEF": "UNDEF", "OPEN": "ON", "CLOSE": "OFF", "STOP": "OFF" }[input]

The Item Command to Thing Transformation would be:

|return {"ON": "OPEN", "OFF":"CLOSE}[input]

In both cases we create a map of all the potential values and what we want to transform them to and then select the mapping based on the input. From the Channel you can get NULL, UNDEF, OPEN, CLOSE and STOP as values so we provide a mapping for all of those. For commands a Switch can only send ON and OFF.