Am on OH 5.3.0.M3 and installed the Gemini binding (model Gemini 3.1 Flash Lite which is the default) incl. the required API key. The chat is basically working fine.
But the chat string item “last response” is not updated (NULL). Need this to operate a rule based on this string item for a voice output of Gemini’s response. Can anybody point me into the right direction?
According to the docs there is no “last response” Channel. The response comes as the return value from the Rule Action. So if you have an Item where you want to store the last response, you need a update that Item yourself in the rule that calls one of the sendMessage Actions.
But I wonder if the docs need to be updated (I’m on the latest milestone) as the list of Channels doesn’t match what I’m seeing on the actual Thing. But what I do see there matches what the ChatGPT binding does with the single “Chat” Item.
You sendCommand the prompt and the binding will update the same Item with the result. The Item is not updated with the response when you call the sendMessage Action. If you use the action, you need to update that Item yourself.
Thanks for your input. I see a single channel “chat” and created a “response item” (string item) linked to this channel assuming that something should happen. My feeling was already that i misunderstood something.
Here is how I use an Item linked to that Channel in a rule.
// Clear and seed the OpenAI prompt proxy channel
console.debug('Sending prompt to LLM: ' + prompt);
items.OpenAI.postUpdate('');
items.OpenAI.sendCommand(prompt);
// Wait for LLM to respond to generate the message
timer.loop(() => {
console.debug('Waiting for LLM response...');
// sleep for a second if not yet ready TODO: add timeout
if(items.OpenAI.state == prompt || items.OpenAI.state == '') {
console.debug('No response yet');
return 'PT1S';
}
Note timer is a LoopingTimer from openHAB Rules Tools.
Though I wrote that when I wasn’t aware that there was a sendMessage Action or maybe there wasn’t one back then.
A more proper implementation would be something like:
const geminiActions = actions.get("gemini", "gemini:account:geminiAPI");
const response = geminiActions.sendMessage(prompt); // will block until there is a reply
// If you want to keep the response in an Item
items.GeminiLastResponse.postUpdate(response);