openhab / openhab-google-assistant

openHAB Google Assistant: Actions on Google for openHAB
Eclipse Public License 2.0
176 stars 86 forks source link

OpenHAB items can't be used a starters in routines #509

Open alackmann opened 10 months ago

alackmann commented 10 months ago

Having gotten OpenHAB and Google Assistant / Home integrated, I'm trying to have Switches or Lights triggered within OpenHAB become triggers for Google Home Routines.

It appears you should be able to do this. Google Home app (Android) now has the ability to create routines with Starters labelled "When a device does something" and shows Displays / Lights / Speakers / TVs (at least in my GH).

Unfortunately, even with bi-directional updating working for a Light or Switch OH Item within Google Home these Items never appear as options in Routines / Starters. If they could, this would significantly improve the functionality of the binding by providing a way to trigger events within the Google Home ecosystem from OpenHAB.

Also mentioned in https://community.openhab.org/t/issue-commands-to-ga/141423

michikrug commented 10 months ago

Hi, as already mentioned in the linked openHAB Community thread, I am convinced that the unavailability of the openHAB devices for starters is connected to the current limitation that we are not able to actively push the devices' states to the Google Home Graph, which is required to trigger such routines.

The way the current integration is working does only use a "pull" way of getting information. So only if you actively request a device's state, it is requested by the integration from your personal OH instance.

What would be required to do is a complete new solution that runs inside a user's OH instance and actively pushes state changes of items into the personal Google Home Graph of the user. I do not see this happening in the scope of this project.

I did some experiments with dirty hacks that kinda work in that direction using rules and custom scripts, which actually made devices appear as starters as desired but also was not yet able to have devices appearing as starters for routines.


For some insights of what I did in my experiments...

Calling a custom Python script on state changes like:

rule "Report State Temperatur Bad"
when
        Item MiTempB_Temperature changed
then
        executeCommandLine(Duration.ofSeconds(4), "python3", "/etc/openhab/scripts/statereporter.py", "-i", "MiTempB")
end

The script then does a call to the local OH REST API to get the full item state and sends it to an endpoint of a modified version of this integration that has support for updating the Google Home graph. Once a request is received, the regular logic is called to convert to item information into the Google Home required device data and pushed into the Home Graph.

The Python script can be accessed at: https://github.com/michikrug/openhab-google-assistant/blob/itemname-rework/stateReporter.py

The modifications made to talk to the Home Graph can be seen in (probably not including all changes): https://github.com/michikrug/openhab-google-assistant/blob/itemname-rework/testServer.js#L11 and https://github.com/michikrug/openhab-google-assistant/blob/itemname-rework/functions/index.js#L29-L42 and https://github.com/michikrug/openhab-google-assistant/blob/itemname-rework/functions/openhab.js#L216-L263

michikrug commented 10 months ago

I actually set up a test routine just now and it indeed did work with my dirty hacks :D

alackmann commented 9 months ago

What would be required to do is a complete new solution that runs inside a user's OH instance and actively pushes state changes of items into the personal Google Home Graph of the user. I do not see this happening in the scope of this project

That's great to hear you've been able to make it work. With that investigation - what's the feasibility of adding it into the Binding? I think this would add significant functionality to the integration.

michikrug commented 8 months ago

What would be required to do is a complete new solution that runs inside a user's OH instance and actively pushes state changes of items into the personal Google Home Graph of the user. I do not see this happening in the scope of this project

That's great to hear you've been able to make it work. With that investigation - what's the feasibility of adding it into the Binding? I think this would add significant functionality to the integration.

Into what binding? Currently, there is none taking care of such interaction. We currently only rely on the exposure of OH through myOpenHAB to send and retrieve item information. No binding is involved.

I myself do not feel able to create one.