gytisgreitai / openhab-google-home

13 stars 1 forks source link

Similar named items #6

Closed mtzro2003 closed 4 years ago

mtzro2003 commented 5 years ago

I have a little bit of trouble when turning ON/OFF similar named items... With the openHAB's official google connector it's not happening. So, here are the items:

Switch Kitchen_TV_Switch "Kitchen TV" <television> (gTV_Switch, gNight_Mode_OFF) /*["Switchable"]*/ {google="action.devices.types.TV" [roomHint="Kitchen"]}
Switch Kitchen_TV_Source_TVSource "Kitchen TV Source" (gTV_Sources) /*["Scene"]*/ {google="action.devices.types.SWITCH" [roomHint="Kitchen"]}
Switch Kitchen_TV_Channel_ProTV "Kitchen ProTV" (gTV_Channels) /*["Scene"]*/ {expire="1s, state=NULL", google="action.devices.types.SWITCH" [roomHint="Kitchen"]}

I guess the appellatives for these items would be 'kitchen tv','kitchen tv source' and 'kitchen protv'. When asking Google (being in the kitchen) to Turn ON TV it replies with Sure, turning ON 3 things and all 3 items receive the ON command:

2019-11-06 11:17:36.923 [vent.ItemStateChangedEvent] - Kitchen_TV_Channel_ProTV changed from NULL to ON
2019-11-06 11:17:36.926 [ome.event.ItemCommandEvent] - Item 'Kitchen_TV_Source_TVSource' received command ON
2019-11-06 11:17:36.931 [ome.event.ItemCommandEvent] - Item 'Kitchen_TV_Switch' received command ON

I guess the logs from the app-only image corresponding to this command are:

Request {
  "inputs": [
    {
      "context": {
        "locale_country": "US",
        "locale_language": "en"
      },
      "intent": "action.devices.EXECUTE",
      "payload": {
        "commands": [
          {
            "devices": [
              {
                "customData": {
                  "itemType": "Switch"
                },
                "id": "Kitchen_TV_Channel_ProTV"
              },
              {
                "customData": {
                  "itemType": "Switch"
                },
                "id": "Kitchen_TV_Source_TVSource"
              },
              {
                "customData": {
                  "itemType": "Switch"
                },
                "id": "Kitchen_TV_Switch"
              }
            ],
            "execution": [
              {
                "command": "action.devices.commands.OnOff",
                "params": {
                  "on": true
                }
              }
            ]
          }
        ]
      }
    }
  ],
  "requestId": "4295158831957456047"
}
Headers {
  "host": "XXXXXXXXXXXXXXX:8443",
  "x-real-ip": "66.102.9.105",
  "x-forwarded-for": "66.102.9.105",
  "x-forwarded-proto": "https",
  "connection": "close",
  "content-length": "459",
  "content-type": "application/json;charset=UTF-8",
  "google-assistant-api-version": "v1",
  "authorization": "Bearer 7113feb8173cdec23cdfc109ebc99524ba39917923cbe506cf9a307186762b7f",
  "user-agent": "Mozilla/5.0 (compatible; Google-Cloud-Functions/2.1; +http://www.google.com/bot.html)",
  "accept-encoding": "gzip,deflate,br"
}
on off execute got true
execution result value ON
execution result states {}
on off execute got true
execution result value ON
execution result states {}
on off execute got true
execution result value ON
execution result states {}
Response {
  "status": 200,
  "headers": {
    "content-type": "application/json;charset=utf-8"
  },
  "body": {
    "requestId": "4295158831957456047",
    "payload": {
      "commands": [
        {
          "ids": [
            "Kitchen_TV_Channel_ProTV"
          ],
          "status": "SUCCESS",
          "states": {
            "on": true
          }
        },
        {
          "ids": [
            "Kitchen_TV_Source_TVSource"
          ],
          "status": "SUCCESS",
          "states": {
            "on": true
          }
        },
        {
          "ids": [
            "Kitchen_TV_Switch"
          ],
          "status": "SUCCESS",
          "states": {
            "on": true
          }
        }
      ]
    }
  }
}

