domoticz-gbridge-plugin icon indicating copy to clipboard operation
domoticz-gbridge-plugin copied to clipboard

Not sending update

Open christoferjh opened this issue 5 years ago • 18 comments

When switching on or off light in domoticz, the state is not sent. Nothing shown in logs. The other way works (can use google to turn lights on and off). Can create new lights from domotics, ping works. What am I doing wrong? Pretty sure this have worked. Using hosted.

christoferjh avatar Jul 04 '19 10:07 christoferjh

Hi, hosted is not supported: if you are hosting gBridge locally and you want to the values pushed back to Google (so you can ask, Hey Google, is the light on?), add the MQTT Client Gateway with LAN interface to your hardware, see third screenshot

giejay avatar Jul 04 '19 11:07 giejay

Not sure I understand? Is it not supported to update state if I use https://gbridge.kappelt.net/? The singular reason I pay is to not need to config and do local hosting?

christoferjh avatar Jul 04 '19 15:07 christoferjh

I dont think I understand you, your lights are turning on and off right? When doing it directly in Domoticz? But you want the state in gBridge so you can query, hey google, is my light on?

giejay avatar Jul 04 '19 16:07 giejay

Exactly! It works to turn lights on and off from gBridge. As I understand gBridge keeps a cache of the state, I guess that cache isn't updated from domoticz via this plugin?

christoferjh avatar Jul 04 '19 16:07 christoferjh

Correct. Only when using the local hosted gBridge, that works.

giejay avatar Jul 04 '19 16:07 giejay

Okay, but is it possible to push the state some other way? Or is it that the hosted version doesn't allow state updating? It looks like it should work by going domoticz -> nod-red -> gBridge, but I guess the limitation is in the hosted version since it could work from this plugin similarly by just forward the changes?

christoferjh avatar Jul 04 '19 17:07 christoferjh

That would involve subscribing to multiple topics, the local domoticz topic, on which all changes are pushed (and then forwarded to gbridge) and subscribing to the remote one. Could be done, maybe Ill dive into it this weekend.

giejay avatar Jul 04 '19 17:07 giejay

Just checking, do you have a local MQTT broker running?

giejay avatar Jul 10 '19 16:07 giejay

Yes, that's how I communicate with mysensors and node-red.

christoferjh avatar Jul 11 '19 11:07 christoferjh

So I tried subscribing to multiple MQTT brokers but it seems Domoticz doesnt like that very much. Im getting a lot of errors. You can try it for yourself by checking out this branch: https://github.com/giejay/domoticz-gbridge-plugin/tree/feature/multiple-mqtt-brokers

You can komma separate the brokers like: mqtt.gbridge.io:1883,192.168.2.17:1883

It needs the local one to have anonymous login.

giejay avatar Jul 12 '19 15:07 giejay

Did you try to use your local MQTT server as bridge ? It's explained here : https://doc.gbridge.io/firstSteps/mqttServer.html#using-own-mosquitto-as-a-bridge I didn't tested it but as I understand it, the distant gbridge MQTT server become a client to the local MQTT server and all the messages are seen locally. This should work without any code modification but the gbridge plugin configuration must be changed to local. @giejay do you think this might work ?

SylvainPer avatar Oct 06 '19 13:10 SylvainPer

Yes that might work indeed!

giejay avatar Oct 06 '19 15:10 giejay

@christoferjh could you try this configuration ? If it works, a section on the readme would be helpful.

SylvainPer avatar Oct 07 '19 07:10 SylvainPer

Previous posts are a long time ago but I'am still using this plugin with a local gbridge. Also trying to get the status working with a bridge. But there is a problem in the plugin why it is not working.

I use friendly names for a device. For example in the description "gBridge:opladen" of a switch device. So the topic in my case is: gBridge/u1/opladen/onoff and switch on/off the device from google is working. But I see the status is published in gBridge/u1/59/onoff/set. So the idx of the device is used and not the friendly name. That is why it is not working I think.

I'am not very familiar with Python but I see I have to change this in de corresponding adapter. But how?

glsf91 avatar Oct 25 '20 12:10 glsf91

Hi,

Here you can change the id to a friendly name: https://github.com/giejay/domoticz-gbridge-plugin/blob/master/adapters/on_off_switch_adapter.py#L40

And for other adapters I guess the same thing should be done

giejay avatar Oct 25 '20 13:10 giejay

Thanks. Yes I discovered this already. But because of lack of Python experience I do not see how I can retrieve the friendly name. I also think at that place you do not know if you have to use the friendly name or the idx.

glsf91 avatar Oct 25 '20 13:10 glsf91

Just replace idx on line 44 with friendlyName or name, not sure which one Domoticz exposes. That is the correct place for publishing new statuses.

giejay avatar Oct 25 '20 13:10 giejay

friendlyName is not a domoticz device thing. It is in the description after gBridge: friendlyname.

But I found another solution and now status is working.

I changed:

def publishState(self, mqtt_client, device, base_topic, value):
    base_topic = base_topic + '/' + str(self.determineDeviceIdOrName(device)) + '/onoff/set'
    mqtt_client.Publish(base_topic, value)

And added:

def determineDeviceIdOrName(self, device):
    if "gBridge" in device['Description']:
        match = re.search('gBridge:(.*)([\n|\r]?)', device['Description'])
        if match:
            res = match.group(1).strip()
        else:
            res = device['idx']
    else:
        res = device['idx']
    return res

glsf91 avatar Oct 25 '20 14:10 glsf91