Subscribe to changes in Domoticz switches, Possible?
Moderators: leecollings, remb0
-
- Posts: 347
- Joined: Friday 03 April 2015 17:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Subscribe to changes in Domoticz switches, Possible?
I'm polling the Domoticz system via API calls (http...../json.htm......) to get the latest status of the switches. Polling is not efficient, status only updated according the polling speed, extra data traffic, etc. Is there a way to subscribe to Domoticz and be informed if the status of a Switch changes?
In other words, my app is being informed by Domoticz if there is a status change in one or more switches.
Looking forward to your feedback and suggestions.
In other words, my app is being informed by Domoticz if there is a status change in one or more switches.
Looking forward to your feedback and suggestions.
-
- Posts: 2262
- Joined: Monday 29 August 2016 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
You can open a websocket. Changes in devices are pushed by Domoticz via the websocket to clients.
This mechanism is used by the Domoticz web client and by Dashticz.
Or use mqtt
This mechanism is used by the Domoticz web client and by Dashticz.
Or use mqtt
- heggink
- Posts: 972
- Joined: Tuesday 08 September 2015 21:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 12451
- Location: NL
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
Mqtt should work. Domoticz will post all changes to domoticz/out topic...
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
-
- Posts: 49
- Joined: Wednesday 03 May 2023 10:12
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
What's wrong with on/off action script entry?
- waltervl
- Posts: 5149
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
You can also use the push HTTPlink option if your application supports it. https://www.domoticz.com/wiki/HttpLink
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 347
- Joined: Friday 03 April 2015 17:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
I've thought about that as well indeed. I'm playing with a mobile app. I don't know the IP address of the mobile device and also I don't know within Domoticz if the App is running on the mobile or not. Apart from that I don't want to make much config changes within Domoticz as that makes the installation process for a wider audience more complex. Hence my idea/question if it is possible when the App is running to subscribe to switch changes in Domoticz and that Domoticz then sends message to the mobile App.
-
- Posts: 24
- Joined: Wednesday 26 July 2017 6:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
Greetings!! Can you give me some more info on using the websocket???
Or some links about it
-
- Posts: 2262
- Joined: Monday 29 August 2016 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
I can give a link to the js code:
https://github.com/Dashticz/dashticz/bl ... i.js#LL182
The code is a bit messy...
-
- Posts: 347
- Joined: Friday 03 April 2015 17:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
The websocket sounds really interesting. The only thing left is to find out how this is working. Any more info available apart from the source code which is difficult to read how it works?
-
- Posts: 347
- Joined: Friday 03 April 2015 17:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
Somebody a suggestion on how to make a websocket connection to Domoticz? I'm playing around with this for a couple of hours but without success.
React native example I tried (not a complete list):
var ws = new WebSocket('ws://192.168.0.100/')
var ws = new WebSocket('wss://192.168.0.100/')
var ws = new WebSocket('ws://192.168.0.100/json')
var ws = new WebSocket('wss://192.168.0.100/json')
var ws = new WebSocket('ws://192.168.0.100/json'/)
var ws = new WebSocket('wss://192.168.0.100/json'/)
var ws = new WebSocket('wss://xxxxxx:[email protected]/json')
and many more variations but I cannot get a successful connection.
When using the socket.io module within the Postman application I also cannot get a connection.
Is there a specific configuration required in Domoticz? I'm running the latest version so websockets should be support.
Also I don't know how otherwise to debug this! All support is more then welcome.
React native example I tried (not a complete list):
var ws = new WebSocket('ws://192.168.0.100/')
var ws = new WebSocket('wss://192.168.0.100/')
var ws = new WebSocket('ws://192.168.0.100/json')
var ws = new WebSocket('wss://192.168.0.100/json')
var ws = new WebSocket('ws://192.168.0.100/json'/)
var ws = new WebSocket('wss://192.168.0.100/json'/)
var ws = new WebSocket('wss://xxxxxx:[email protected]/json')
and many more variations but I cannot get a successful connection.
When using the socket.io module within the Postman application I also cannot get a connection.
Is there a specific configuration required in Domoticz? I'm running the latest version so websockets should be support.
Also I don't know how otherwise to debug this! All support is more then welcome.
-
- Posts: 2262
- Joined: Monday 29 August 2016 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
You have to define the protocol. Add ['domoticz'] as second WebSocket parameter.
-
- Posts: 347
- Joined: Friday 03 April 2015 17:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
Excellent, thanks. That was the trick.
This is not working for me:
var ws = new WebSocket('https://192.168.0.100/json/', ["domoticz"])
ws.onopen = () => {
// connection opened
ws.send('something'); // send a message
};
ws.onmessage = (e) => {
// a message was received
console.log(e.data);
};
ws.onerror = (e) => {
// an error occurred
console.log(e.message);
};
-
- Posts: 2262
- Joined: Monday 29 August 2016 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
Is the connection opening? (is the onopen function called?)rgroothuis wrote: ↑Saturday 13 May 2023 13:10Excellent, thanks. That was the trick.
This is not working for me:
var ws = new WebSocket('https://192.168.0.100/json/', ["domoticz"])
ws.onopen = () => {
// connection opened
ws.send('something'); // send a message
};
ws.onmessage = (e) => {
// a message was received
console.log(e.data);
};
ws.onerror = (e) => {
// an error occurred
console.log(e.message);
};
You have to remove the ending slash of the url (/json, not /json/)
In the onopen callback you can send your first message. Something like:
Code: Select all
var msg = {
event: 'request',
requestid: requestid,
query: myquery,
};
requestid = (requestid + 1) % 1000;
try {
socket.send(JSON.stringify(msg));
} catch (ev) {
...
}
Code: Select all
myquery='type=devices&filter=all&used=true&order=Name'
Only after sending a first query via the websocket to Domoticz, Domoticz will send device updates via the websocket to the client.
These device updates will have a requestid -1
-
- Posts: 2262
- Joined: Monday 29 August 2016 22:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
In Chrome DevTools (F12), Network tab, you should see the websocket connection, and the messages that are sent and received.
-
- Posts: 347
- Joined: Friday 03 April 2015 17:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
Sorry. Typo in my text above. Should have been: it is NOW working!! The onopgemerkt is called and without sending data to Domoticz I already get data delivered from Domoticz. This is looking promising. Next is to under the message coming in, how to parse them.
-
- Posts: 49
- Joined: Wednesday 03 May 2023 10:12
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Subscribe to changes in Domoticz switches, Possible?
Okay, seems I misunderstood the objective.rgroothuis wrote: ↑Friday 12 May 2023 16:24 I've thought about that as well indeed. I'm playing with a mobile app. I don't know the IP address of the mobile device and also I don't know within Domoticz if the App is running on the mobile or not. Apart from that I don't want to make much config changes within Domoticz as that makes the installation process for a wider audience more complex. Hence my idea/question if it is possible when the App is running to subscribe to switch changes in Domoticz and that Domoticz then sends message to the mobile App.
Who is online
Users browsing this forum: No registered users and 1 guest