[Solved] Exposing String Items to Alexa

Dear community,

I would like to use a switch item to toggle an ESP8266 module to send commands via its serial port. Therefore, I flashed an ESP8266 with a little firmware that converts incoming MQTT messages to serial output.

In openHAB I defined the following item:

String Mathilde "Mathilde" ["Lighting"] { mqtt=">openHABian_MQTT:/MathildeIn:command:*:default]"}

The sitemap looks like this:

Switch item=Mathilde mappings=["Clean"=ON, "Clean Stop"=OFF] icon="switch"

The commands are executed on the ESP8266 just fine, when the switch is toggled via app or webinterface.

However, it is not possible to have Alexa execute the commands. When telling Alexa to turn on or off the switch, she acknoledges the command with “OK”. However, nothing happens.

I assume, it has something to do with the fact, that the switch is defined as a string. However, I don’t know how to work around this issue. Any help is highly appreciated.

EDIT: Modified the item and sitemap extracts from general to specific implementation, to match with the logs in the follow up posts.

That’s interesting. Are you using the official Alexa skill or working thru the Hue emulation binding ?

If you configured the ESP thru an .items file, what does that item description say ?

Have you looked closely at the log files to see if there’s any relevant information? Have you turned the logging level to DEBUG or TRACE?

Why don’t you use a Switch Item instead of a String item?

Thanks for the replies.

I am using the official Alexa skill. The ESP is configured through the .items string entry as described in the original post.

The use of a string item is due to the fact, that I need to send a string via MQTT to the ESP.

This is the log, when triggered via Alexa (Mathilde = ESP, “Clean” = “OnString” compared to the general problem description in the original post. I am trying to run a Neato robot from openHAB):

13:35:09.247 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Mathilde' received command ON
13:35:09.284 [INFO ] [marthome.event.ItemStateChangedEvent] - Mathilde changed from OFF to ON

And this, when triggered via app:

13:35:49.789 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Mathilde' received command Clean
13:35:49.826 [INFO ] [marthome.event.ItemStateChangedEvent] - Mathilde changed from ON to Clean

Apparently, the mapping in the sitemap (“Clean”=ON) is only excuted when beeing called from the app (which somewhat makes sense, because the definition is in the sitemap).

So the question is, whether it is possible to do the mapping in the string item definition? Otherwise I might have to work with a rule.

the following setup works with hue emulation, a hardware hue hub and Alexa, so im not sure if itll be helpful in your case…

im now using openhab 2.2.0 snapshot 1060, but the solution below is working since first stable 2.1.0:

// Item def
Switch Verstaerker_Wohnzimmer "Verstärker" <light> (Wohnzimmer) [ "Switchable" ] {mqtt=">[mqttBroker:SteckdoseA:command:ON:AN],>[mqttBroker:SteckdoseA:command:OFF:AUS]"}
// sitemap
Switch item=Verstaerker_Wohnzimmer icon="soundvolume" label="Verstärker"

my little mqtt-client-firmware implemented on a particle photon is receiving the value of the command ON/OFF (value: AN/AUS) as a byte*, so there is a little work to do to get a string.

by the way: i always used a mapping definition vice versa:

Switch item=Wohnzimmer_Beleuchtung mappings=[OFF="Alle aus", ON="Alle an"]
1 Like

Excellent, that item definition did the trick.

Switch Mathilde "Mathilde" ["Lighting"] { mqtt=">[openHABian_MQTT:/MathildeIn:command:ON:Clean], >[openHABian_MQTT:/MathildeIn:command:ON:Clean], >[openHABian_MQTT:/MathildeIn:command:OFF:Clean Stop]"}

No string to byte conversion was necessary, the string is correctly interpreted in the ESP8266.

Another positive side effect: The Neato sometimes needs to receive the clean command twice (when it is in deep sleep). The double definition of the MQTT on command accounts for that.