Skip to content

Commit

Permalink
added support for reading historical data
Browse files Browse the repository at this point in the history
  • Loading branch information
windka committed Apr 4, 2022
1 parent 5d56454 commit c69e118
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

## [0.7.0] [2022-04-04]
### historical data can be read out now: see examples

## [0.6.2] [2022-02-19]
### updated icon

Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ msg.payload = {
```


## Getting Historical Data
To read out the internal measurement history you need to specify the start and end data as follows:
```
let end = new Date();
let start = new Date();
start.setDate(end.getDate() - 2); // last 2 days.
msg.payload = {
data : {
from : startDate,
to : endData
}
};
```



# License

Author: Karl-Heinz Wind
Expand Down
2 changes: 1 addition & 1 deletion examples/sense.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"id":"66b4df9cdc60b976","type":"inject","z":"3a763adab0a2a52d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":360,"wires":[["6592afcafa8f6f46"]]},{"id":"30a5462281a04175","type":"debug","z":"3a763adab0a2a52d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":360,"wires":[]},{"id":"58c71aaadfcde7a3","type":"inject","z":"3a763adab0a2a52d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":420,"wires":[["c8e2533ad925c950"]]},{"id":"616a402c7b2fb9c7","type":"inject","z":"3a763adab0a2a52d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":480,"wires":[["f2d67eb619de6923"]]},{"id":"92e22b3bbcf30152","type":"debug","z":"3a763adab0a2a52d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":420,"wires":[]},{"id":"52d922654befa906","type":"debug","z":"3a763adab0a2a52d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":480,"wires":[]},{"id":"6592afcafa8f6f46","type":"grohe sense","z":"3a763adab0a2a52d","location":"dd73ac27fcefb839","room":"WC","appliance":"Sense1","devicetype":"101","description":"","x":440,"y":360,"wires":[["30a5462281a04175"]]},{"id":"c8e2533ad925c950","type":"grohe sense","z":"3a763adab0a2a52d","location":"dd73ac27fcefb839","room":"Küche","appliance":"Sense2","devicetype":"101","description":"","x":440,"y":420,"wires":[["92e22b3bbcf30152"]]},{"id":"f2d67eb619de6923","type":"grohe sense","z":"3a763adab0a2a52d","location":"dd73ac27fcefb839","room":"Wasserkeller","appliance":"Sense3","devicetype":"101","description":"","x":440,"y":480,"wires":[["52d922654befa906"]]},{"id":"dd73ac27fcefb839","type":"grohe location","location":"Haus"}]
[{"id":"66b4df9cdc60b976","type":"inject","z":"3a763adab0a2a52d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":360,"wires":[["6592afcafa8f6f46"]]},{"id":"30a5462281a04175","type":"debug","z":"3a763adab0a2a52d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":360,"wires":[]},{"id":"58c71aaadfcde7a3","type":"inject","z":"3a763adab0a2a52d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":420,"wires":[["c8e2533ad925c950"]]},{"id":"616a402c7b2fb9c7","type":"inject","z":"3a763adab0a2a52d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":480,"wires":[["f2d67eb619de6923"]]},{"id":"92e22b3bbcf30152","type":"debug","z":"3a763adab0a2a52d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":420,"wires":[]},{"id":"52d922654befa906","type":"debug","z":"3a763adab0a2a52d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":480,"wires":[]},{"id":"6592afcafa8f6f46","type":"grohe sense","z":"3a763adab0a2a52d","location":"dd73ac27fcefb839","room":"WC","appliance":"Sense1","devicetype":"101","description":"","x":440,"y":360,"wires":[["30a5462281a04175"]]},{"id":"c8e2533ad925c950","type":"grohe sense","z":"3a763adab0a2a52d","location":"dd73ac27fcefb839","room":"Küche","appliance":"Sense2","devicetype":"101","description":"","x":440,"y":420,"wires":[["92e22b3bbcf30152"]]},{"id":"f2d67eb619de6923","type":"grohe sense","z":"3a763adab0a2a52d","location":"dd73ac27fcefb839","room":"Wasserkeller","appliance":"Sense3","devicetype":"101","description":"","x":440,"y":480,"wires":[["52d922654befa906"]]},{"id":"e3aeb6fbe42726b5","type":"function","z":"3a763adab0a2a52d","name":"data","func":"let end = new Date();\nlet start = new Date();\nstart.setDate(end.getDate() - 1); // last 7 days.\n\nmsg.payload = {\n data : {\n from : start,\n to : end\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":540,"wires":[["f2d67eb619de6923"]]},{"id":"d76b31949d238dd4","type":"inject","z":"3a763adab0a2a52d","name":"get data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":540,"wires":[["e3aeb6fbe42726b5"]]},{"id":"dd73ac27fcefb839","type":"grohe location","location":"Haus"}]
2 changes: 1 addition & 1 deletion examples/senseguard.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"id":"acb005546b6d1d8a","type":"catch","z":"3a763adab0a2a52d","name":"","scope":null,"uncaught":false,"x":130,"y":60,"wires":[["12d34d7f89400a30"]]},{"id":"12d34d7f89400a30","type":"debug","z":"3a763adab0a2a52d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":300,"y":60,"wires":[]},{"id":"d4e111d3e6674702","type":"inject","z":"3a763adab0a2a52d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":120,"wires":[["ed7589d527fde314"]]},{"id":"16aa744e037af364","type":"debug","z":"3a763adab0a2a52d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":120,"wires":[]},{"id":"1714900eea381bcf","type":"inject","z":"3a763adab0a2a52d","name":"open valve","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":120,"y":160,"wires":[["b137886b772ea0d2"]]},{"id":"b137886b772ea0d2","type":"function","z":"3a763adab0a2a52d","name":"open","func":"msg.payload = { \n command : {\n // temp_user_unlock_on: false,\n // reason_for_change: 1,\n // pressure_measurement_running: false,\n // buzzer_on: false,\n // buzzer_sound_profile: 2,\n valve_open: true,\n // measure_now: false,\n }\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":160,"wires":[["ed7589d527fde314"]]},{"id":"2ee7f46b1e23c3be","type":"inject","z":"3a763adab0a2a52d","name":"close valve","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":120,"y":200,"wires":[["01cffcf2a41fdbf6"]]},{"id":"01cffcf2a41fdbf6","type":"function","z":"3a763adab0a2a52d","name":"close","func":"msg.payload = { \n command : {\n // temp_user_unlock_on: false,\n // reason_for_change: 1,\n // pressure_measurement_running: false,\n // buzzer_on: false,\n // buzzer_sound_profile: 2,\n valve_open: false,\n // measure_now: false,\n }\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":200,"wires":[["ed7589d527fde314"]]},{"id":"ed7589d527fde314","type":"grohe sense","z":"3a763adab0a2a52d","location":"dd73ac27fcefb839","room":"Wasserkeller","appliance":"SenseGuard","devicetype":"103","description":"","x":450,"y":120,"wires":[["16aa744e037af364"]]},{"id":"dd73ac27fcefb839","type":"grohe location","location":"Haus"}]
[{"id":"d4e111d3e6674702","type":"inject","z":"3a763adab0a2a52d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":120,"wires":[["ed7589d527fde314"]]},{"id":"16aa744e037af364","type":"debug","z":"3a763adab0a2a52d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":120,"wires":[]},{"id":"1714900eea381bcf","type":"inject","z":"3a763adab0a2a52d","name":"open valve","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":120,"y":220,"wires":[["b137886b772ea0d2"]]},{"id":"b137886b772ea0d2","type":"function","z":"3a763adab0a2a52d","name":"open","func":"msg.payload = { \n command : {\n // temp_user_unlock_on: false,\n // reason_for_change: 1,\n // pressure_measurement_running: false,\n buzzer_on: true,\n // buzzer_sound_profile: 1,\n valve_open: true,\n // measure_now: true,\n }\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":220,"wires":[["ed7589d527fde314"]]},{"id":"2ee7f46b1e23c3be","type":"inject","z":"3a763adab0a2a52d","name":"close valve","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":120,"y":260,"wires":[["01cffcf2a41fdbf6"]]},{"id":"01cffcf2a41fdbf6","type":"function","z":"3a763adab0a2a52d","name":"close","func":"msg.payload = { \n command : {\n // temp_user_unlock_on: false,\n // reason_for_change: 1,\n // pressure_measurement_running: false,\n buzzer_on: false,\n // buzzer_sound_profile: 2,\n valve_open: false,\n // measure_now: false,\n }\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":260,"wires":[["ed7589d527fde314"]]},{"id":"ed7589d527fde314","type":"grohe sense","z":"3a763adab0a2a52d","location":"dd73ac27fcefb839","room":"Wasserkeller","appliance":"SenseGuard","devicetype":"103","description":"","x":510,"y":120,"wires":[["16aa744e037af364"]]},{"id":"c478c1d3715264d5","type":"function","z":"3a763adab0a2a52d","name":"data","func":"let end = new Date();\nlet start = new Date();\nstart.setDate(end.getDate() - 1); // last 7 days.\n\nmsg.payload = {\n data : {\n from : start,\n to : end\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":250,"y":300,"wires":[["ed7589d527fde314"]]},{"id":"8c577a27b2846c21","type":"inject","z":"3a763adab0a2a52d","name":"get data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":300,"wires":[["c478c1d3715264d5"]]},{"id":"dd73ac27fcefb839","type":"grohe location","location":"Haus"}]
78 changes: 54 additions & 24 deletions grohe/99-grohe.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ module.exports = function (RED) {
try {
node.session = await ondusApi.login(node.credentials.username, node.credentials.password);

let response = await node.session.getLocations();
let locations = JSON.parse(response.text);
let response = await node.session.getDahsboard();
let dashboard = JSON.parse(response.text);

let locations = dashboard.locations

for (let i = 0; i < locations.length; i++) {
let location = locations[i];
if (location.name === node.locationName){
node.location = location;

let response2 = await node.session.getRooms(node.location.id);
node.rooms = JSON.parse(response2.text);
node.rooms = location.rooms;

for (let j = 0; j < node.rooms.length; j++) {
let room = node.rooms [j];

let response3 = await node.session.getAppliances(node.location.id, room.id);
let appliances = JSON.parse(response3.text);
let appliances = room.appliances;
node.appliancesByRoomName[room.name] = {
room : room,
appliances : appliances,
Expand Down Expand Up @@ -156,30 +156,56 @@ module.exports = function (RED) {
// Hint: respsonse is not used right now.
}
}
let response1 = await node.config.session.getApplianceInfo(

let responseInfo = await node.config.session.getApplianceInfo(
node.applianceIds.locationId,
node.applianceIds.roomId,
node.applianceIds.applianceId);
let info = JSON.parse(response1.text);
let info = JSON.parse(responseInfo.text);

let response2 = await node.config.session.getApplianceStatus(
node.applianceIds.locationId,
node.applianceIds.roomId,
node.applianceIds.applianceId);
let status = JSON.parse(response2.text);
let responseStatus = await node.config.session.getApplianceStatus(
node.applianceIds.locationId,
node.applianceIds.roomId,
node.applianceIds.applianceId);
let status = JSON.parse(responseStatus.text);

let response3 = await node.config.session.getApplianceNotifications(
let responseNotifications = await node.config.session.getApplianceNotifications(
node.applianceIds.locationId,
node.applianceIds.roomId,
node.applianceIds.applianceId);
let notifications = JSON.parse(response3.text);
let notifications = JSON.parse(responseNotifications.text);

let data;
if(msg.payload !== undefined && msg.payload.data !== undefined ){
let fromDate = msg.payload.data.from;
let toDate = msg.payload.data.to;

let result = {
info : info,
status : status,
notifications : notifications,
};
let responseData = await node.config.session.getApplianceData(
node.applianceIds.locationId,
node.applianceIds.roomId,
node.applianceIds.applianceId,
fromDate,
toDate);
data = JSON.parse(responseData.text);
}

let result = {};

if(info != null){
result.info = info;
}

if(status != null){
result.status = status;
}

if(notifications != null){
result.notifications = notifications;
}

if(data != null){
result.data = data.data;
}

if (info[0].type === ondusApi.OndusType.SenseGuard) {

Expand All @@ -188,15 +214,19 @@ module.exports = function (RED) {
node.applianceIds.roomId,
node.applianceIds.applianceId);
let command = JSON.parse(response4.text);

// Here timestamp could also be interessting in future.
result.command = command.command;
// Here timestamp could also be interessting in future.
}


msg.payload = result;
node.send([msg]);

let notificationCount = notifications.length;
let notificationCount = 0;
if(notifications !== undefined){
notificationCount = notifications.length;
}

if (notificationCount == 0){
node.status({ fill: 'green', shape: 'ring', text: 'ok' });
}
Expand Down
11 changes: 11 additions & 0 deletions grohe/ondusApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ class OndusSession {
});
}

getDahsboard() {
let url = apiUrl + '/dashboard';
return this.get(url);
}

getLocations() {
let url = apiUrl + '/locations';
return this.get(url);
Expand All @@ -253,6 +258,11 @@ class OndusSession {
return this.get(url);
}

getApplianceNotificationId(locationId, roomId, applianceId, notificationId) {
let url = apiUrl + '/locations/' + locationId + '/rooms/' + roomId + '/appliances/' + applianceId + '/notifications/' + notificationId;
return this.get(url);
}

getApplianceData(locationId, roomId, applianceId, fromDate, toDate) {
let url = apiUrl + '/locations/' + locationId + '/rooms/' + roomId + '/appliances/' + applianceId + '/data';
if (fromDate) {
Expand Down Expand Up @@ -300,6 +310,7 @@ let OndusType = {
Sense : 101,
SensePlus : 102,
SenseGuard : 103,
// BlueHome : 104 // TDOD
};


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-grohe-sense",
"version": "0.6.2",
"version": "0.7.0",
"description": "Grohe sense nodes via ondus API.",
"node-red": {
"version": ">=0.1.0",
Expand Down

0 comments on commit c69e118

Please sign in to comment.