Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation about how to set up MQTT #1

Closed
h4nc opened this issue Oct 23, 2018 · 25 comments
Closed

Documentation about how to set up MQTT #1

h4nc opened this issue Oct 23, 2018 · 25 comments
Assignees

Comments

@h4nc
Copy link

h4nc commented Oct 23, 2018

Hi,

first of all thank you for sharing this.

I managed to install your gigaset-elements-proxy and I can see the incoming sensor data in the command line.
In you documentation you say

MQTT events pushes event to queue /gigaset/<sensor_friendly_name> with true or fasle payload

but I cannot receive MQTT events. I'm not very experienced but I think the ServerIP, the user and the password of the MQTT Broker has to be set up somewhere. I can't see anything about this in your documentation.

Could you add this or explain it here how to do that? Is there another config-file for mqtt somewhere?

Would be glad about an answer! Thank you!

@ycardon
Copy link
Owner

ycardon commented Oct 23, 2018

Hello,

You are right, I haven't set properties in the config file for setting ip/user/pwd. Right now it assume that the MQTT server is on the same machine (localhost) with no user/pwd.

const mqtt = require('mqtt').connect('mqtt://localhost', {clientId: 'gigaset-elements-proxy'})

I'll take some time to make these configurable but meanwhile you can change it directly in the above file. According to the mqtt library documentation:

change> connect('mqtt://localhost', {clientId: 'gigaset-elements-proxy'})
to>     connect('mqtt://myserverip', {clientId: 'myclientid', username: 'myuser', password:'mypassword'}) 

@ycardon ycardon self-assigned this Oct 23, 2018
@h4nc
Copy link
Author

h4nc commented Oct 23, 2018

Thanks for the fast reply!

So I changed this line no but I still get no mqtt events on my client.

I'm not really sure which topic I have to subscribe.

The command line window says "acquired event: Toilette | tilt"

So in my MQTT client I subscribed to the topic
/gigaset/Toilette
but I don't get a message.

Also I have to say that for noobs it is hard to follow your documentation. (I had to leard things like that I habe to install npm and git first).
I came here from a home assistant community thread.
In yourdocumentation you say that you use it for home assistant.

Maybe you could also post some configuration/automation examples in the ha community. This is the link:
https://community.home-assistant.io/t/help-needed-with-gigaset-elements/28201

Would be nice if also unexperienced users (most hass.io users) are able to use your code. Maybe I can help, seeing the things from the noob site.

OT: Also another question. I'm not a 100% sure but I think you show two ways to install? By npm and git. This is also confusing. Which one should we choose? I choose git but for this you also have to have npm installed. So what are the differences?

@ycardon
Copy link
Owner

ycardon commented Oct 23, 2018

This events will be written on "gigaset/Toilette" and not on "/gigaset/Toilette" (without the /). My mistake... Maybe you can also enable some logs on MQTT server so that you can see what's happening.

I'm sorry I'm not explicit enough in the documentation but it's not intended to be a tutorial. I'm taking your suggestions and will add a link to the home-assistant community !

git vs. npm: npm is the standard way to install packages and command lines utilities. git is preferable if you have to modify the source code (first because you know where you installed it). As you noticed yourself, as this project is not a "fully integrated project", git is probably better. For both you have to get node installed (npm is coming with node).

NB: It seems that we don't have the same gigaset devices. I have nothing that "tilt": maybe you'll have to modify the following line and replace "close" by "tilt". To find the correct values you can open the following url in a browser http://myserver:3000 and click the "event" link (paste the result here if you want me to have a look, but it's pretty simple: it prints the events as Gigaset cloud is returning them, in the code, I'm just changing some values and sending the events to the local MQTT server: have a look at the code, I home it's quite understandable).

mqtt.publish(`gigaset/${ev.o.friendly_name}`, ev.o.type == 'ds02' && ev.type == 'close' ? 'false' : 'true')

@h4nc
Copy link
Author

h4nc commented Oct 24, 2018

I have three sensor values: open, close and tilt.
If I replaye close by tilt, than close will not be recognized anymore. How do I have to change this.
close = false;
tilt = true, open = true

Also nothing opens at http://myserver:3000
What am I doing wrong?

Thank you very much

@ycardon
Copy link
Owner

ycardon commented Oct 24, 2018

then you will have to change the line to:

