Genie Community Forum

Trigger a HA script / automation?

Is there any way to trigger a HA automation? Right now, I am used to saying ‘Alexa, goodnight’, which is a trigger word for Alexa to start a routine that starts a HA script that puts my house in night mode (lights off, heat off, alarm on, check doors, etc).
I’d like to do the same using Genie.
Basically two parts:

  1. Have Genie start a HA script / automation that puts my house in night mode
  2. As part of the script / automation I’d like to get Genie to say something. Right now Alexa says: ‘All doors are closed’ or ‘the front door is open’ as part of the script, depending on if all doors are closed or not.

How can I make both of these work?

I am guessing I am just too far ahead of the curve, but it would be awesome to be able to trigger an automation/script and/or get Genie to say things.

In comparison, Rhasspy provides a way to make all clients “speak”, same for Google and Alexa. Genie client could just expose an API that the server can call. HA can then call the server to make all clients “speak”.

Google / Alexa can trigger an automation / script either natively or with a trick. I think we can do the same for Genie preferably natively or by “turning on” a boolean value in HA. I’ll try to implement that, but it would be great if Genie can natively start an automation/script in HA.

just tried with an input_boolean but was not able to get Genie to “turn that on”. Any ideas?

Genie does not currently support input_boolean entities, partly because they are a recent addition to Home Assistant (IIRC) and partly because they don’t map to well-defined devices so it’s hard to have good NLP for them.

As for “speaking”, you can trigger Genie to speak by causing Genie to run a specific ThingTalk program that sends out the alert, using the Genie web APIs.

Input_booleans are one of the oldest things in HA. Does not matter, I’d prefer to be able to just trigger an automation / script. Like ‘Genie, start bedtime’ for example. Or even better, just a Magic keyword that we can then map to the action of starting an automation. For example: ‘Genie, goodnight’. (that’s what I currently have with Alexa).

Any links to how to let the client speak? What if you have multiple clients linked to the same server? The way this works with Alexa is you just call one service with the message and you can optionally specify clients that need to say the message. If you don’t specify anything all connected clients will say the message.
I’d love to get something like that working, although it’s not useful for me unless we can trigger automations / scripts. I think adding that capability would make Genie to a potential replacement for other smart assistants in a HA driven household like mine.

To let the client speak the easiest way is to call the /converse API (reference), specifying the conversation ID of the client, and a payload like so:

{
  "type":"tt",
  "code":"@org.thingpedia.builtin.thingengine.builtin.say(message=\"hello world\");"
}

Off the top of my head, I don’t think there is a way to trigger a command on all connected clients. Timers go to all clients, so maybe a 1 second timer (ontimer(date=[$now + 1s]) => @org.thingpedia.builtin.thingengine.builtin.say...) could do. It’s a bit of a hack.
It would be great if anyone interested contributed this as a new clean addition to the Genie API.

thanks, I’ll give this a try and would love to help make this a reality - just how exactly can I contribute to the Genie API?
Also, any news on how we might trigger automations / scripts in HA? Can we expose those entities to Genie and enable something like: ‘Genie, start X’?

Hi, to help and contribute, the best places to start from are the wiki and github:

About triggering the automations I can suggest to create the automation and then by following this: https://www.home-assistant.io/integrations/switch.command_line, use this “virtual device” changes.

In this way the switch changes (or bulb, or whatever else that maybe you don’t have already as real device) will be mapped and recognized from Genie, and turning it on and off will trigger automation on and off too.

Last but not least you could also think to improve the home assistant support of genie adding interaction with services, or blueprint or automations directly

1 Like

thanks that’s exactly what I did :slight_smile: I ran into a couple of issues though: cannot access http://127.0.0.1:3000 · Issue #310 · stanford-oval/genie-server · GitHub and Install on wsl (Windows Subsystem for Linux) · Issue #309 · stanford-oval/genie-server · GitHub.

thanks - regarding your last comment about improving the ha support of genie by adding those interactions, how would you go about that? I guess the genie add-on would have to expose services such as ‘say’ or ‘announce’ to HA. I don’t think it does that today. Also, reversely, I guess HA will just expose automations to Genie, so how come they don’t show up - does Genie filter them somewhere?

I know the workaround with the switch to trigger an automation, although I have not tried it. I prefer to have scripts/automations exposed natively as they should be.

Well, starting from the bottom, let’s consider that Genie is not just an HA extension, but is an ecosystem by itself, and you could create automation in it (at the moment more complex going with the thingtalk language, less by text/voice), so the missing support of the HA one is also because we are trying to address more different features as possible, than have duplicates.

Consider also that integration with other ecosystems (like HA) could have missing parts/functions because: 1) is not our core priority, 2) genie is an open source project and so it would like to rely also on the community support, 3) the core team is a small group inside stanford lab, so is difficult to “add” and “extend” features at the same time;

Said so, going with my suggestion is not exactly a workaround because in a way or another, starting an automation is an on/off event, then we can talk about that the automations are available and exposed by HA, but if HA gave different possibility to achieve same result why don’t use it? :grinning_face_with_smiling_eyes:

Then back on the begin of your post, is not Genie that expose something, but HA that expose endopoints as websockets where Genie attach with a specific skill

https://github.com/stanford-oval/thingpedia-common-devices/tree/master/main/io.home-assistant

So it will be just a matter of extending the actual base skill to interact with that service and then ad a specific skill to manage that kind of commands/functions.

Then the only problem I can see there is on creating the right dataset for the nlp training in a way that it couldn’t be misunderstood with other commands because it would be something like “start this automation” or “turn this automation on” (where “automation” could help) otherwise “say” as you wrote, is already referred to a capability (mentioned by Giovanni)

https://github.com/stanford-oval/genie-toolkit/blob/master/data/builtins/org.thingpedia.builtin.thingengine.builtin/manifest.tt.in

“announce” is better because not in the “say” dataset, and could be a specific skill as for example the “drop in” by alexa,

hey, I am finally trying to make this work and have made a PR to add automation support to the basic HA skill (I don’t assume for a second this will all be fine, but we can continue the conversation on the PR:)). In parallel I started on adding the specific automation skill, but I am having trouble when it comes to this step: Synthesize and Train with Genie | Genie Wiki. I have installed genie-sdk and virtualenv of course, but I am not sure what to do to synthesize and train. source ../.virtualenv/genie/bin/activate does not work - what am I missing?