1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/domoticz_ynh.git synced 2024-09-03 18:26:17 +02:00
domoticz_ynh/doc/ADMIN.md

98 lines
5.4 KiB
Markdown
Raw Normal View History

2024-01-22 23:13:37 +01:00
## Broker Mosquitto
2023-02-27 23:24:05 +01:00
2023-06-01 23:28:10 +02:00
During installation, a [MQTT](https://en.wikipedia.org/wiki/MQTT) broker, [Mosquitto](https://mosquitto.org/), is installed at the same time as Domoticz.
2023-11-29 10:25:00 +01:00
This broker requires a dedicated domain or subdomain to work (ex : mqtt.your.domain.tld): creating this domain prior installation is a prerequisite
2024-01-21 17:19:29 +01:00
You may also install the [Mosquitto package](https://github.com/YunoHost-Apps/mosquitto_ynh) without using the one provided by domoticz_ynh.
2023-02-27 23:24:05 +01:00
2023-11-29 10:25:00 +01:00
#### Adding in Domoticz
2023-02-27 23:24:05 +01:00
2023-11-29 10:25:00 +01:00
To use Mosquitto, you need to customize the communication between Domoticz and the broker by following the [domoticz documentation](https://www.domoticz.com/wiki/MQTT#Installing_Mosquitto), part *Add hardware "MQTT Client Gateway"*.
2023-02-27 23:24:05 +01:00
User and password are automatically generated during installation, you may retrieve them with
````
2024-01-22 23:22:25 +01:00
sudo yunohost app setting __APP__ mqtt_user
sudo yunohost app setting __APP__ mqtt_pwd
2023-02-27 23:24:05 +01:00
````
#### Publish/Subscribe
By default, mosquitto will listen on 2 ports:
2023-11-29 10:25:00 +01:00
- 1883 on localhost using MQTT protocol
- 8883 using websocket protocol. NGINX redirect external port 443 to this internal port.
2023-02-27 23:24:05 +01:00
2023-11-29 10:25:00 +01:00
Hence, To publish/subscribe on a topic from the outside, you have to use a software supporting websocket protocol (ex : paho Python library).
2023-02-27 23:24:05 +01:00
#### Mosquitto_pub et mosquitto_sub
These 2 tools do not support websocket protocol, only direct mqtt: base settings will not allow communication from an outside device.
If you're using them directly from your server, this kind of syntax should work:
````
mosquitto_pub -u *user* -P *password* -h mqtt.your.domain.tld -p 1883 -t 'domoticz/in' -m '{ "idx" : 1, "nvalue" : 0, "svalue" : "25.0" }'
````
In the same way:
````
mosquitto_sub -u *user* -P *password* -h mqtt.your.domain.tld -p 1883 -t 'domoticz/out'
````
If you wish to open direct mqtt protocol from an outside device, you'll need to:
2023-11-29 10:25:00 +01:00
- open port 1883 on YunoHost firewall (**Attention, security risk**)
- Allows IP addresses in Mosquitto configuration for this listener
- Set the tls setting in Mosquitto configuration by giving access to crt.pem and key.pem from your mqtt domain by setting respective certfile et keyfile variables. **This is mandatory to ensure a secure connection.**
2023-02-27 23:24:05 +01:00
2023-11-29 10:25:00 +01:00
#### Upgrade from version without Mosquitto
If you have package 2020.2~ynh3 or below or if you have chosen to not set a domain during initial installation, Mosquitto is not installed by default.
2023-02-27 23:24:05 +01:00
If you need to activate mosquitto in retrospect, do following actions:
2023-11-29 10:25:00 +01:00
1. Create a domain or a subdomain (for example: 'mqtt.your.domain.tld')
2023-02-27 23:24:05 +01:00
2. Connect to your server in command line
2024-01-22 23:22:25 +01:00
3. Type following command : `yunohost app setting __APP__ mqtt_domain -v mqtt.your.domain.tld`
2023-11-29 10:25:00 +01:00
4. Upgrade Domoticz to last package.
2024-01-22 23:22:25 +01:00
If you're already on the last package version, use the following command: `yunohost app upgrade __APP__ --force`
2023-02-27 23:24:05 +01:00
## Configuration
### Sensors, language and this kind of stuff
Main configuration of the app take place inside the app itself.
### Zwave management
2023-11-29 10:25:00 +01:00
If you're using Zwave devices, install Mosquitto along Domoticz and give a try to [zwave-JS-UI package](https://github.com/YunoHost-Apps/zwave-js-ui_ynh).
2023-02-27 23:24:05 +01:00
Once installed, just follow instructions from the [wiki](https://www.domoticz.com/wiki/Zwave-JS-UI)
### Access and API
By default, access for the [JSON API](https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's) is allowed on following path `/yourdomain.tld/api_/domoticzpath`.
2023-11-29 10:25:00 +01:00
So if you access Domoticz via https://mydomainname.tld/domoticz, use the following webpath for the API: `/mydomainname.tld/api_/domoticz/json.htm?yourapicommand`
2023-02-27 23:24:05 +01:00
2023-11-29 10:25:00 +01:00
By default, only sensor updates and switch toogle are authorized. To authorized a new command, you have to manually update the NGINX config file:
2023-02-27 23:24:05 +01:00
````
2024-01-22 23:22:25 +01:00
sudo nano /etc/nginx/conf.d/yourdomain.tld.d/api___APP__.conf
2023-02-27 23:24:05 +01:00
````
Then edit the following block by adding the regex of the command you want to allow:
````
#set the list of authorized json command here in regex format
#you may retrieve the command from https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's
#By default, sensors updates and toggle switch are authorized
if ( $args ~* type=command&param=udevice&idx=[0-9]*&nvalue=[0-9]*&svalue=.*$|type=command&param=switchlight&idx=[0-9]*&switchcmd=Toggle$) {
set $api "1";
}
````
2023-11-29 10:25:00 +01:00
For example, to add the JSON command to retrieve the status of a device (/json.htm?type=devices&rid=IDX),modify the line as this:
2023-02-27 23:24:05 +01:00
````
if ( $args ~* type=command&param=udevice&idx=[0-9]*&nvalue=[0-9]*&svalue=.*$|type=command&param=switchlight&idx=[0-9]*&switchcmd=Toggle$|type=devices&rid=[0-9]* ) {
set $api "1";
}
````
All IPv4 addresses within the local network (192.168.0.0/24) and *all IPv6* addresses are authorized as API.
2023-11-29 10:25:00 +01:00
As far as I know, there is no way to filter for IPv6 address on local network: You may remove the authorization by removing or commenting this line in `/etc/nginx/conf.d/yourdomain.tld.d/domoticz.conf`:
2023-02-27 23:24:05 +01:00
````
allow ::/1;
````
2023-11-29 10:25:00 +01:00
This will authorized only IPv4 within local network to access your Domoticz API.
2023-05-26 23:23:50 +02:00
You may add individual IPv6 address in the same way.
2024-01-22 23:13:37 +01:00
## Upgrades
Upgrades from inside the application have been disabled. Well, in fact I just hide the link, so you can still upgrade using the command line if you know how to do it. This is to avoid some unexpected upgrade that may break the YunoHost integration, such as the mandatory user management from 2023.1.
2023-05-26 23:23:50 +02:00
## Limitations
2024-01-22 23:13:37 +01:00
* Backup cannot be restored on a different machine type (arm, x86...) as compiled sources are different
* LDAP is not supported by the upstream app