openhab / openhab-google-assistant

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

Add Rollershutter #59

Closed fab33 closed 5 years ago

fab33 commented 5 years ago

Hi, Please can you add Rollershutter tag to have : UP DOWN PERCENTAGE. Thank you

alibahba commented 5 years ago

Google Smart home is currently not supporting roller shutters, so we can't add them. Supported devices You can use the lightning tag as a hack.

marziman commented 5 years ago

Hi @alibahba & @fab33 ,

sorrym thats not fully correct. There is support for Shutters according a mail from Google to us.

"To support Blinds, you will need the Blinds device type and Open Close Trait. The Open/Close trait should be guarded by 2FA if used for security type devices (e.g. Doors, Windows, Garage Doors etc) but for blinds, this would be okay. "

But it will require adding 2FA and I am not sure when I can tackle that.

See here for the Blinds device type and here for the Open Close trait

alibahba commented 5 years ago

When I read this I understand that for blinds 2FA is not required. I will give it a try with Christmas.

pythen commented 5 years ago

Hello,

I have extended the script openhab.js with the action BLINDS.

The following functions are available:

The detection of a blind device is not that easy. A suitable tag is missing. My current detection solution is not clean.

Does somebody has any idea?

fmalfatto commented 5 years ago

Any new on this support? I had it working at very beginning defining it as switchable, but now it does not work. It expects UP/DOWN/Commands instead of ON/OFF:

[rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/Tenda_Studio' with an invalid status value 'OFF'.

Rollershutter Tenda_Studio "T. Fulvio [%d %%]" <blinds> (Tende) ["Switchable"] { channel="openwebnet:bus_automation:mhs1:Studio_F:shutter"}

mvalla commented 5 years ago

Hi @pythen

The detection of a blind device is not that easy. A suitable tag is missing.

According to the ESH Ontology & Semantic Tags proposal (see: https://community.openhab.org/t/habot-walkthrough-2-n-semantic-tagging-item-resolving/55651) the correct tag to look for is "Blinds" Can you provide a test version with your extended script?

pythen commented 5 years ago

Hi @mvalla

Thank you for the tip. ["Blinds"] is the correct tag

try this version: https://github.com/pythen/openhab-google-assistant/blob/master/functions/openhab.js

Please give me some feedback then can I create a pull request.

The commands are

Blind down / up Blind 80% down / 80% up Stop Blind

In German

[Jalousie/Rolladen] schließen / öffnen [Jalousie/Rolladen] 80% schließen / 80% öffnen Stopp [Jalousie/Rolladen]

fmalfatto commented 5 years ago

Help! What am I supposed to do with this file? I have no such file in my installation to substitute it. find / -name 'openhab.js' does not return me anything but errors in /proc (that is normal). I have edited my things with the new ["Blinds"] tag but Google home does not see enything after sync.

Rollershutter Tenda_Est "T. sogg. E [%d %%]" <blinds> (Tende) ["Blinds"] { channel="openwebnet:bus_automation:mhs1:Sogg_E:shutter"}

nicolaus-hee commented 5 years ago

@alibahba Google assistant now supports smart blinds

https://www.theverge.com/2019/3/13/18263963/google-assistant-smart-blinds-developers-native-support

mvalla commented 5 years ago

@pythen thanks for providing the changed file but I cannot test it myself as I do not have configured the endpoints backend (@fmalfatto : that is where you can test the modified file, you have to setup your own backend: see: https://github.com/openhab/openhab-google-assistant/blob/master/README.md).

@pythen if it works in your setup, why not just create a PR so that maybe @marziman can include it in the next release and deploy for everyone? Now that Google Assistant supports smart blinds, everybody would benefit from this enhancement.

pythen commented 5 years ago

@mvalla I think I can deploy it until tomorrow.

marziman commented 5 years ago

I will test and deploy afterwards. Give me chance to test it. Thx.

pythen commented 5 years ago

Yes of course

Pull Request: https://github.com/openhab/openhab-google-assistant/pull/77

mvalla commented 5 years ago

@pythen @marziman any planned date for the support for rollershutter to be deployed ? I am available for testing (with public myopenhab)

ozirissp commented 5 years ago

Any news, about the tests ? Can we expect a deployment soon ?

pythen commented 5 years ago

Sorry, I don't have permission to deploy something publicly.

pythen commented 5 years ago

@marziman, what's the plan?

mvalla commented 5 years ago

Any news to include the support for blinds?

@marziman if you are too busy, is there another maintainer for openHAB-google Assistant addon that could test and deploy the feature on your behalf? Also, If you have no time for testing and could upload it on a beta/test server (like was done in the first version of Assistant before official publication) I think many users would be available to help

marziman commented 5 years ago

This will be deployed this weekend with a new release. I was busy with other work stuff and I will notify here.

BR Mehmet

robin-thoni commented 5 years ago

Sorry to spam, but, what's the current status?

Lele81 commented 5 years ago

Hello, I deployed my own OpenHAB Cloud and connected to Google Assistant (following the tutorial on the readme), and all is working, except the shutters. Tag "Blinds" is applied, and shutters are shown on GoogleAssistant devices. So when I say (in italian)

"ok google, abbassa la tapparella dell'ufficio"

it answers correctly:

"Certo, chiudo il dispositivo ufficio"

but nothing happens, apart an horrible error on openhab.log (on the openhab2 installation):

2019-04-23 15:18:57.741 [WARN ] [org.apache.karaf.services.eventadmin] - EventAdmin: Exception during event dispatch [org.osgi.service.event.Event [topic=openhab/command/Shutter_C] {item=Sh utter_C, bridgemarker=true, command=0, timestamp=1556025537738} | {org.openhab.model.item.binding.BindingConfigReader, org.osgi.service.event.EventHandler}={service.id=363, service.bundleid =210, service.scope=bundle, event.topics=openhab/command/*, component.name=org.openhab.binding.serial, component.id=219} | Bundle(org.openhab.binding.serial_1.13.0 [210])] java.lang.NullPointerException: null at org.openhab.core.library.types.DecimalType.format(DecimalType.java:63) ~[?:?] at org.openhab.binding.serial.internal.SerialBinding.receiveCommand(SerialBinding.java:128) ~[?:?] at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:45) ~[?:?] at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415) [3:org.apache.karaf.services.eventadmin:4.2.1] at org.apache.felix.eventadmin.impl.tasks.HandlerTask.runWithoutBlacklistTiming(HandlerTask.java:82) [3:org.apache.karaf.services.eventadmin:4.2.1] at org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks.execute(SyncDeliverTasks.java:104) [3:org.apache.karaf.services.eventadmin:4.2.1] at org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks$TaskExecuter.run(AsyncDeliverTasks.java:166) [3:org.apache.karaf.services.eventadmin:4.2.1] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?] at java.lang.Thread.run(Thread.java:748) [?:?]

Shutter is connected (and working well) via a serial homemade interface, that expects a command like "POSCx" - where x is position from 0 to 100, or HALTC to halt the shutter, and gives the position as a feedback in format PosC:x . The shutter is configured on items in this way:

Rollershutter Shutter_C "Ufficio" (firstfloor, Shutters) ["Blinds"] {serial="/dev/ttyS2@115200,REGEX(PosC:([0-9.]*)),UP(POSC0\n),DOWN(POSC100\n),STOP(HALTC\n)", autoupdate="false" }

Perhaps something have to be reviewed?

pythen commented 5 years ago

@Lele81 With which version of openhab-google-assistant is the error? Can you try from this master repository? https://github.com/pythen/openhab-google-assistant

I use google blinds commands since December without a error.

What's in Google cloud logfile?

For Example:

openhabGoogleAssistant - turnOpenClose reqCommand:{"devices":[{"customData":{"itemTag":"Blinds","itemType":"Rollershutter","openhabVersion":"2.1"},"id":"Roll_OG_Media"}],"execution":[{"command":"action.devices.commands.OpenClose","params":{"openPercent":50}}]}

fmalfatto commented 5 years ago

I'm in the same situation. I use since two month Google Assistant to switch on/off lights and to read temperatures. But I cannot understand how afford rollershutters. Where should I write these example lines ? I simply added the tags in /etc/openhab2/items/Openwebnet.items and they worked ... but not the rollershutters.

Lele81 commented 5 years ago

@pythen i've cloned the official repository replacing openhab.js with the updated one from https://github.com/openhab/openhab-google-assistant/pull/77

This is the log from google cloud:

D openhabGoogleAssistant kknufc1n2vd7 2019-04-24 06:32:18.796 Function execution started I openhabGoogleAssistant kknufc1n2vd7 2019-04-24 06:32:18.930 openhabGoogleAssistant: Cloud function called:{"inputs":[{"context":{"locale_language":"it"},"intent":"action.devices.EXECUTE","payload":{"commands":[{"devices":[{"customData":{"itemTag":"Blinds","itemType":"Rollershutter","openhabVersion":"2.1"},"id":"Shutter_C"}],"execution":[{"command":"action.devices.commands.OpenClose","params":{"openPercent":100}}]}]}}],"requestId":"12856440427210327734"} I openhabGoogleAssistant kknufc1n2vd7 2019-04-24 06:32:18.933 openhabGoogleAssistant - turnOpenClose reqCommand:{"devices":[{"customData":{"itemTag":"Blinds","itemType":"Rollershutter","openhabVersion":"2.1"},"id":"Shutter_C"}],"execution":[{"command":"action.devices.commands.OpenClose","params":{"openPercent":100}}]} I openhabGoogleAssistant kknufc1n2vd7 2019-04-24 06:32:19.847 openhabGoogleAssistant - turnOpenClose done with result:{"requestId":"12856440427210327734","payload":{"commands":{"ids":["Shutter_C"],"status":"SUCCESS"}}} D openhabGoogleAssistant kknufc1n2vd7 2019-04-24 06:32:19.848 Function execution took 1053 ms, finished with status code: 200

Is it possibile that the problem is caused by the assistant passing the percent parameter, when the item accepts only UP, DOWN and STOP commands? In this case i would have to modify the item to pass appropriate command to the serial interface (sending "PosC:x") but i don't know how to do this.

Later I'll test your fork repository, but I fear the problem is what i suppose...

EDIT: your repository tested, same result (files i used yesterday were the same, so no changes on behaviour was expected)

Lele81 commented 5 years ago

@fmalfatto What repository have you used? Can you view rollershutter items as devices on Google home app? I can view them, even if they don't work.

fmalfatto commented 5 years ago

I do not understand what you mean. I installed this: org.openhab.binding.openwebnet-2.5.0.M2-1.jar following the "manual installation" way. Then I added the tags in item file and at first I saw blinds (and they worked too) but after a while (maybe after an upgrade) they disappeared and I never had them again in Home assistant, also if I deleted everything and restart from scratch

pythen commented 5 years ago

@Lele81

Is it possibile that the problem is caused by the assistant passing the percent parameter, when the item accepts only UP, DOWN and STOP commands? In this case i would have to modify the item to pass appropriate command to the serial interface (sending "PosC:x") but i don't know how to do this.

Later I'll test your fork repository, but I fear the problem is what i suppose...

EDIT: your repository tested, same result (files i used yesterday were the same, so no changes on behaviour was expected)

Yes, it's possible.

Is your item definition correct? Try this

Rollershutter Shutter_C "Ufficio" (firstfloor, Shutters) ["Blinds"] {serial="/dev/ttyS2@115200,REGEX(s/^(100|[1-9]?[0-9])$/POSC$1\\n/g),UP(POSC0\n),DOWN(POSC100\n),STOP(HALTC\n)", autoupdate="false" }

Regex test

I'm not sure with \\n or \n in regex command, is better if you test both variants.

REGEX(s/^(100|[1-9]?[0-9])$/POSC$1\\n/g) or REGEX(s/^(100|[1-9]?[0-9])$/POSC$1\n/g)

Lele81 commented 5 years ago

@pythen

With both variants, i received an error on converting regex result in openhab log:

2019-04-29 18:58:50.983 [WARN ] [binding.serial.internal.SerialDevice] - Unable to convert regex result 'PosC:100' for item Shutter_C to number

Other hints?

pythen commented 5 years ago

REGEX(s/^PosC:(100|[1-9]?[0-9])$/$1/g)

https://regex101.com/r/lLPe94/4

Change the string PosC:100 to a number string

BernRos commented 5 years ago

Is it correct that the "Blinds" tag only works with version 2.5.0? I have 2.4.0 and there they are not appearing in Google Home Assistant.

gnalbandian commented 5 years ago

I have OH 2.5.0 build #1583 and yet no blinds showing in Google assistant

pythen commented 5 years ago

@marziman Can I do anything to make the changes deploy faster? Your last comments are 3 weeks ago.

simoneluconi commented 5 years ago

This things should really be maintained by more people. It's unacceptable that if one people "is busy" a lot of user must wait a month for one simple update.

marziman commented 5 years ago

I am deploying it now. It should be online later.

Please keep in mind: It is not only pushing deploy. It needs to be tested and made properly. I am curious if this breaks the whole integration anyone will write here so bold.

@simoneluconi Feel free to take things over. You can be part of it. Helps more than complaining. You will see how much time it will take

marziman commented 5 years ago

Ok guys give me some one more day.

Sorry that I ve delayed this, but is really not a quick shot.

I will post in the community as soon the deployment was successful

marziman commented 5 years ago

Will be fixed with https://github.com/openhab/openhab-google-assistant/pull/77

Lele81 commented 5 years ago

@pythen I've tried your REGEX proposal, but plugin behaviour has not changed, furthermore i got some errors, but I believe this happens because my board says "PosC:x" to report the position but expects "POSCx" to set it (i've done this when i built the board to reduce errors, because TX and RX wires are very near and sometimes RX line picks up TX signal) However, i think i found the problem: when i say "open the rollershutter", the command is internally translated in:

[org.apache.karaf.services.eventadmin] - EventAdmin: Exception during event dispatch [org.osgi.service.event.Event [topic=openhab/command/Shutter_C] {item=Shutter_C, bridgemarker=true, command=0, timestamp=............

and when i say "close the rollershutter" the command is translated to:

[org.apache.karaf.services.eventadmin] - EventAdmin: Exception during event dispatch [org.osgi.service.event.Event [topic=openhab/command/Shutter_C] {item=Shutter_C, bridgemarker=true, command=100, timestamp=............

The difference over the two command was the tag "command", that says 0 or 100, but the serial binding expects only UP, DOWN or HALT command (and i suppose it does not supports percentuals) So the problem could be solved with a modification that sends these commands when a serial binding for the rollershutter is in use.

(or doing a complete rewrite of the binding, that catches the position and sends an halt command when the desidered position has reached, but this is very over my knowledge...)

pythen commented 5 years ago

@Lele81 This problem should be solved on the side of the openhab configuration. Changes the return value for only one connection type is not a good idea.

By rule definition for example

ozirissp commented 5 years ago

Hello,

Is it deployed yet ? Since last Google IO, many new Items can be added to Google Home.

Is there a way have a more simple pipeline and/or staging environnement for fastest testing and release process ?

Easier pipeline may engage more developer to help and improve this binding.

magd1978 commented 5 years ago

Hi. First of all, THANKS for the improvements of the connector for Google Home Assistant. I have a doubt. I understand that the deployment that has been done is only in the Github repository. Then if I want to try it, I should download the latest version of the MASTER branch, compile it and run my own instance of openHAB cloud. Is that so? When will these improvements be applied to myopenhab.org?

Lele81 commented 5 years ago

@pythen I solved the problem by using a workaround. Reading the code, it turned out that actually the serial binding does not support output to serial port by regex, but only allows to apply regex to what comes from the serial. So I could never get this... I therefore turned another way. I added a dimmer item - not published on sitemap - connected to the assistant through ["Blinds"], and an item string for the serial output. Using a rule, when an update arrives on the item connected to the assistant, it sends a specific string via serial link. And it works perfectly.

item file: the Dimmer item is connected to GA as a shutter, giving 0-100 position the shutter item is as it was, untouched and not directly connected to GA.

Dimmer Tapparella_C "Ufficio" (firstfloor,Shutters) ["Blinds"] String ShutterBoard_Data "Shutter Board Data [%s]" (All) {serial="/dev/ttyS2@115200"} Rollershutter Shutter_C "Ufficio" (firstfloor, Shutters) {serial="/dev/ttyS2@115200,REGEX(PosC:([0-9.]*)),UP(POSC0\n),DOWN(POSC100\n),STOP(HALTC\n)", autoupdate="false" }

rules file:

rule "Tapparella_C_Assistant" when Item Tapparella_C received update then val PercInv = 100 - (Integer::parseInt(String::format("%s", Tapparella_C.state))) logInfo("Shutters GoogleAssistant", "Google Assistant request for Shutter C: " + PercInv) sendCommand(ShutterBoard_Data, "POSC"+PercInv+"\n") end

The only "problem" is that in this way google assistant cannot know the actual position of the shutter if it is opened or closed by openhab. But it doesn't really matter, I was interested in controlling shutters with my voice when I am at home, and so i can view their state on my own.

pythen commented 5 years ago

@Lele81 I check it at weekend.

@marziman Did you publish the changes?

marziman commented 5 years ago

@All,

it is deployed. I will take time to make some automation to the deployment. So in future it should not take so much time and be so much depending on my availability.

Sorry again for the delay. Iam closing this issue.

BR Mehmet

magd1978 commented 5 years ago

Hi. I just tried the integration of the blinds with Google Home (Spanish version) and I found an incongruity. For openHab, opening a blind is setting it to 0%. But when asking Google Home to open a blind the received command is 100% (the procentage indicates the opening value instead of the closing value). It can be fixed via openHab rules, but it does not seem like a very elegant solution. I believe that the translation of the values ​​should be done by the openHab connector, whether a command is sent from Google Home, or if an update of the value is reported from openHab. And already put to ask, it would be interesting that you could set some parameter that indicated to the connector whether it must to translate the corrected values ​​0% and 100% to UP / DOWN commands, for bindings that do not support percentages. This parameter could be an additional label such as "UpDownOnly" or "NoPercentage".

ozirissp commented 5 years ago

@magd1978 I have the same issue (french Google Home) ... With this issue I have to ask "OPEN" for closing my shutters and vice versa for CLOSE ... In addition, I also have the "Invert the blinds percentage value" parameter for my Open Zwave channel without this I also have a reverse state of my blinds on UI. If I disable this parameter I have the correct behavior with Google Assistant, but my UI (Android mostly) is messed up.

robin-thoni commented 5 years ago

Seems to be in the right way for me

pythen commented 5 years ago

@All https://github.com/openhab/openhab-google-assistant/issues/82

@simoneluconi Your comment in this form is unnecessary

BernRos commented 5 years ago

I have some issues with my Rollershutters. Google Assistant finds them now, although I'm not sure if everything is OK as there is still a small gear in the icon. When I tell Google Assistant to open or close the blinds, it confirms the command, but nothing happens.

This is my item and the belonging rule:

Item:
Rollershutter Jalousien_OG_Bad   "Rollo Bad" (gBAD, gRollo_OG) [ "Blinds" ]

Rule:
rule "Jalousien Bad"
when
    Item Jalousien_OG_Bad received command
then
    if (receivedCommand==UP) sendHttpGetRequest("http://192.168.0.200/goform/ReadWrite?variable=Jal_BAD_Up_Web&value=1&write=Write")
    if (receivedCommand==STOP) sendHttpGetRequest("http://192.168.0.200/goform/ReadWrite?variable=Jal_BAD_Up_Web&value=0&variable1=Jal_BAD_Down_Web&value=0&write=Write")
    if (receivedCommand==DOWN) sendHttpGetRequest("http://192.168.0.200/goform/ReadWrite?variable=Jal_BAD_Down_Web&value=1&write=Write")
end

With the OpenHAB app or the BasicUI everything works fine (for sure it works also outside of my network, so the connection to myOpenHab should be also OK). Don't know what I'm doing wrong here...

magd1978 commented 5 years ago

I have some issues with my Rollershutters. Google Assistant finds them now, although I'm not sure if everything is OK as there is still a small gear in the icon. When I tell Google Assistant to open or close the blinds, it confirms the command, but nothing happens.

This is my item and the belonging rule:

Item:
Rollershutter Jalousien_OG_Bad   "Rollo Bad" (gBAD, gRollo_OG) [ "Blinds" ]

Rule:
rule "Jalousien Bad"
when
  Item Jalousien_OG_Bad received command
then
  if (receivedCommand==UP) sendHttpGetRequest("http://192.168.0.200/goform/ReadWrite?variable=Jal_BAD_Up_Web&value=1&write=Write")
  if (receivedCommand==STOP) sendHttpGetRequest("http://192.168.0.200/goform/ReadWrite?variable=Jal_BAD_Up_Web&value=0&variable1=Jal_BAD_Down_Web&value=0&write=Write")
  if (receivedCommand==DOWN) sendHttpGetRequest("http://192.168.0.200/goform/ReadWrite?variable=Jal_BAD_Down_Web&value=1&write=Write")
end

With the OpenHAB app or the BasicUI everything works fine. Don't know what I'm doing wrong here...

This is because your implementation does not support percent commands. This is being addressed by @pythen in this new issue #82 that @ozirissp opened.

robin-thoni commented 5 years ago

@BernRos little gear seems to be normal (I was also wondering):