I'm sure I could name the items entirely different from each other and, then, the problem will go away, but, as I said, with the official implementation it's not happening. You can see in the items' definition the switchable and scene tags as they were before switch to your implementation... Also, with another names, I will not sound 'natural' when asking Google... I'm in the kitchen and I want to start the TV --> Hey Google, turn on TV; change the channel -- Hey Google, turn on ProTV and so on... Any idea?

gytisgreitai commented 5 years ago
mtzro2003 commented 5 years ago
  • can you post the sync output of those items?

Well, here is the entire log. The last Google query was Hey Google, sync my devices.

  • with official implementation, do you have those items assigned to rooms in google home app?

Yes, assigned to rooms, but manually :laughing:. roomHint was a life saver!

  • is it the same if you rename Kitchen TV -> to TV. what about if you add synonyms="TV" on that item?

Cannot rename to just TV as I also have Bedroom TV, Livingroom TV and so on. A total of 5 TVs, in 5 rooms, and the corresponding channels. You'll see in the log above. Right now, only Kitchen TV has the Kitchen TV Source and Kitchen ProTV channel exposed to your app. The rest are commented while I'm sorting this out. :smile:

  • what if you change item type from TV to SWITCH ?

Tried that. In the beginning they were all switches. I changed to TV only for the icon in Google Home app.

  • behind the scenes, how are you handling that input source and channel switch ?

Well, they are all controlled by Broadlink RM3's, one in each room. All the TVs, all the TV sources and all the channels are part of some groups. Whenever the group changes, the rule identifies the triggeringItem, extract the room and send the command to the corresponding RM3. Something like that. I could share the rules if you're interested :smile: There are 3 Samsungs, 1 Philips - these are "dumb" TVs - and one Philips with Android, but I didn't had the chance to re-write its rule so it's also controlled mostly by infra-red.

gytisgreitai commented 5 years ago

Well I'm guessing that it works by chance in the official implementation - it only executes request for the first device it receives, and others are ignored (looking at implementation it instantly sends the result for the first device). This assumption though could only be verified by running your own instance of official code and looking at stackdriver logs

Another problem might be that I'm passing item name into nicknames, I would need to remove it and check if that helps.

Now, I understand your assumption that if you say turn on TV that google should turn on the device that has type TV but it seems that google is favoring names over device types. One more option to try out is to use synonyms="TV"

BUT:) Afaik the correct way would be to completely change your item mapping. Google has recently relaxed the requirement for Modes and Toggles, I have not had the time to change the docs and do extenstive testing, but it seems that there are some issues with grammar when issuing commands. In theory any word should work with toggles and traits, but from testing done today, it's just some weird stuff going on...

// I could not make it work with item named Kitchen TV, but setting name to Samsung seems to work fine. 
// because with name set to Kitchen TV it was saying "I don't know which Kitchen TV should i turn on", because afaik the name
// doubles you have a TV named "Kitchen TV" and it is in the kitchen so it gets an alias "Kitchen TV". So one physical TV, but two aliases 
// You can say 'turn on the tv' to your kitchen speaker, or 'turn on the Kitchen tv' to any other speaker
Group Kitchen_TV "Samsung TV" { google="action.devices.types.TV" [roomHint="kitchen"]  }
Switch Kitchen_TV_Power  "Kitchen TV Power" (Kitchen_TV) { google="action.devices.traits.OnOff" }

// this one is tricky... theoretically `intput source=input source` should work, but it does not. `input=input`, `output=output` also. 
// and the grammar is quite shitty: `turn source on for the tv` some more trial and error needed perhaps..
Switch Kitchen_TV_InputSource  "Kitchen TV Source" (Kitchen_TV) { google="action.devices.traits.Toggles" [ toggle="source=source",  lang="en"]}