mqtt.publish(`gigaset/${ev.o.friendly_name}`, ev.o.type == 'ds02' && (ev.type == 'close' || ev.type == 'tilt') ? 'false' : 'true')

the ? is called the ternary or conditional operator, you can play with the condition before the ?.

Also nothing opens at http://myserver:3000

You did replace "myserver" with your real server name right ? Or maybe you already have a process running on port 3000, you can change that in the application config file.

@h4nc
Copy link
Author

h4nc commented Oct 24, 2018

Thanks I will try that.

yes I tried the ip adress from the gigaset elements base and the one of the mqtt broker. Both did not open.

@ycardon
Copy link
Owner

ycardon commented Oct 24, 2018

myserver will be the server where you've installed gigaset-element-proxy

I'll add some debug information, both for MQTT connection and the web server to help users during the setup.

@ycardon
Copy link
Owner

ycardon commented Oct 24, 2018

btw, do you get that log when launching node app.js

[Wed Oct 24 2018 11:23:07] [INFO]   server listening on http://localhost:3000

@ycardon
Copy link
Owner

ycardon commented Oct 24, 2018

FYI, I've pushed a new version with

  • more options to setup MQTT (server hostname, user and password)
  • handling of 'tilt' event

@h4nc
Copy link
Author

h4nc commented Oct 24, 2018

I installed in on my main system now (everything before was testing on a test system).

I did everything as before and I get the following error when executing Appjs

module.js:549
throw err;
^

Error: Cannot find module 'console-stamp'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (/home/pi/gigaset-elements-proxy/app.js:12:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)

Is it me or a problem with the new version?

Edit: Maybe I have to add that. This time I used
sudo apt-get install nodejs
but using "npm install" was not possible (error: no command).
so I had to install npm additionally.
In the test system I did not install nodejs. So this is also a difference

@h4nc
Copy link
Author

h4nc commented Oct 24, 2018

I started again with a clean stretch lite image.
It works again. Not sure if this is the problem but I didn't use "sudo apt-get install nodejs" this time.

I had another tool on the same system and I want to install this again. Could this be the problem, so that both tool corrupt each other? This is the tool (plantgateway). It also uses mqtt.

https://github.com/ChristianKuehnel/plantgateway

Also I would like to know how you set up your sensors in home assistant.
Did you use something like this?

binary_sensor:
  - platform: mqtt
    name: "Toilette"
    state_topic: "gigaset/Toilette"
    device_class: window

The events are only triggered when something changes right? How do get the right values after a reboot? In this case this values stay unknown until something changes on that sensor right?

Maybe it would be better to use restfull-sensors instead of mqtt, because than it is possible to set a refreshrate. Negative here that you generate a lot of data.
Don't know which way it is butter, but I just worry about getting the right values.

Thanks!

@ycardon
Copy link
Owner

ycardon commented Oct 24, 2018

Error: Cannot find module 'console-stamp'

You're right, the error comes from the fact npm install failed (it retrieves the necessary dependencies). Seems that npmdoes not comes with nodejs (sorry about that, I'm not using raspbian).

I've defined the sensors as you said

binary_sensor:
  - platform: mqtt
    state_topic: gigaset/garage
    name: Porte du garage
    device_class: garage_door
    payload_on: 'true'
    payload_off: 'false'

I'm not sure if the payload_on and payload_off are really mandatory, you will tell me :)

@ycardon
Copy link
Owner

ycardon commented Oct 24, 2018

Could this be the problem, so that both tool corrupt each other

There are no reason they will... I'm using the same MQTT server with various clients: this project but also several ESP8266 (arduino-like) sensors, everything works great. The only difference with your setup is I'm not using any user/password to protect MQTT and maybe it not the same server (I use mosquito).

How do get the right values after a reboot? In this case this values stay unknown until something changes on that sensor right?

Right. I think some users proposed a way to restore previous values in HA, I've never tested it.

use restfull-sensors instead of mqtt

Yes, this is an other option (I haven't gone that way because I also have movement sensors, they will only fire events), you can find the status of the sensors in the "raw" API http://myserver:3000/api/v1/me/basestations, or use this one http://localhost:3000/sensors where I extracted some useful informations (I've just committed a new version to extract the "open/close" state, line 100 of app.js). You can even initialise HA values with the states and then use the mqtt events...

@h4nc
Copy link
Author

h4nc commented Oct 24, 2018

Do you have an example for the restful sensor?

