Overriding item commands with a mapping

Tags: #<Tag:0x00007f616ee407b0> #<Tag:0x00007f616ee40698>

Hey guys!

I’m currently trying to connect Google Assistant through IFTTT with OpenHab2.

I want to be able to control switches (such as lights, AV power etc) with voice commands through Google Assistant.
When creating a IFTTT rule, I’m able to map a “turn lights $” so that it sends command $ (what ever $ is) to an OpenHab2 item.

Problem is – Google Assistant spells values ON and OFF in lowercase so my OpenHab2 Switch receives “on” and “off” instead of “ON” and “OFF”. I’ve tried adding a mapping in Switch’s definition, but that doesn’t seem to transform incoming commands.

This is how I tried to do it:

Switch YamahaPower "Yamaha Power [MAP(switch_lowercase.map):%s" <switch> { channel="..." }

I’ve tried reversing mapping in the .map file with no luck.
I either get:
Received invalid command 'off' for item 'YamahaPower'
or
Could not transform 'ON' with the file 'switch_lowercase.map' : Target value not found in map for 'ON'

Is there a simpler way to handle this than to create a bunch of proxy switches for each switch I want to be able to control via Google Assistant?

The point is, MAP in this case does only work for the label, not the state itself.

That’s what I concluded as well.

What would you propose I do?

Well… I do not use IFTTT nor Google Assistant.

The “normal” way would be, to setup Things and Items to control everything with openHAB2, then implement IFTTT to control openHAB2. If some commands are written incorrect from IFTTT-side, I would guess this is a bug.
ON and OFF should always be sent and received in upper case, same for INCREASE/DECREASE, OPEN/CLOSED and UP/DOWN/STOP, as these are valid states.

Google Assistant & IFTTT is a rather simple setup:

  • you specify a query to trigger on, e.g. “turn lights $” where $ is a wildcard
  • you specify which item should get a command sent to, e.g. “CUSTOM_COMMAND_{{TextField}}” where {{TextField}} is what “$” wildcard captured

I can model things like “set AV input to $” or “dim $ to #”, but all of those would need some kind of re-mapping since Google Assistant “hears” in lowercase :slight_smile:

Creating a proxy seems really tedious, but I don’t have any other ideas at this point.
Maybe creating a catch-all proxy of format ITEM_NAME$value that will than split on $ within a rule, and then sendCommand(ITEM_NAME, transform("MAP", ..., value))
This would also beat the purpose of having items…