// `hey google, set TV channel to `Viasat Nature` when in Kitchen and `Kitchen_TV_Channel` should receive `viasatnature` command
// if this does not work try using `channel=medium` instead of `channel=channel`. this does not make any sense, but for me 
// `channel=channel` was not fully working when issuing commands to google home mini
String Kitchen_TV_Channel  "Kitchen TV Channel" (Kitchen_TV) { google="action.devices.traits.Modes" [ mode="channel=channel", modeSettings="viasatnature=Viasat Nature,viasatexplorer=Viasat Explorer", lang="en"]}

And pull latest for update, i've fixed one issue with toggles

mtzro2003 commented 5 years ago

Thanks for the suggestions. I'll try and report back in about a week as I'm away on a business trip.

On Wed, Nov 6, 2019, 22:31 Gytis Ramanauskas notifications@github.com wrote:

Well I'm guessing that it works by chance in the official implementation - it only executes request for the first device it receives, and others are ignored (looking at implementation it instantly sends the result for the first device). This assumption though could only be verified by running your own instance of official code and looking at stackdriver logs

Another problem might be that I'm passing item name into nicknames, I would need to remove it and check if that helps.

Now, I understand your assumption that if you say turn on TV that google should turn on the device that has type TV but it seems that google is favoring names over device types. One more option to try out is to use synonyms="TV"

BUT:) Afaik the correct way would be to completely change your item mapping. Google has recently relaxed the requirement for Modes and Toggles, I have not had the time to change the docs and do extenstive testing, but it seems that there are some issues with grammar when issuing commands. In theory any word should work with toggles and traits, but from testing done today, it's just some weird stuff going on...

// I could not make it work with item named Kitchen TV, but setting name to Samsung seems to work fine. // because with name set to Kitchen TV it was saying "I don't know which Kitchen TV should i turn on", because afaik the name // doubles you have a TV named "Kitchen TV" and it is in the kitchen so it gets an alias "Kitchen TV". So one physical TV, but two aliases // You can say 'turn on the tv' to your kitchen speaker, or 'turn on the Kitchen tv' to any other speaker Group Kitchen_TV "Samsung TV" { google="action.devices.types.TV" [roomHint="kitchen"] } Switch Kitchen_TV_Power "Kitchen TV Power" (Kitchen_TV) { google="action.devices.traits.OnOff" }

// this one is tricky... theoretically intput source=input source should work, but it does not. input=input, output=output also. // and the grammar is quite shitty: turn source on for the tv some more trial and error needed perhaps.. Switch Kitchen_TV_InputSource "Kitchen TV Source" (Kitchen_TV) { google="action.devices.traits.Toggles" [ toggle="source=source", lang="en"]}

// hey google, set TV channel toViasat Naturewhen in Kitchen andKitchen_TV_Channelshould receiveviasatnaturecommand // if this does not work try usingchannel=mediuminstead ofchannel=channel. this does not make any sense, but for me //channel=channel` was not fully working when issuing commands to google home mini String Kitchen_TV_Channel "Kitchen TV Channel" (Kitchen_TV) { google="action.devices.traits.Modes" [ mode="channel=channel", modeSettings="viasatnature=Viasat Nature,viasatexplorer=Viasat Explorer", lang="en"]}

And pull latest for update, i've fixed one issue with toggles

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gytisgreitai/openhab-google-home/issues/6?email_source=notifications&email_token=AAQWPISZYIRS55IDJI7VBALQSMSTRA5CNFSM4JJSGDX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDH4OVY#issuecomment-550487895, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQWPIWJOEQ5SH3RW775G6LQSMSTRANCNFSM4JJSGDXQ .

mtzro2003 commented 4 years ago

OK, so back to work :smile: Well, aside from other items (lights and such) now I only have 1 TV defined as:

Group gKitchen_TV "Kitchen Samsung" {google="action.devices.types.TV" [roomHint="Kitchen"]}
Switch Kitchen_TV_Switch "Kitchen TV Power" <television> (gKitchen_TV, gNight_Mode_OFF) {google="action.devices.traits.OnOff"} //{exec=">[ON:sudo python /etc/openhab2/scripts/my_scripts/BlackBeanControl/BlackBeanControl.py -c samsung_power -d Kitchen_RM3] >[OFF:sudo python /etc/openhab2/scripts/my_scripts/BlackBeanControl/BlackBeanControl.py -c samsung_power -d Kitchen_RM3]"}

String Kitchen_TV_Channel "Kitchen TV Channel" <tv_channel> (gKitchen_TV) {google="action.devices.traits.Modes" [mode="channel=channel", modeSettings="bbcearth=16,cartoonnetwork=22,digi24=33,digianimalworld=36,digilife=38,digiworld=49,discovery=50,disneychannel=51,disneyjunior=52,ducktv=54,historychannel=78,minimax=96,natgeo=99,natgeohd=100,natgeowild=101,natgeowildhd=102,nickelodeon=107,protv=117,travelchannel=137,viasatexplorer=153,viasathistory=154,viasatnature=156", lang="en"], expire="1s, state=NULL"}

Items named Kitchen_TV_Channel_ProTV or Kitchen_TV_Source_TVSource where actually commented out and they do not exist anymore. However, when asking (in the Kitchen) Hey Google, turn on TV, it tries to send the command also to those 2 removed devices:

09:46:45.451 [INFO ] [.rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/Kitchen_TV_Channel_ProTV' for the unknown item 'Kitchen_TV_Channel_ProTV'.
09:46:45.466 [INFO ] [.rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/Kitchen_TV_Source_TVSource' for the unknown item 'Kitchen_TV_Source_TVSource'.
09:46:45.483 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Kitchen_TV_Switch' received command ON
09:46:45.484 [ERROR] [se.smarthome.model.script.gKitchen_TV] - Kitchen_TV_Switch received [ON]
09:46:45.484 [INFO ] [smarthome.event.ItemStateChangedEvent] - Kitchen_TV_Switch changed from OFF to ON
09:46:45.487 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Kitchen_TV_Switch' received command ON
09:46:45.488 [ERROR] [se.smarthome.model.script.gKitchen_TV] - Kitchen_TV_Switch received [ON]

Why on Earth does it try to action the source and the channel? I repeat, they are removed. I also removed and re-created the docker app-only, sync'ed devices 2 times. They do not appear in the Google Home items list, nor in openHAB. The official openHAB Google integration is also unlinked - and I don't think I'll ever link it again :smile: For testing purposes, I also have the following rule:

rule "gKitchen_TV"
when
    Member of gKitchen_TV received command
then
    logError("gKitchen_TV", triggeringItem.name.toString + " received [" + receivedCommand + "]")
end

As you can see form openHAB's log:tail the item Kitchen_TV_Switch receives the ON command twice. I'm also attaching the docker

and you can clearly see that, on SYNC it doesn't list Kitchen_TV_Channel_ProTV or Kitchen_TV_Source_TVSource.

Any thoughts?

gytisgreitai commented 4 years ago

I'll have a look at the logs, have you tried rebooting the device and syncing ?

Btw, you have not sanitised the logs. I have removed the link to the log, but in case someone has already viewed it, change your credentials.

mtzro2003 commented 4 years ago

Well, I restarted openHAB's service and re-created the docker with the latest image BEFORE syncing... Do you think I should clean-cache for openHAB and try again? REST API doesn't list those items... Where does Google get them? As I said the container was removed and I don't keep any config outside of it. One last thing would be to delete the google project and re-create it... but it would be really interesting to see why and where does Google get those items...

gytisgreitai commented 4 years ago

No, I mean have you tried rebooting actual google device (Home, mini, etc.)? And can you reproduce the same on your phone where those items are not listed?

mtzro2003 commented 4 years ago

Tried now rebooting the Kitchen device - Google Home Hub - same thing. Tried on other devices and on the phone also. Same thing... it tries to send command to those 2 ghost devices :smile:

Screenshot_20191122-111402

gytisgreitai commented 4 years ago

Well the only thing I can think off is that google for some reason does not like the unofficial TV and REMOTECONTROL devices types, and though sync reports ok, it actually fails somewhere deeer. Maybe try commenting them out, issue sync on the kitchen device, check if items are there, uncomment and sync again?

mtzro2003 commented 4 years ago

Nope, it didn't work... I'll try the last resort - re-create google project. I'll report back.

mtzro2003 commented 4 years ago

Well... DAMN!!! I got it working!!! :fireworks:

I didn't have to re-create everything to get rid of those ghost items... It was enough to unlink and re-link the service!

Now, for the channel switching part... I got that working also!!! It seems that I didn't understand properly the action.devices.traits.Modes :sob: Here's the config that works perfectly:

Group gKitchen_TV "Kitchen Samsung" {google="action.devices.types.TV" [roomHint="Kitchen"]}
Switch Kitchen_TV_Switch "Kitchen TV Power" <television> (gKitchen_TV, gTV_Switch, gNight_Mode_OFF) {google="action.devices.traits.OnOff"}
//String Kitchen_TV_Channel "Kitchen TV Channel" <tv_channel> (gKitchen_TV) {google="action.devices.traits.Modes" [mode="channel=medium", modeSettings="bbcearth=16,cartoonnetwork=22,digi24=33,digianimalworld=36,digilife=38,digiworld=49,discovery=50,disneychannel=51,disneyjunior=52,ducktv=54,historychannel=78,minimax=96,natgeo=99,natgeohd=100,natgeowild=101,natgeowildhd=102,nickelodeon=107,protv=117,travelchannel=137,viasatexplorer=153,viasathistory=154,viasatnature=156", lang="en"], expire="1s, state=NULL"}
String Kitchen_TV_Channel "Kitchen TV Channel" <tv_channel> (gKitchen_TV) {google="action.devices.traits.Modes" [mode="channel=channel", modeSettings="16=bbc earth,22=cartoon network,33=digi 24,36=digi animal world,38=digi life,49=digi world,50=discovery,51=disney channel,52=disney junior,54=duck tv,78=history channel,96=minimax,99=nat geo,100=nat geo hd,101=nat geo wild,102=nat geo wild hd,107=nickelodeon,117=pro tv,137=travel channel,153=viasat explorer,154=viasat history,156=viasat nature", lang="en"], expire="1s, state=NULL"}

Noticed the commented item? The mode and alias where swapped :cry: Also, the alias was not split into words... Here I have to do some trials to check how Google will transcribe the pronounced channel names. If the mode alias is not the same with what Google transcribes it will throw an error because it won't find the mode. From here on, openHAB received the channel number and it's a piece of cake... Now I can get rid of all those openHAB's switches that I was using with the original Google integration.

Hoooooooorrrrrrraaaaaayyyyyyyy!!! :laughing:

I'll try also the source changing part, but at least I'm sure I'm heading in the right direction.

mtzro2003 commented 4 years ago
String Kitchen_TV_Source "Kitchen TV Source" <hdmi> (gKitchen_TV) {google="action.devices.traits.Modes" [mode="source=source", modeSettings="tv=tv,hdmi2=kodi"],expire="1s, state=NULL"}

and it works! "Hey Google, set TV source to TV"

2019-11-22 14:14:03.147 [ERROR] [e.smarthome.model.script.gKitchen_TV] - Kitchen_TV_Switch received [ON]
2019-11-22 14:14:06.341 [ERROR] [e.smarthome.model.script.gKitchen_TV] - Kitchen_TV_Channel received [33]
2019-11-22 14:14:22.233 [ERROR] [e.smarthome.model.script.gKitchen_TV] - Kitchen_TV_Source received [hdmi2]
2019-11-22 14:14:37.512 [ERROR] [e.smarthome.model.script.gKitchen_TV] - Kitchen_TV_Source received [tv]

Thank you very much, Gytis!