Not sure about the payload thing. I still have to play arround with the whole thing do understand it and get it as I want.

@ycardon
Copy link
Owner

ycardon commented Oct 24, 2018

Nope, I haven't used them (yet :) most of my setup is mqtt based.

Take your time: most of the fun is setting your smart home and learn new things, once it's running... well, it runs.

(and tell me about your mqtt problem so I can close the issue :)

@h4nc
Copy link
Author

h4nc commented Oct 25, 2018

Ok, so

payload_on: 'true'
payload_off: 'false'

is mandatory.

I have the problem now that both "close" and "tilt" send a true value over mqtt. So home assisant see's both as "open".

@ycardon
Copy link
Owner

ycardon commented Oct 25, 2018

So you were able to push gigaset event to mqtt. Good news ! How did you solve your mqtt problem (it might help other users) ? Can you also confirm that you can open the http://myserver:3000/ URL with a browser ?

both "close" and "tilt" send a true value over mqtt

The test in the following line is literally: if the sensor type is ds02 and (event is close or tilt), then return false, otherwise return true. So I guess your sensor type is not ds02. As I told you, my sensors doesn't tilt. Can you have a look at the raw gigaset event API http://myserver:3000/api/v2/me/events and tell me whate is your sensor type (it's just after friendly_name and id) ?

mqtt.publish(`gigaset/${ev.o.friendly_name}`, ev.o.type == 'ds02' && (ev.type == 'close' || ev.type == 'tilt') ? 'false' : 'true')

edit: I've also pushed a new version displaying more information in the log about the acquired event.

@h4nc
Copy link
Author

h4nc commented Oct 25, 2018

So you were able to push gigaset event to mqtt. Good news ! How did you solve your mqtt problem (it might help other users) ? Can you also confirm that you can open the http://myserver:3000/ URL with a browser ?

Yes, I received an event over mqtt. My problem was solved with your advice, changing the localhost to the Ip of my broker (mosquitto addon at hass.io).
I can open http://myserver:3000
I startet your tool yesterday, but the server was not reachable anymore today, I had to start appjs again. But I didn't set up auto start yet. Hopefully this will solve this.

Can you have a look at the raw gigaset event API

It looks like the type is ws02. Problem now could appear if the sensors have different type. I have to look that up also.

@ycardon
Copy link
Owner

ycardon commented Oct 25, 2018

Good, I'm just adding the ws02 sensor type in the test, and if you are ok with that I'm closing the issue. Thank you again for your comments and suggestions.

edit: yes, creating a service will solve the issue. When you start a process node app.js via the command line that is not a deamon (a background process), it is killed when you disconnect your session.

@ycardon ycardon closed this as completed Oct 25, 2018
@h4nc
Copy link
Author

h4nc commented Oct 25, 2018

I looked up all my sensors

i have ws02 (the ones that tilt)
ds02 (door)
and ps02 (motion)

Thank you for your help

Could you also tell me what I have to do to load your changes? Is it just:

git clone https://github.com/ycardon/gigaset-elements-proxy

again?

@ycardon
Copy link
Owner

ycardon commented Oct 25, 2018

You just have to git pull inside the gigaset-element-proxy directory meaning you want to pull the updated content (save somewhere your config/default.yaml or rename it to config/local.yaml so that it's not overwritten), git clone is only needed to initialise the link between a distant project and create a local copy (I know it may sound complicated at first but it's a skill that you will reuse, every git project works like that).

I do also have motion ps2 motion sensors, it should run smoothly :)

@h4nc
Copy link
Author

h4nc commented Oct 25, 2018

When I use git pull I get the message that I have to commit or stash before I merge? What does it mean and what should I do to make it work? Thanks!

@ycardon
Copy link
Owner

ycardon commented Oct 25, 2018

Well this is another long git story. Easier way is to:

  • put aside your config/default.yaml
  • delete the gigaset-element-proxy directory
  • git clone https://github.com/ycardon/gigaset-elements-proxy
  • cd gigaset-elements-proxy
  • npm install
  • put back your config/default.yaml

@h4nc
Copy link
Author

h4nc commented Oct 25, 2018

Thanks, i figured out another way in the meantime.

I removed the appjs file and than did "git pull" again, after this it worked. I didn't even have to care abour default.yaml file (it left it alone for some reason).

@ycardon
Copy link
Owner

ycardon commented May 16, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants