├── .devcontainer └── devcontainer.json ├── .eslintrc.json ├── .github └── workflows │ ├── node.js.yml │ └── npm-publish.yml ├── .gitignore ├── .npmignore ├── .prettierrc ├── .vscode └── launch.json ├── LICENSE ├── README.md ├── _config.yml ├── examples ├── current-energy-price.gql ├── grafana │ └── home-power-dashboard.json ├── homes.gql ├── images │ ├── tibber-api-endpoint.png │ ├── tibber-feed.png │ ├── tibber-notify.png │ └── tibber-query.png ├── node-red-home-power.json ├── node-red-tibber-test-flow.json └── send-push-notification.gql ├── node-red-default-settings.js ├── nodes ├── tibber-api-endpoint.html ├── tibber-api-endpoint.js ├── tibber-data.html ├── tibber-data.js ├── tibber-feed.html ├── tibber-feed.js ├── tibber-notify.html ├── tibber-notify.js ├── tibber-query.html └── tibber-query.js ├── package-lock.json ├── package.json └── tests ├── test-tibber-api-endpoint.js ├── test-tibber-feed.js └── test-tibber-query.js /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Node.js & TypeScript", 3 | "image": "mcr.microsoft.com/devcontainers/typescript-node:20", 4 | "features": { 5 | "ghcr.io/devcontainers/features/git:1": {}, 6 | "ghcr.io/devcontainers/features/git-lfs:1": {}, 7 | "ghcr.io/devcontainers/features/github-cli:1": {}, 8 | "ghcr.io/stuartleeks/dev-container-features/shell-history:0": {}, 9 | "ghcr.io/devcontainers/features/docker-in-docker": {} 10 | }, 11 | // Features to add to the dev container. More info: https://containers.dev/implementors/features. 12 | // "features": {}, 13 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 14 | // "forwardPorts": [], 15 | // Use 'postCreateCommand' to run commands after the container is created. 16 | // "postCreateCommand": "yarn install", 17 | // Configure tool-specific properties. 18 | "customizations": { 19 | "vscode": { 20 | "extensions": [ 21 | "github.vscode-pull-request-github", 22 | "ms-vscode.vs-keybindings", 23 | "dbaeumer.vscode-eslint", 24 | "esbenp.prettier-vscode", 25 | "Orta.vscode-jest", 26 | "Gruntfuggly.todo-tree", 27 | "github.vscode-github-actions" 28 | ] 29 | } 30 | }, 31 | "mounts": [ 32 | "type=bind,source=/home/${localEnv:USER}/.ssh,target=/home/node/.ssh", 33 | "type=bind,source=/home/${localEnv:USER}/.zshrc,target=/home/node/.zshrc" 34 | ], 35 | // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. 36 | // "remoteUser": "root" 37 | } -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "commonjs": true, 5 | "node": true 6 | }, 7 | "extends": "eslint:recommended", 8 | "globals": { 9 | "Atomics": "readonly", 10 | "SharedArrayBuffer": "readonly" 11 | }, 12 | "parserOptions": { 13 | "ecmaVersion": 2018 14 | }, 15 | "rules": { 16 | } 17 | } -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [ "**" ] 9 | pull_request: 10 | branches: [ "**" ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [18.x, 20.x, 22.x, lts/*] 20 | # See supported Node.js release schedule at 21 | # https://nodejs.org/en/about/releases/ 22 | # https://nodered.org/docs/faq/node-versions 23 | 24 | steps: 25 | - uses: actions/checkout@v3 26 | - name: Use Node.js ${{ matrix.node-version }} 27 | uses: actions/setup-node@v3 28 | with: 29 | node-version: ${{ matrix.node-version }} 30 | cache: 'npm' 31 | - run: npm ci 32 | - run: npm run build --if-present 33 | - run: npm test 34 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created 2 | # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages 3 | 4 | name: Node.js Package 5 | 6 | on: 7 | release: 8 | types: [published] 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v3 15 | - uses: actions/setup-node@v3 16 | with: 17 | node-version: lts/* 18 | - run: npm ci 19 | - run: npm test 20 | 21 | publish-npm: 22 | needs: build 23 | runs-on: ubuntu-latest 24 | steps: 25 | - uses: actions/checkout@v3 26 | - uses: actions/setup-node@v3 27 | with: 28 | node-version: lts/* 29 | registry-url: https://registry.npmjs.org/ 30 | - run: npm ci 31 | - if: ${{ github.event.release.prerelease }} 32 | run: npm publish . --tag beta 33 | env: 34 | NODE_AUTH_TOKEN: ${{secrets.npm_token}} 35 | - if: ${{ !github.event.release.prerelease }} 36 | run: npm publish . 37 | env: 38 | NODE_AUTH_TOKEN: ${{secrets.npm_token}} 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | # Visual Studio Code dir. 64 | .vscode/ 65 | .config.json* 66 | .flows_* 67 | flows_* 68 | .flows.* 69 | flows.* 70 | .config.*.json 71 | .config.*.json.backup 72 | version.js 73 | version.mjs 74 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .eslintrc.json 2 | .travis.yml 3 | .vscode/ 4 | _config.yml 5 | npm-release* 6 | tests/ 7 | node-red-contrib-tibber-api-*.tgz 8 | .config.json* 9 | .flows_* 10 | flows_* 11 | .config.*.json 12 | .config.*.json.backup 13 | .devcontainer/ 14 | .github/ 15 | .prettierrc 16 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 150, 3 | "trailingComma": "all", 4 | "singleQuote": true, 5 | "tabWidth": 4 6 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Debug Node-Red", 6 | "runtimeArgs": [ 7 | "run-script", 8 | "debug" 9 | ], 10 | "runtimeExecutable": "npm", 11 | "skipFiles": [ 12 | "/**" 13 | ], 14 | "type": "node" 15 | }, 16 | { 17 | "type": "node", 18 | "request": "launch", 19 | "name": "Mocha Tests", 20 | "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", 21 | "args": [ 22 | "--reporter", 23 | "dot", 24 | "--slow", 25 | "5000", 26 | "--colors", 27 | "${file}", 28 | ], 29 | "internalConsoleOptions": "openOnSessionStart", 30 | "skipFiles": [ 31 | "/**" 32 | ] 33 | }, 34 | ] 35 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 André Biseth 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # node-red-contrib-tibber-api 2 | 3 | Node Red module for integrating with Tibber Pulse through Tibber api. 4 | 5 | | Status | NPM | DeepScan | 6 | |--------|-----|----------| 7 | | [![GitHub Actions](https://github.com/bisand/node-red-contrib-tibber-api/actions/workflows/node.js.yml/badge.svg?branch=master)](https://github.com/bisand/node-red-contrib-tibber-api/actions/workflows/node.js.yml) [![GitHub Actions](https://github.com/bisand/node-red-contrib-tibber-api/actions/workflows/npm-publish.yml/badge.svg?event=release)](https://github.com/bisand/node-red-contrib-tibber-api/actions/workflows/npm-publish.yml?event=release) | [![npm version](https://img.shields.io/npm/v/node-red-contrib-tibber-api.svg)](https://www.npmjs.com/package/node-red-contrib-tibber-api) | [![DeepScan grade](https://deepscan.io/api/teams/16513/projects/19830/branches/520473/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=16513&pid=19830&bid=520473) | 8 | 9 | ## General 10 | 11 | This Node-Red module is used for communication with [Tibber API](https://developer.tibber.com/) through [GraphQL](https://developer.tibber.com/docs/overview) queries and for retrieving data from Tibber Pulse via websocket. 12 | [Tibber](https://tibber.com) is a norwegian technology focused power company which is providing tools to get more insight and controll over your home and its power consumption. 13 | 14 | > Note! 15 | > 16 | > From version 5.0.0 the URL for the `tibber-feed` has been removed from `tibber-api-endpoint` configuration node. The only URL needed now is the Query URL. The feed will automatically fetch the websocket url from Tibber. 17 | > 18 | > The version has also been bumped to reflect the version of the underlying [tibber-api](https://www.npmjs.com/package/tibber-api) component. 19 | 20 | ## Prerequisites 21 | 22 | Click the link below to sign up, and receive 400 NOK to shop smart home gadgets from [Tibber Store](https://tibber.com/no/store): 23 | 24 | > [https://invite.tibber.com/fjafad7b](https://invite.tibber.com/fjafad7b) 25 | 26 | You will also need an API token from Tibber. Get it here: 27 | 28 | > https://developer.tibber.com/ 29 | 30 | > Note! In order to use the included Grafana dashboard example, you will need Grafana 6.x or higher. 31 | 32 | ## Installation 33 | 34 | ### NPM package 35 | 36 | > https://www.npmjs.com/package/node-red-contrib-tibber-api 37 | 38 | ### Node-Red 39 | 40 | #### To install module in Node-Red GUI 41 | 42 | 1. Go to main menu. 43 | 2. Select **Manage palette**. 44 | 3. Select **Install** tab. 45 | 4. Search for **node-red-contrib-tibber-api** 46 | 5. Click **Install** button to perform the installation. 47 | 48 | #### Manual installation 49 | 50 | ```bash 51 | $ npm install node-red-contrib-tibber-api 52 | ``` 53 | 54 | ## Nodes 55 | 56 | ### Tibber Feed node (*tibber-feed*) 57 | 58 | ![tibber-feed](examples/images/tibber-feed.png) 59 | 60 | Realtime power consuption data from Tibber Pulse. Provide API token, Home ID and select what kind of information you want to retrieve. 61 | > Note! There should be only one instance running of *tibber-feed* per API key. Doing otherwise may return unpredictable result, or even error responses from the API. 62 | 63 | ### Tibber API call node (*tibber-query*) 64 | 65 | ![tibber-query](examples/images/tibber-query.png) 66 | 67 | Do basic calls to Tibber API using GraphQL queries. To query the Tibber API, simply provide raw GraphQL queries in the payload of the incoming message. See Tibber API documentation and API Explorer for more informations. 68 | 69 | ### Tibber push notification (*tibber-notify*) 70 | 71 | ![tibber-notify](examples/images/tibber-notify.png) 72 | 73 | Send push nofifications to connected TIbber apps via Tibber API using GraphQL queries. Fill in Title, Message and which screen to open in the app directly in the node, or by providing the data via the incomming . 74 | 75 | ### Tibber data (*tibber-data*) 76 | 77 | Select from a set of predefined queries to retrieve data from Tibber API. 78 | The additional parameters can be provided either by the message payload or by configuring the node itself. By using the message payload you will be able to select query and parameters provided by other nodes in the flow. 79 | 80 | Payload example: 81 | ```json 82 | { 83 | "queryName": "getTomorrowsEnergyPrices", 84 | "homeId": "96a14971-525a-4420-aae9-e5aedaa129ff", 85 | "energyResolution": "DAILY", 86 | "lastCount": 14 87 | } 88 | ``` 89 | 90 | Available queries: 91 | ```javascript 92 | /** 93 | * Get selected home with some selected properties, including address and owner. 94 | * @param homeId Tibber home ID 95 | * @return IHome object 96 | */ 97 | getHome(homeId: string): IHome; 98 | 99 | /** 100 | * Get homes with all properties, including energy price, consumption and production. 101 | * @param homeId Tibber home ID 102 | * @return IHome object 103 | */ 104 | getHomeComplete(homeId: string): IHome; 105 | 106 | /** 107 | * Get homes with some selected properties, including address and owner. 108 | * @return Array of IHome. 109 | */ 110 | getHomes(): IHome[]; 111 | 112 | /** 113 | * Get homes with all properties, including energy price, consumption and production. 114 | * @return Array of IHome 115 | */ 116 | getHomesComplete(): IHome[]; 117 | 118 | /** 119 | * Get current energy price for selected home. 120 | * @param homeId Tibber home ID 121 | * @return IPrice object 122 | */ 123 | getCurrentEnergyPrice(homeId: string): IPrice; 124 | 125 | /** 126 | * Get current energy prices from all homes registered to current user 127 | * @return Array of IPrice 128 | */ 129 | getCurrentEnergyPrices(): IPrice[]; 130 | 131 | /** 132 | * Get energy prices for today. 133 | * @param homeId Tibber home ID 134 | * @return Array of IPrice 135 | */ 136 | getTodaysEnergyPrices(homeId: string): IPrice[]; 137 | 138 | /** 139 | * Get energy prices for tomorrow. These will only be available between 12:00 and 23:59 140 | * @param homeId Tibber home ID 141 | * @return Array of IPrice 142 | */ 143 | getTomorrowsEnergyPrices(homeId: string): IPrice[]; 144 | 145 | /** 146 | * Get energy consumption for one or more homes. 147 | * Returns an array of IConsumption 148 | * @param energyResolution EnergyResolution. Valid values: HOURLY, DAILY, WEEKLY, MONTHLY, ANNUAL 149 | * @param lastCount Return the last number of records 150 | * @param homeId Tibber home ID. Optional parameter. Empty parameter will return all registered homes. 151 | * @return Array of IConsumption 152 | */ 153 | getConsumption(energyResolution: EnergyResolution, lastCount: number, homeId?: string): IConsumption[]; 154 | ``` 155 | 156 | ### Configuration node (*tibber-api-endpoint*) 157 | 158 | ![tibber-api-endpoint](examples/images/tibber-api-endpoint.png) 159 | 160 | When configuring regular tibber nodes, you will have to create or select the configuration from the property **API Endpoint**. Here you can specify **GraphQL Endpoint** and **API Key**. This configuration can easily be used by any Tibber nodes. This will greatly simplyfy changing of urls and API key, since the change happens on all nodes using the configuration. 161 | 162 | ## Examples 163 | 164 | To easily test out the examples, you should use a server stack containing Node-Red, InfluxDB, and Grafana. Such stack can easily be installed by using the following docker based IoTServer: 165 | 166 | Installation instructions: 167 | 168 | ```sh 169 | git clone https://github.com/bisand/IoTServer.git iotserver 170 | cd iotserver 171 | sudo ./init.sh 172 | ``` 173 | 174 | Read the included [readme](https://github.com/bisand/IoTServer/blob/master/README.md) for more info. 175 | 176 | ### Node-Red examples 177 | 178 |
179 | Tibber Pulse - Example flow 180 |

181 | 182 | ### tibber-test-flow.json 183 | 184 | ```json 185 | [ 186 | { 187 | "id": "4e0718b1.2af2a8", 188 | "type": "tab", 189 | "label": "Tibber Test Flow", 190 | "disabled": false, 191 | "info": "" 192 | }, 193 | { 194 | "id": "8099995f.515738", 195 | "type": "inject", 196 | "z": "4e0718b1.2af2a8", 197 | "name": "", 198 | "topic": "", 199 | "payload": "{viewer{homes{id size appNickname appAvatar address{address1 address2 address3 postalCode city country latitude longitude}}}}", 200 | "payloadType": "str", 201 | "repeat": "", 202 | "crontab": "", 203 | "once": false, 204 | "onceDelay": 0.1, 205 | "x": 130, 206 | "y": 80, 207 | "wires": [ 208 | [ 209 | "28454c92.811574" 210 | ] 211 | ] 212 | }, 213 | { 214 | "id": "944c04ef.7b6638", 215 | "type": "debug", 216 | "z": "4e0718b1.2af2a8", 217 | "name": "", 218 | "active": true, 219 | "tosidebar": true, 220 | "console": false, 221 | "tostatus": false, 222 | "complete": "false", 223 | "x": 570, 224 | "y": 80, 225 | "wires": [] 226 | }, 227 | { 228 | "id": "c80cad4f.7a806", 229 | "type": "tibber-feed", 230 | "z": "4e0718b1.2af2a8", 231 | "name": "", 232 | "active": true, 233 | "apiUrl": "wss://api.tibber.com/v1-beta/gql/subscriptions", 234 | "apiToken": "d1007ead2dc84a2b82f0de19451c5fb22112f7ae11d19bf2bedb224a003ff74a", 235 | "homeId": "96a14971-525a-4420-aae9-e5aedaa129ff", 236 | "timestamp": "1", 237 | "power": "1", 238 | "lastMeterConsumption": "1", 239 | "accumulatedConsumption": "1", 240 | "accumulatedProduction": "1", 241 | "accumulatedCost": "1", 242 | "accumulatedReward": "1", 243 | "currency": "1", 244 | "minPower": "1", 245 | "averagePower": "1", 246 | "maxPower": "1", 247 | "powerProduction": "1", 248 | "minPowerProduction": "1", 249 | "maxPowerProduction": "1", 250 | "lastMeterProduction": "1", 251 | "powerFactor": "1", 252 | "voltagePhase1": "1", 253 | "voltagePhase2": "1", 254 | "voltagePhase3": "1", 255 | "currentL1": "1", 256 | "currentL2": "1", 257 | "currentL3": "1", 258 | "x": 120, 259 | "y": 180, 260 | "wires": [ 261 | [ 262 | "781f5eed.ea2a3" 263 | ] 264 | ] 265 | }, 266 | { 267 | "id": "781f5eed.ea2a3", 268 | "type": "debug", 269 | "z": "4e0718b1.2af2a8", 270 | "name": "", 271 | "active": true, 272 | "tosidebar": true, 273 | "console": false, 274 | "tostatus": false, 275 | "complete": "false", 276 | "x": 350, 277 | "y": 180, 278 | "wires": [] 279 | }, 280 | { 281 | "id": "28454c92.811574", 282 | "type": "tibber-query", 283 | "z": "4e0718b1.2af2a8", 284 | "name": "", 285 | "active": true, 286 | "apiUrl": "https://api.tibber.com/v1-beta/gql", 287 | "apiToken": "d1007ead2dc84a2b82f0de19451c5fb22112f7ae11d19bf2bedb224a003ff74a", 288 | "x": 350, 289 | "y": 80, 290 | "wires": [ 291 | [ 292 | "944c04ef.7b6638" 293 | ] 294 | ] 295 | }, 296 | { 297 | "id": "f3a4184a.047968", 298 | "type": "tibber-notify", 299 | "z": "4e0718b1.2af2a8", 300 | "name": "", 301 | "active": true, 302 | "apiUrl": "https://api.tibber.com/v1-beta/gql", 303 | "apiToken": "d1007ead2dc84a2b82f0de19451c5fb22112f7ae11d19bf2bedb224a003ff74a", 304 | "notifyTitle": "", 305 | "notifyMessage": "", 306 | "notifyScreen": "", 307 | "x": 330, 308 | "y": 300, 309 | "wires": [] 310 | }, 311 | { 312 | "id": "b0e33b71.865f18", 313 | "type": "inject", 314 | "z": "4e0718b1.2af2a8", 315 | "name": "", 316 | "topic": "", 317 | "payload": "{\"title\":\"Test\",\"message\":\"This is a simple test\",\"screen\":\"HOME\"}", 318 | "payloadType": "json", 319 | "repeat": "", 320 | "crontab": "", 321 | "once": false, 322 | "onceDelay": 0.1, 323 | "x": 120, 324 | "y": 300, 325 | "wires": [ 326 | [ 327 | "f3a4184a.047968" 328 | ] 329 | ] 330 | } 331 | ] 332 | ``` 333 |

334 | 335 |
336 | Tibber Pulse - Home power consumption example 337 |

338 | 339 | ### home-power.json 340 | 341 | ```json 342 | [ 343 | { 344 | "id": "683fd7.e63da028", 345 | "type": "tab", 346 | "label": "Home Energy", 347 | "disabled": false, 348 | "info": "" 349 | }, 350 | { 351 | "id": "b970f3b0.3ff74", 352 | "type": "tibber-feed", 353 | "z": "683fd7.e63da028", 354 | "name": "", 355 | "active": true, 356 | "apiEndpointRef": "8a80f84f.0cbd98", 357 | "homeId": "96a14971-525a-4420-aae9-e5aedaa129ff", 358 | "timestamp": "1", 359 | "power": "1", 360 | "lastMeterConsumption": "1", 361 | "accumulatedConsumption": "1", 362 | "accumulatedProduction": "1", 363 | "accumulatedCost": "1", 364 | "accumulatedReward": "1", 365 | "currency": "1", 366 | "minPower": "1", 367 | "averagePower": "1", 368 | "maxPower": "1", 369 | "powerProduction": "1", 370 | "minPowerProduction": "1", 371 | "maxPowerProduction": "1", 372 | "lastMeterProduction": "1", 373 | "powerFactor": "1", 374 | "voltagePhase1": "1", 375 | "voltagePhase2": "1", 376 | "voltagePhase3": "1", 377 | "currentL1": "1", 378 | "currentL2": "1", 379 | "currentL3": "1", 380 | "x": 140, 381 | "y": 300, 382 | "wires": [["1491f46.f317b0c"]] 383 | }, 384 | { 385 | "id": "4d0b020a.94fbac", 386 | "type": "debug", 387 | "z": "683fd7.e63da028", 388 | "name": "", 389 | "active": false, 390 | "tosidebar": true, 391 | "console": false, 392 | "tostatus": false, 393 | "complete": "false", 394 | "x": 590, 395 | "y": 360, 396 | "wires": [] 397 | }, 398 | { 399 | "id": "2773a5f1.d99aca", 400 | "type": "tibber-query", 401 | "z": "683fd7.e63da028", 402 | "name": "", 403 | "active": true, 404 | "apiEndpointRef": "8a80f84f.0cbd98", 405 | "x": 370, 406 | "y": 100, 407 | "wires": [["4a25248d.5e506c"]] 408 | }, 409 | { 410 | "id": "983cd36.d80383", 411 | "type": "inject", 412 | "z": "683fd7.e63da028", 413 | "name": "Get Home Id", 414 | "topic": "", 415 | "payload": "{ viewer { homes { id address { address1 address2 address3 postalCode city country latitude longitude } } } }", 416 | "payloadType": "str", 417 | "repeat": "", 418 | "crontab": "", 419 | "once": false, 420 | "onceDelay": 0.1, 421 | "x": 150, 422 | "y": 100, 423 | "wires": [["2773a5f1.d99aca"]] 424 | }, 425 | { 426 | "id": "4a25248d.5e506c", 427 | "type": "debug", 428 | "z": "683fd7.e63da028", 429 | "name": "", 430 | "active": true, 431 | "tosidebar": true, 432 | "console": false, 433 | "tostatus": false, 434 | "complete": "false", 435 | "x": 550, 436 | "y": 100, 437 | "wires": [] 438 | }, 439 | { 440 | "id": "e0404127.1a2f8", 441 | "type": "http request", 442 | "z": "683fd7.e63da028", 443 | "name": "", 444 | "method": "POST", 445 | "ret": "txt", 446 | "paytoqs": false, 447 | "url": "http://influxdb:8086/write?precision=s&consistency=any&db=test", 448 | "tls": "", 449 | "proxy": "", 450 | "authType": "", 451 | "x": 590, 452 | "y": 300, 453 | "wires": [["4d0b020a.94fbac"]] 454 | }, 455 | { 456 | "id": "1491f46.f317b0c", 457 | "type": "function", 458 | "z": "683fd7.e63da028", 459 | "name": "Transform payload", 460 | "func": "let p = msg.payload;\n\nif (!p.voltagePhase1)\n return null;\n\nfor (var prop in p) {\n if (!p[prop])\n p[prop] = 0;\n}\n\n// Meassurement\nlet data = \"power\";\n\n// Tag set\ndata += \",location=test\";\ndata += \",currency=\" + p.currency;\n\n// Field set\ndata += \" power=\" + p.power;\ndata += \",lastMeterConsumption=\" + p.lastMeterConsumption;\ndata += \",accumulatedConsumption=\" + p.accumulatedConsumption;\ndata += \",accumulatedProduction=\" + p.accumulatedProduction;\ndata += \",accumulatedCost=\" + p.accumulatedCost;\ndata += \",accumulatedReward=\" + p.accumulatedReward;\ndata += \",minPower=\" + p.minPower;\ndata += \",averagePower=\" + p.averagePower;\ndata += \",maxPower=\" + p.maxPower;\ndata += \",powerProduction=\" + p.powerProduction;\ndata += \",minPowerProduction=\" + p.minPowerProduction;\ndata += \",maxPowerProduction=\" + p.maxPowerProduction;\ndata += \",lastMeterProduction=\" + p.lastMeterProduction;\ndata += \",powerFactor=\" + p.powerFactor;\ndata += \",voltagePhase1=\" + p.voltagePhase1;\ndata += \",voltagePhase2=\" + p.voltagePhase2;\ndata += \",voltagePhase3=\" + p.voltagePhase3;\ndata += \",currentL1=\" + p.currentL1;\ndata += \",currentL2=\" + p.currentL2;\ndata += \",currentL3=\" + p.currentL3;\n\nmsg.payload = data;\n\nreturn msg;\n", 461 | "outputs": 1, 462 | "noerr": 0, 463 | "x": 390, 464 | "y": 300, 465 | "wires": [["e0404127.1a2f8"]] 466 | }, 467 | { 468 | "id": "4286466c.a02e08", 469 | "type": "http request", 470 | "z": "683fd7.e63da028", 471 | "name": "", 472 | "method": "POST", 473 | "ret": "txt", 474 | "paytoqs": false, 475 | "url": "http://influxdb:8086/query?q=CREATE%20DATABASE%20%22test%22", 476 | "tls": "", 477 | "proxy": "", 478 | "authType": "", 479 | "x": 370, 480 | "y": 40, 481 | "wires": [["d102d972.8fb0c8"]] 482 | }, 483 | { 484 | "id": "b24ffef4.c3ca", 485 | "type": "inject", 486 | "z": "683fd7.e63da028", 487 | "name": "Create test database", 488 | "topic": "", 489 | "payload": "", 490 | "payloadType": "str", 491 | "repeat": "", 492 | "crontab": "", 493 | "once": false, 494 | "onceDelay": 0.1, 495 | "x": 170, 496 | "y": 40, 497 | "wires": [["4286466c.a02e08"]] 498 | }, 499 | { 500 | "id": "d102d972.8fb0c8", 501 | "type": "debug", 502 | "z": "683fd7.e63da028", 503 | "name": "", 504 | "active": true, 505 | "tosidebar": true, 506 | "console": false, 507 | "tostatus": false, 508 | "complete": "false", 509 | "x": 550, 510 | "y": 40, 511 | "wires": [] 512 | }, 513 | { 514 | "id": "165b29ab.c7bef6", 515 | "type": "tibber-query", 516 | "z": "683fd7.e63da028", 517 | "name": "", 518 | "active": true, 519 | "apiEndpointRef": "8a80f84f.0cbd98", 520 | "x": 370, 521 | "y": 180, 522 | "wires": [["9f49c320.526db"]] 523 | }, 524 | { 525 | "id": "425b3d0d.8f10d4", 526 | "type": "inject", 527 | "z": "683fd7.e63da028", 528 | "name": "Daily energy prices", 529 | "topic": "", 530 | "payload": "{ viewer { homes { currentSubscription { priceInfo { today { total energy tax startsAt currency level } } } } } }", 531 | "payloadType": "str", 532 | "repeat": "", 533 | "crontab": "30 00 * * *", 534 | "once": false, 535 | "onceDelay": 0.1, 536 | "x": 180, 537 | "y": 180, 538 | "wires": [["165b29ab.c7bef6"]] 539 | }, 540 | { 541 | "id": "810b8faa.9656a", 542 | "type": "debug", 543 | "z": "683fd7.e63da028", 544 | "name": "", 545 | "active": true, 546 | "tosidebar": true, 547 | "console": false, 548 | "tostatus": false, 549 | "complete": "payload", 550 | "targetType": "msg", 551 | "x": 550, 552 | "y": 240, 553 | "wires": [] 554 | }, 555 | { 556 | "id": "9f49c320.526db", 557 | "type": "function", 558 | "z": "683fd7.e63da028", 559 | "name": "Transform energy price", 560 | "func": "let pl = msg.payload;\n\nlet prices = pl.viewer.homes[0].currentSubscription.priceInfo.today;\n\n// Meassurement\nlet data = \"\";\n\nfor(let i = 0; i < prices.length; i++)\n{\n let p = prices[i];\n data += \"energy\";\n\n // Tag set\n data += \",location=test\";\n data += \",currency=\" + p.currency;\n \n // Field set\n data += \" total=\" + p.total;\n data += \",energy=\" + p.energy;\n data += \",tax=\" + p.tax;\n data += \",level=\\\"\" + p.level + \"\\\"\";\n data += \" \" + new Date(p.startsAt).getTime() / 1000 + \"\";\n data += \"\\n\";\n}\n\nmsg.payload = data;\n\nreturn msg;", 561 | "outputs": 1, 562 | "noerr": 0, 563 | "x": 590, 564 | "y": 180, 565 | "wires": [["c478abbd.5715e8"]] 566 | }, 567 | { 568 | "id": "c478abbd.5715e8", 569 | "type": "http request", 570 | "z": "683fd7.e63da028", 571 | "name": "", 572 | "method": "POST", 573 | "ret": "txt", 574 | "paytoqs": false, 575 | "url": "http://influxdb:8086/write?precision=s&consistency=any&db=test", 576 | "tls": "", 577 | "proxy": "", 578 | "authType": "", 579 | "x": 370, 580 | "y": 240, 581 | "wires": [["810b8faa.9656a"]] 582 | }, 583 | { 584 | "id": "8a80f84f.0cbd98", 585 | "type": "tibber-api-endpoint", 586 | "z": "", 587 | "queryUrl": "https://api.tibber.com/v1-beta/gql", 588 | "apiKey": "d1007ead2dc84a2b82f0de19451c5fb22112f7ae11d19bf2bedb224a003ff74a", 589 | "name": "Demo" 590 | } 591 | ] 592 | ``` 593 | 594 |

595 | 596 | ### Grafana example dashboard 597 | 598 |
599 | Grafana - Home power consumption dashboard example 600 |

601 | 602 | ### home-power-dashboard.json 603 | 604 | ```json 605 | { 606 | "annotations": { 607 | "list": [ 608 | { 609 | "builtIn": 1, 610 | "datasource": "-- Grafana --", 611 | "enable": true, 612 | "hide": true, 613 | "iconColor": "rgba(0, 211, 255, 1)", 614 | "name": "Annotations & Alerts", 615 | "type": "dashboard" 616 | } 617 | ] 618 | }, 619 | "editable": true, 620 | "gnetId": null, 621 | "graphTooltip": 0, 622 | "id": 1, 623 | "links": [], 624 | "panels": [ 625 | { 626 | "gridPos": { 627 | "h": 5, 628 | "w": 4, 629 | "x": 0, 630 | "y": 0 631 | }, 632 | "id": 6, 633 | "options": { 634 | "fieldOptions": { 635 | "calcs": [ 636 | "lastNotNull" 637 | ], 638 | "defaults": { 639 | "mappings": [], 640 | "max": 260, 641 | "min": 200, 642 | "thresholds": [ 643 | { 644 | "color": "red", 645 | "value": null 646 | }, 647 | { 648 | "color": "dark-red", 649 | "value": 200 650 | }, 651 | { 652 | "color": "yellow", 653 | "value": 210 654 | }, 655 | { 656 | "color": "green", 657 | "value": 220 658 | }, 659 | { 660 | "color": "green", 661 | "value": 230 662 | }, 663 | { 664 | "color": "#EAB839", 665 | "value": 240 666 | }, 667 | { 668 | "color": "dark-red", 669 | "value": 250 670 | } 671 | ], 672 | "unit": "volt" 673 | }, 674 | "override": {}, 675 | "values": false 676 | }, 677 | "orientation": "auto", 678 | "showThresholdLabels": true, 679 | "showThresholdMarkers": true 680 | }, 681 | "pluginVersion": "6.3.5", 682 | "targets": [ 683 | { 684 | "groupBy": [ 685 | { 686 | "params": [ 687 | "$interval" 688 | ], 689 | "type": "time" 690 | }, 691 | { 692 | "params": [ 693 | "previous" 694 | ], 695 | "type": "fill" 696 | } 697 | ], 698 | "measurement": "power", 699 | "orderByTime": "ASC", 700 | "policy": "default", 701 | "query": "SELECT last(\"voltagePhase1\") FROM \"power\" WHERE $timeFilter", 702 | "rawQuery": false, 703 | "refId": "A", 704 | "resultFormat": "time_series", 705 | "select": [ 706 | [ 707 | { 708 | "params": [ 709 | "voltagePhase1" 710 | ], 711 | "type": "field" 712 | }, 713 | { 714 | "params": [], 715 | "type": "last" 716 | } 717 | ] 718 | ], 719 | "tags": [] 720 | } 721 | ], 722 | "timeFrom": null, 723 | "timeShift": null, 724 | "title": "Voltage - Phase 1", 725 | "type": "gauge" 726 | }, 727 | { 728 | "gridPos": { 729 | "h": 5, 730 | "w": 4, 731 | "x": 4, 732 | "y": 0 733 | }, 734 | "id": 7, 735 | "options": { 736 | "fieldOptions": { 737 | "calcs": [ 738 | "lastNotNull" 739 | ], 740 | "defaults": { 741 | "mappings": [], 742 | "max": 260, 743 | "min": 200, 744 | "thresholds": [ 745 | { 746 | "color": "red", 747 | "value": null 748 | }, 749 | { 750 | "color": "dark-red", 751 | "value": 200 752 | }, 753 | { 754 | "color": "yellow", 755 | "value": 210 756 | }, 757 | { 758 | "color": "green", 759 | "value": 220 760 | }, 761 | { 762 | "color": "green", 763 | "value": 230 764 | }, 765 | { 766 | "color": "#EAB839", 767 | "value": 240 768 | }, 769 | { 770 | "color": "dark-red", 771 | "value": 250 772 | } 773 | ], 774 | "unit": "volt" 775 | }, 776 | "override": {}, 777 | "values": false 778 | }, 779 | "orientation": "auto", 780 | "showThresholdLabels": true, 781 | "showThresholdMarkers": true 782 | }, 783 | "pluginVersion": "6.3.5", 784 | "targets": [ 785 | { 786 | "groupBy": [ 787 | { 788 | "params": [ 789 | "$interval" 790 | ], 791 | "type": "time" 792 | }, 793 | { 794 | "params": [ 795 | "previous" 796 | ], 797 | "type": "fill" 798 | } 799 | ], 800 | "measurement": "power", 801 | "orderByTime": "ASC", 802 | "policy": "default", 803 | "refId": "A", 804 | "resultFormat": "time_series", 805 | "select": [ 806 | [ 807 | { 808 | "params": [ 809 | "voltagePhase2" 810 | ], 811 | "type": "field" 812 | }, 813 | { 814 | "params": [], 815 | "type": "last" 816 | } 817 | ] 818 | ], 819 | "tags": [] 820 | } 821 | ], 822 | "timeFrom": null, 823 | "timeShift": null, 824 | "title": "Voltage - Phase 2", 825 | "type": "gauge" 826 | }, 827 | { 828 | "gridPos": { 829 | "h": 5, 830 | "w": 4, 831 | "x": 8, 832 | "y": 0 833 | }, 834 | "id": 8, 835 | "options": { 836 | "fieldOptions": { 837 | "calcs": [ 838 | "lastNotNull" 839 | ], 840 | "defaults": { 841 | "mappings": [], 842 | "max": 260, 843 | "min": 200, 844 | "thresholds": [ 845 | { 846 | "color": "red", 847 | "value": null 848 | }, 849 | { 850 | "color": "dark-red", 851 | "value": 200 852 | }, 853 | { 854 | "color": "yellow", 855 | "value": 210 856 | }, 857 | { 858 | "color": "green", 859 | "value": 220 860 | }, 861 | { 862 | "color": "green", 863 | "value": 230 864 | }, 865 | { 866 | "color": "#EAB839", 867 | "value": 240 868 | }, 869 | { 870 | "color": "dark-red", 871 | "value": 250 872 | } 873 | ], 874 | "unit": "volt" 875 | }, 876 | "override": {}, 877 | "values": false 878 | }, 879 | "orientation": "auto", 880 | "showThresholdLabels": true, 881 | "showThresholdMarkers": true 882 | }, 883 | "pluginVersion": "6.3.5", 884 | "targets": [ 885 | { 886 | "groupBy": [ 887 | { 888 | "params": [ 889 | "$interval" 890 | ], 891 | "type": "time" 892 | }, 893 | { 894 | "params": [ 895 | "previous" 896 | ], 897 | "type": "fill" 898 | } 899 | ], 900 | "measurement": "power", 901 | "orderByTime": "ASC", 902 | "policy": "default", 903 | "refId": "A", 904 | "resultFormat": "time_series", 905 | "select": [ 906 | [ 907 | { 908 | "params": [ 909 | "voltagePhase3" 910 | ], 911 | "type": "field" 912 | }, 913 | { 914 | "params": [], 915 | "type": "last" 916 | } 917 | ] 918 | ], 919 | "tags": [] 920 | } 921 | ], 922 | "timeFrom": null, 923 | "timeShift": null, 924 | "title": "Voltage - Phase 3", 925 | "type": "gauge" 926 | }, 927 | { 928 | "gridPos": { 929 | "h": 13, 930 | "w": 4, 931 | "x": 12, 932 | "y": 0 933 | }, 934 | "id": 4, 935 | "interval": "", 936 | "options": { 937 | "displayMode": "lcd", 938 | "fieldOptions": { 939 | "calcs": [ 940 | "lastNotNull" 941 | ], 942 | "defaults": { 943 | "decimals": 2, 944 | "mappings": [], 945 | "max": 50, 946 | "min": 0, 947 | "thresholds": [ 948 | { 949 | "color": "green", 950 | "value": null 951 | }, 952 | { 953 | "color": "yellow", 954 | "value": 25 955 | }, 956 | { 957 | "color": "red", 958 | "value": 40 959 | } 960 | ], 961 | "title": "", 962 | "unit": "amp" 963 | }, 964 | "override": {}, 965 | "values": false 966 | }, 967 | "orientation": "vertical" 968 | }, 969 | "pluginVersion": "6.3.5", 970 | "targets": [ 971 | { 972 | "alias": "Phase 1", 973 | "groupBy": [], 974 | "measurement": "power", 975 | "orderByTime": "ASC", 976 | "policy": "default", 977 | "refId": "A", 978 | "resultFormat": "time_series", 979 | "select": [ 980 | [ 981 | { 982 | "params": [ 983 | "currentL1" 984 | ], 985 | "type": "field" 986 | } 987 | ] 988 | ], 989 | "tags": [] 990 | }, 991 | { 992 | "alias": "Phase 2", 993 | "groupBy": [], 994 | "measurement": "power", 995 | "orderByTime": "ASC", 996 | "policy": "default", 997 | "refId": "B", 998 | "resultFormat": "time_series", 999 | "select": [ 1000 | [ 1001 | { 1002 | "params": [ 1003 | "currentL2" 1004 | ], 1005 | "type": "field" 1006 | } 1007 | ] 1008 | ], 1009 | "tags": [] 1010 | }, 1011 | { 1012 | "alias": "Phase 3", 1013 | "groupBy": [], 1014 | "measurement": "power", 1015 | "orderByTime": "ASC", 1016 | "policy": "default", 1017 | "refId": "C", 1018 | "resultFormat": "time_series", 1019 | "select": [ 1020 | [ 1021 | { 1022 | "params": [ 1023 | "currentL3" 1024 | ], 1025 | "type": "field" 1026 | } 1027 | ] 1028 | ], 1029 | "tags": [] 1030 | } 1031 | ], 1032 | "timeFrom": null, 1033 | "timeShift": null, 1034 | "title": "Phase current", 1035 | "type": "bargauge" 1036 | }, 1037 | { 1038 | "cacheTimeout": null, 1039 | "colorBackground": false, 1040 | "colorPostfix": false, 1041 | "colorPrefix": false, 1042 | "colorValue": true, 1043 | "colors": [ 1044 | "#299c46", 1045 | "rgba(237, 129, 40, 0.89)", 1046 | "#d44a3a" 1047 | ], 1048 | "format": "watt", 1049 | "gauge": { 1050 | "maxValue": 100, 1051 | "minValue": 0, 1052 | "show": false, 1053 | "thresholdLabels": false, 1054 | "thresholdMarkers": true 1055 | }, 1056 | "gridPos": { 1057 | "h": 4, 1058 | "w": 4, 1059 | "x": 16, 1060 | "y": 0 1061 | }, 1062 | "id": 10, 1063 | "interval": null, 1064 | "links": [], 1065 | "mappingType": 1, 1066 | "mappingTypes": [ 1067 | { 1068 | "name": "value to text", 1069 | "value": 1 1070 | }, 1071 | { 1072 | "name": "range to text", 1073 | "value": 2 1074 | } 1075 | ], 1076 | "maxDataPoints": 100, 1077 | "nullPointMode": "connected", 1078 | "nullText": null, 1079 | "options": {}, 1080 | "pluginVersion": "6.3.5", 1081 | "postfix": "", 1082 | "postfixFontSize": "50%", 1083 | "prefix": "", 1084 | "prefixFontSize": "50%", 1085 | "rangeMaps": [ 1086 | { 1087 | "from": "null", 1088 | "text": "N/A", 1089 | "to": "null" 1090 | } 1091 | ], 1092 | "sparkline": { 1093 | "fillColor": "rgb(3, 94, 107)", 1094 | "full": false, 1095 | "lineColor": "rgb(31, 120, 193)", 1096 | "show": false, 1097 | "ymax": null, 1098 | "ymin": null 1099 | }, 1100 | "tableColumn": "", 1101 | "targets": [ 1102 | { 1103 | "groupBy": [ 1104 | { 1105 | "params": [ 1106 | "$__interval" 1107 | ], 1108 | "type": "time" 1109 | }, 1110 | { 1111 | "params": [ 1112 | "null" 1113 | ], 1114 | "type": "fill" 1115 | } 1116 | ], 1117 | "measurement": "power", 1118 | "orderByTime": "ASC", 1119 | "policy": "default", 1120 | "refId": "A", 1121 | "resultFormat": "time_series", 1122 | "select": [ 1123 | [ 1124 | { 1125 | "params": [ 1126 | "power" 1127 | ], 1128 | "type": "field" 1129 | }, 1130 | { 1131 | "params": [], 1132 | "type": "last" 1133 | } 1134 | ] 1135 | ], 1136 | "tags": [] 1137 | } 1138 | ], 1139 | "thresholds": "5000,10000", 1140 | "timeFrom": null, 1141 | "timeShift": null, 1142 | "title": "Current power", 1143 | "type": "singlestat", 1144 | "valueFontSize": "100%", 1145 | "valueMaps": [ 1146 | { 1147 | "op": "=", 1148 | "text": "N/A", 1149 | "value": "null" 1150 | } 1151 | ], 1152 | "valueName": "current" 1153 | }, 1154 | { 1155 | "cacheTimeout": null, 1156 | "colorBackground": false, 1157 | "colorValue": false, 1158 | "colors": [ 1159 | "#299c46", 1160 | "rgba(237, 129, 40, 0.89)", 1161 | "#d44a3a" 1162 | ], 1163 | "decimals": 2, 1164 | "format": "kwatth", 1165 | "gauge": { 1166 | "maxValue": 100, 1167 | "minValue": 0, 1168 | "show": false, 1169 | "thresholdLabels": false, 1170 | "thresholdMarkers": true 1171 | }, 1172 | "gridPos": { 1173 | "h": 4, 1174 | "w": 4, 1175 | "x": 20, 1176 | "y": 0 1177 | }, 1178 | "id": 17, 1179 | "interval": null, 1180 | "links": [], 1181 | "mappingType": 1, 1182 | "mappingTypes": [ 1183 | { 1184 | "name": "value to text", 1185 | "value": 1 1186 | }, 1187 | { 1188 | "name": "range to text", 1189 | "value": 2 1190 | } 1191 | ], 1192 | "maxDataPoints": 100, 1193 | "nullPointMode": "connected", 1194 | "nullText": null, 1195 | "options": {}, 1196 | "postfix": "", 1197 | "postfixFontSize": "50%", 1198 | "prefix": "", 1199 | "prefixFontSize": "50%", 1200 | "rangeMaps": [ 1201 | { 1202 | "from": "null", 1203 | "text": "N/A", 1204 | "to": "null" 1205 | } 1206 | ], 1207 | "sparkline": { 1208 | "fillColor": "rgba(31, 118, 189, 0.18)", 1209 | "full": false, 1210 | "lineColor": "rgb(31, 120, 193)", 1211 | "show": false, 1212 | "ymax": null, 1213 | "ymin": null 1214 | }, 1215 | "tableColumn": "", 1216 | "targets": [ 1217 | { 1218 | "groupBy": [ 1219 | { 1220 | "params": [ 1221 | "$__interval" 1222 | ], 1223 | "type": "time" 1224 | }, 1225 | { 1226 | "params": [ 1227 | "null" 1228 | ], 1229 | "type": "fill" 1230 | } 1231 | ], 1232 | "measurement": "power", 1233 | "orderByTime": "ASC", 1234 | "policy": "default", 1235 | "refId": "A", 1236 | "resultFormat": "time_series", 1237 | "select": [ 1238 | [ 1239 | { 1240 | "params": [ 1241 | "accumulatedConsumption" 1242 | ], 1243 | "type": "field" 1244 | }, 1245 | { 1246 | "params": [], 1247 | "type": "last" 1248 | } 1249 | ] 1250 | ], 1251 | "tags": [] 1252 | } 1253 | ], 1254 | "thresholds": "", 1255 | "timeFrom": null, 1256 | "timeShift": null, 1257 | "title": "Consumption today", 1258 | "type": "singlestat", 1259 | "valueFontSize": "80%", 1260 | "valueMaps": [ 1261 | { 1262 | "op": "=", 1263 | "text": "N/A", 1264 | "value": "null" 1265 | } 1266 | ], 1267 | "valueName": "current" 1268 | }, 1269 | { 1270 | "cacheTimeout": null, 1271 | "colorBackground": false, 1272 | "colorPostfix": false, 1273 | "colorPrefix": false, 1274 | "colorValue": true, 1275 | "colors": [ 1276 | "#299c46", 1277 | "rgba(237, 129, 40, 0.89)", 1278 | "#d44a3a" 1279 | ], 1280 | "format": "watt", 1281 | "gauge": { 1282 | "maxValue": 100, 1283 | "minValue": 0, 1284 | "show": false, 1285 | "thresholdLabels": false, 1286 | "thresholdMarkers": true 1287 | }, 1288 | "gridPos": { 1289 | "h": 3, 1290 | "w": 4, 1291 | "x": 16, 1292 | "y": 4 1293 | }, 1294 | "id": 11, 1295 | "interval": null, 1296 | "links": [], 1297 | "mappingType": 1, 1298 | "mappingTypes": [ 1299 | { 1300 | "name": "value to text", 1301 | "value": 1 1302 | }, 1303 | { 1304 | "name": "range to text", 1305 | "value": 2 1306 | } 1307 | ], 1308 | "maxDataPoints": 100, 1309 | "nullPointMode": "connected", 1310 | "nullText": null, 1311 | "options": {}, 1312 | "pluginVersion": "6.3.5", 1313 | "postfix": "", 1314 | "postfixFontSize": "50%", 1315 | "prefix": "", 1316 | "prefixFontSize": "50%", 1317 | "rangeMaps": [ 1318 | { 1319 | "from": "null", 1320 | "text": "N/A", 1321 | "to": "null" 1322 | } 1323 | ], 1324 | "sparkline": { 1325 | "fillColor": "rgb(3, 94, 107)", 1326 | "full": false, 1327 | "lineColor": "rgb(31, 120, 193)", 1328 | "show": false, 1329 | "ymax": null, 1330 | "ymin": null 1331 | }, 1332 | "tableColumn": "", 1333 | "targets": [ 1334 | { 1335 | "groupBy": [ 1336 | { 1337 | "params": [ 1338 | "$__interval" 1339 | ], 1340 | "type": "time" 1341 | }, 1342 | { 1343 | "params": [ 1344 | "null" 1345 | ], 1346 | "type": "fill" 1347 | } 1348 | ], 1349 | "measurement": "power", 1350 | "orderByTime": "ASC", 1351 | "policy": "default", 1352 | "refId": "A", 1353 | "resultFormat": "time_series", 1354 | "select": [ 1355 | [ 1356 | { 1357 | "params": [ 1358 | "averagePower" 1359 | ], 1360 | "type": "field" 1361 | }, 1362 | { 1363 | "params": [], 1364 | "type": "last" 1365 | } 1366 | ] 1367 | ], 1368 | "tags": [] 1369 | } 1370 | ], 1371 | "thresholds": "5000,10000", 1372 | "timeFrom": null, 1373 | "timeShift": null, 1374 | "title": "Average power", 1375 | "type": "singlestat", 1376 | "valueFontSize": "80%", 1377 | "valueMaps": [ 1378 | { 1379 | "op": "=", 1380 | "text": "N/A", 1381 | "value": "null" 1382 | } 1383 | ], 1384 | "valueName": "current" 1385 | }, 1386 | { 1387 | "cacheTimeout": null, 1388 | "colorBackground": false, 1389 | "colorValue": false, 1390 | "colors": [ 1391 | "#299c46", 1392 | "rgba(237, 129, 40, 0.89)", 1393 | "#d44a3a" 1394 | ], 1395 | "decimals": 2, 1396 | "format": "currencyNOK", 1397 | "gauge": { 1398 | "maxValue": 100, 1399 | "minValue": 0, 1400 | "show": false, 1401 | "thresholdLabels": false, 1402 | "thresholdMarkers": true 1403 | }, 1404 | "gridPos": { 1405 | "h": 3, 1406 | "w": 4, 1407 | "x": 20, 1408 | "y": 4 1409 | }, 1410 | "id": 20, 1411 | "interval": null, 1412 | "links": [], 1413 | "mappingType": 1, 1414 | "mappingTypes": [ 1415 | { 1416 | "name": "value to text", 1417 | "value": 1 1418 | }, 1419 | { 1420 | "name": "range to text", 1421 | "value": 2 1422 | } 1423 | ], 1424 | "maxDataPoints": 100, 1425 | "nullPointMode": "connected", 1426 | "nullText": null, 1427 | "options": {}, 1428 | "postfix": "", 1429 | "postfixFontSize": "50%", 1430 | "prefix": "", 1431 | "prefixFontSize": "50%", 1432 | "rangeMaps": [ 1433 | { 1434 | "from": "null", 1435 | "text": "N/A", 1436 | "to": "null" 1437 | } 1438 | ], 1439 | "sparkline": { 1440 | "fillColor": "rgba(31, 118, 189, 0.18)", 1441 | "full": false, 1442 | "lineColor": "rgb(31, 120, 193)", 1443 | "show": false, 1444 | "ymax": null, 1445 | "ymin": null 1446 | }, 1447 | "tableColumn": "", 1448 | "targets": [ 1449 | { 1450 | "groupBy": [ 1451 | { 1452 | "params": [ 1453 | "$__interval" 1454 | ], 1455 | "type": "time" 1456 | }, 1457 | { 1458 | "params": [ 1459 | "previous" 1460 | ], 1461 | "type": "fill" 1462 | } 1463 | ], 1464 | "measurement": "energy", 1465 | "orderByTime": "ASC", 1466 | "policy": "default", 1467 | "query": "SELECT last(\"total\") + (41.91 / 100) + ((287.5 / 30.5) / 24) FROM \"energy\" WHERE $timeFilter GROUP BY time($__interval) fill(previous)\n-- Nettleie: 41.91 øre/KWh\n-- Månedlig fastpris: 287,50", 1468 | "rawQuery": true, 1469 | "refId": "A", 1470 | "resultFormat": "time_series", 1471 | "select": [ 1472 | [ 1473 | { 1474 | "params": [ 1475 | "total" 1476 | ], 1477 | "type": "field" 1478 | }, 1479 | { 1480 | "params": [], 1481 | "type": "mean" 1482 | } 1483 | ] 1484 | ], 1485 | "tags": [] 1486 | } 1487 | ], 1488 | "thresholds": "", 1489 | "timeFrom": null, 1490 | "timeShift": null, 1491 | "title": "Current price / KWh", 1492 | "type": "singlestat", 1493 | "valueFontSize": "80%", 1494 | "valueMaps": [ 1495 | { 1496 | "op": "=", 1497 | "text": "N/A", 1498 | "value": "null" 1499 | } 1500 | ], 1501 | "valueName": "current" 1502 | }, 1503 | { 1504 | "aliasColors": {}, 1505 | "bars": false, 1506 | "dashLength": 10, 1507 | "dashes": false, 1508 | "decimals": 2, 1509 | "description": "", 1510 | "fill": 1, 1511 | "fillGradient": 4, 1512 | "gridPos": { 1513 | "h": 8, 1514 | "w": 12, 1515 | "x": 0, 1516 | "y": 5 1517 | }, 1518 | "id": 2, 1519 | "interval": "", 1520 | "legend": { 1521 | "alignAsTable": false, 1522 | "avg": false, 1523 | "current": true, 1524 | "hideEmpty": false, 1525 | "hideZero": false, 1526 | "max": false, 1527 | "min": false, 1528 | "rightSide": false, 1529 | "show": true, 1530 | "total": false, 1531 | "values": true 1532 | }, 1533 | "lines": true, 1534 | "linewidth": 1, 1535 | "nullPointMode": "connected", 1536 | "options": { 1537 | "dataLinks": [] 1538 | }, 1539 | "percentage": false, 1540 | "pointradius": 2, 1541 | "points": false, 1542 | "renderer": "flot", 1543 | "seriesOverrides": [ 1544 | { 1545 | "alias": "Power", 1546 | "yaxis": 2 1547 | }, 1548 | { 1549 | "alias": "Price", 1550 | "yaxis": 1 1551 | } 1552 | ], 1553 | "spaceLength": 10, 1554 | "stack": false, 1555 | "steppedLine": false, 1556 | "targets": [ 1557 | { 1558 | "alias": "Power", 1559 | "groupBy": [ 1560 | { 1561 | "params": [ 1562 | "$__interval" 1563 | ], 1564 | "type": "time" 1565 | }, 1566 | { 1567 | "params": [ 1568 | "linear" 1569 | ], 1570 | "type": "fill" 1571 | } 1572 | ], 1573 | "hide": false, 1574 | "measurement": "power", 1575 | "orderByTime": "ASC", 1576 | "policy": "default", 1577 | "refId": "A", 1578 | "resultFormat": "time_series", 1579 | "select": [ 1580 | [ 1581 | { 1582 | "params": [ 1583 | "power" 1584 | ], 1585 | "type": "field" 1586 | }, 1587 | { 1588 | "params": [], 1589 | "type": "last" 1590 | } 1591 | ] 1592 | ], 1593 | "tags": [] 1594 | }, 1595 | { 1596 | "alias": "Price", 1597 | "groupBy": [ 1598 | { 1599 | "params": [ 1600 | "$__interval" 1601 | ], 1602 | "type": "time" 1603 | }, 1604 | { 1605 | "params": [ 1606 | "previous" 1607 | ], 1608 | "type": "fill" 1609 | } 1610 | ], 1611 | "measurement": "energy", 1612 | "orderByTime": "ASC", 1613 | "policy": "default", 1614 | "refId": "B", 1615 | "resultFormat": "time_series", 1616 | "select": [ 1617 | [ 1618 | { 1619 | "params": [ 1620 | "total" 1621 | ], 1622 | "type": "field" 1623 | }, 1624 | { 1625 | "params": [], 1626 | "type": "mean" 1627 | } 1628 | ] 1629 | ], 1630 | "tags": [] 1631 | } 1632 | ], 1633 | "thresholds": [], 1634 | "timeFrom": null, 1635 | "timeRegions": [], 1636 | "timeShift": null, 1637 | "title": "Power consumprion", 1638 | "tooltip": { 1639 | "shared": true, 1640 | "sort": 0, 1641 | "value_type": "individual" 1642 | }, 1643 | "type": "graph", 1644 | "xaxis": { 1645 | "buckets": null, 1646 | "mode": "time", 1647 | "name": null, 1648 | "show": true, 1649 | "values": [] 1650 | }, 1651 | "yaxes": [ 1652 | { 1653 | "format": "currencyNOK", 1654 | "label": "Price", 1655 | "logBase": 1, 1656 | "max": null, 1657 | "min": null, 1658 | "show": true 1659 | }, 1660 | { 1661 | "decimals": null, 1662 | "format": "watt", 1663 | "label": "Energy", 1664 | "logBase": 1, 1665 | "max": null, 1666 | "min": null, 1667 | "show": true 1668 | } 1669 | ], 1670 | "yaxis": { 1671 | "align": false, 1672 | "alignLevel": null 1673 | } 1674 | }, 1675 | { 1676 | "cacheTimeout": null, 1677 | "colorBackground": false, 1678 | "colorPostfix": false, 1679 | "colorPrefix": false, 1680 | "colorValue": true, 1681 | "colors": [ 1682 | "#299c46", 1683 | "rgba(237, 129, 40, 0.89)", 1684 | "#d44a3a" 1685 | ], 1686 | "format": "watt", 1687 | "gauge": { 1688 | "maxValue": 100, 1689 | "minValue": 0, 1690 | "show": false, 1691 | "thresholdLabels": false, 1692 | "thresholdMarkers": true 1693 | }, 1694 | "gridPos": { 1695 | "h": 3, 1696 | "w": 4, 1697 | "x": 16, 1698 | "y": 7 1699 | }, 1700 | "id": 12, 1701 | "interval": null, 1702 | "links": [], 1703 | "mappingType": 1, 1704 | "mappingTypes": [ 1705 | { 1706 | "name": "value to text", 1707 | "value": 1 1708 | }, 1709 | { 1710 | "name": "range to text", 1711 | "value": 2 1712 | } 1713 | ], 1714 | "maxDataPoints": 100, 1715 | "nullPointMode": "connected", 1716 | "nullText": null, 1717 | "options": {}, 1718 | "pluginVersion": "6.3.5", 1719 | "postfix": "", 1720 | "postfixFontSize": "50%", 1721 | "prefix": "", 1722 | "prefixFontSize": "50%", 1723 | "rangeMaps": [ 1724 | { 1725 | "from": "null", 1726 | "text": "N/A", 1727 | "to": "null" 1728 | } 1729 | ], 1730 | "sparkline": { 1731 | "fillColor": "rgb(3, 94, 107)", 1732 | "full": false, 1733 | "lineColor": "rgb(31, 120, 193)", 1734 | "show": false, 1735 | "ymax": null, 1736 | "ymin": null 1737 | }, 1738 | "tableColumn": "", 1739 | "targets": [ 1740 | { 1741 | "groupBy": [ 1742 | { 1743 | "params": [ 1744 | "$__interval" 1745 | ], 1746 | "type": "time" 1747 | }, 1748 | { 1749 | "params": [ 1750 | "null" 1751 | ], 1752 | "type": "fill" 1753 | } 1754 | ], 1755 | "measurement": "power", 1756 | "orderByTime": "ASC", 1757 | "policy": "default", 1758 | "refId": "A", 1759 | "resultFormat": "time_series", 1760 | "select": [ 1761 | [ 1762 | { 1763 | "params": [ 1764 | "minPower" 1765 | ], 1766 | "type": "field" 1767 | }, 1768 | { 1769 | "params": [], 1770 | "type": "last" 1771 | } 1772 | ] 1773 | ], 1774 | "tags": [] 1775 | } 1776 | ], 1777 | "thresholds": "5000,10000", 1778 | "timeFrom": null, 1779 | "timeShift": null, 1780 | "title": "Minimum power", 1781 | "type": "singlestat", 1782 | "valueFontSize": "80%", 1783 | "valueMaps": [ 1784 | { 1785 | "op": "=", 1786 | "text": "N/A", 1787 | "value": "null" 1788 | } 1789 | ], 1790 | "valueName": "current" 1791 | }, 1792 | { 1793 | "cacheTimeout": null, 1794 | "colorBackground": false, 1795 | "colorPostfix": false, 1796 | "colorPrefix": true, 1797 | "colorValue": false, 1798 | "colors": [ 1799 | "#299c46", 1800 | "rgba(237, 129, 40, 0.89)", 1801 | "#d44a3a" 1802 | ], 1803 | "decimals": 2, 1804 | "format": "currencyNOK", 1805 | "gauge": { 1806 | "maxValue": 100, 1807 | "minValue": 0, 1808 | "show": false, 1809 | "thresholdLabels": false, 1810 | "thresholdMarkers": true 1811 | }, 1812 | "gridPos": { 1813 | "h": 3, 1814 | "w": 4, 1815 | "x": 20, 1816 | "y": 7 1817 | }, 1818 | "id": 15, 1819 | "interval": null, 1820 | "links": [], 1821 | "mappingType": 1, 1822 | "mappingTypes": [ 1823 | { 1824 | "name": "value to text", 1825 | "value": 1 1826 | }, 1827 | { 1828 | "name": "range to text", 1829 | "value": 2 1830 | } 1831 | ], 1832 | "maxDataPoints": 100, 1833 | "nullPointMode": "connected", 1834 | "nullText": null, 1835 | "options": {}, 1836 | "pluginVersion": "6.3.5", 1837 | "postfix": "", 1838 | "postfixFontSize": "50%", 1839 | "prefix": "", 1840 | "prefixFontSize": "50%", 1841 | "rangeMaps": [ 1842 | { 1843 | "from": "null", 1844 | "text": "N/A", 1845 | "to": "null" 1846 | } 1847 | ], 1848 | "sparkline": { 1849 | "fillColor": "rgba(31, 118, 189, 0.18)", 1850 | "full": false, 1851 | "lineColor": "rgb(31, 120, 193)", 1852 | "show": false, 1853 | "ymax": null, 1854 | "ymin": null 1855 | }, 1856 | "tableColumn": "", 1857 | "targets": [ 1858 | { 1859 | "groupBy": [ 1860 | { 1861 | "params": [ 1862 | "$interval" 1863 | ], 1864 | "type": "time" 1865 | } 1866 | ], 1867 | "measurement": "power", 1868 | "orderByTime": "ASC", 1869 | "policy": "default", 1870 | "refId": "A", 1871 | "resultFormat": "time_series", 1872 | "select": [ 1873 | [ 1874 | { 1875 | "params": [ 1876 | "accumulatedCost" 1877 | ], 1878 | "type": "field" 1879 | }, 1880 | { 1881 | "params": [], 1882 | "type": "last" 1883 | } 1884 | ] 1885 | ], 1886 | "tags": [] 1887 | } 1888 | ], 1889 | "thresholds": "", 1890 | "timeFrom": null, 1891 | "timeShift": null, 1892 | "title": "Net cost today", 1893 | "type": "singlestat", 1894 | "valueFontSize": "80%", 1895 | "valueMaps": [ 1896 | { 1897 | "op": "=", 1898 | "text": "N/A", 1899 | "value": "null" 1900 | } 1901 | ], 1902 | "valueName": "current" 1903 | }, 1904 | { 1905 | "cacheTimeout": null, 1906 | "colorBackground": false, 1907 | "colorPostfix": false, 1908 | "colorPrefix": false, 1909 | "colorValue": true, 1910 | "colors": [ 1911 | "#299c46", 1912 | "rgba(237, 129, 40, 0.89)", 1913 | "#d44a3a" 1914 | ], 1915 | "format": "watt", 1916 | "gauge": { 1917 | "maxValue": 100, 1918 | "minValue": 0, 1919 | "show": false, 1920 | "thresholdLabels": false, 1921 | "thresholdMarkers": true 1922 | }, 1923 | "gridPos": { 1924 | "h": 3, 1925 | "w": 4, 1926 | "x": 16, 1927 | "y": 10 1928 | }, 1929 | "id": 13, 1930 | "interval": null, 1931 | "links": [], 1932 | "mappingType": 1, 1933 | "mappingTypes": [ 1934 | { 1935 | "name": "value to text", 1936 | "value": 1 1937 | }, 1938 | { 1939 | "name": "range to text", 1940 | "value": 2 1941 | } 1942 | ], 1943 | "maxDataPoints": 100, 1944 | "nullPointMode": "connected", 1945 | "nullText": null, 1946 | "options": {}, 1947 | "pluginVersion": "6.3.5", 1948 | "postfix": "", 1949 | "postfixFontSize": "50%", 1950 | "prefix": "", 1951 | "prefixFontSize": "50%", 1952 | "rangeMaps": [ 1953 | { 1954 | "from": "null", 1955 | "text": "N/A", 1956 | "to": "null" 1957 | } 1958 | ], 1959 | "sparkline": { 1960 | "fillColor": "rgb(3, 94, 107)", 1961 | "full": false, 1962 | "lineColor": "rgb(31, 120, 193)", 1963 | "show": false, 1964 | "ymax": null, 1965 | "ymin": null 1966 | }, 1967 | "tableColumn": "", 1968 | "targets": [ 1969 | { 1970 | "groupBy": [ 1971 | { 1972 | "params": [ 1973 | "$__interval" 1974 | ], 1975 | "type": "time" 1976 | }, 1977 | { 1978 | "params": [ 1979 | "null" 1980 | ], 1981 | "type": "fill" 1982 | } 1983 | ], 1984 | "measurement": "power", 1985 | "orderByTime": "ASC", 1986 | "policy": "default", 1987 | "refId": "A", 1988 | "resultFormat": "time_series", 1989 | "select": [ 1990 | [ 1991 | { 1992 | "params": [ 1993 | "maxPower" 1994 | ], 1995 | "type": "field" 1996 | }, 1997 | { 1998 | "params": [], 1999 | "type": "last" 2000 | } 2001 | ] 2002 | ], 2003 | "tags": [] 2004 | } 2005 | ], 2006 | "thresholds": "5000,10000", 2007 | "timeFrom": null, 2008 | "timeShift": null, 2009 | "title": "Maximum power", 2010 | "type": "singlestat", 2011 | "valueFontSize": "80%", 2012 | "valueMaps": [ 2013 | { 2014 | "op": "=", 2015 | "text": "N/A", 2016 | "value": "null" 2017 | } 2018 | ], 2019 | "valueName": "current" 2020 | }, 2021 | { 2022 | "cacheTimeout": null, 2023 | "colorBackground": false, 2024 | "colorPostfix": false, 2025 | "colorPrefix": false, 2026 | "colorValue": false, 2027 | "colors": [ 2028 | "#299c46", 2029 | "rgba(237, 129, 40, 0.89)", 2030 | "#d44a3a" 2031 | ], 2032 | "decimals": 2, 2033 | "format": "currencyNOK", 2034 | "gauge": { 2035 | "maxValue": 100, 2036 | "minValue": 0, 2037 | "show": false, 2038 | "thresholdLabels": false, 2039 | "thresholdMarkers": true 2040 | }, 2041 | "gridPos": { 2042 | "h": 3, 2043 | "w": 4, 2044 | "x": 20, 2045 | "y": 10 2046 | }, 2047 | "id": 18, 2048 | "interval": null, 2049 | "links": [], 2050 | "mappingType": 1, 2051 | "mappingTypes": [ 2052 | { 2053 | "name": "value to text", 2054 | "value": 1 2055 | }, 2056 | { 2057 | "name": "range to text", 2058 | "value": 2 2059 | } 2060 | ], 2061 | "maxDataPoints": 100, 2062 | "nullPointMode": "connected", 2063 | "nullText": null, 2064 | "options": {}, 2065 | "pluginVersion": "6.3.5", 2066 | "postfix": "", 2067 | "postfixFontSize": "50%", 2068 | "prefix": "", 2069 | "prefixFontSize": "50%", 2070 | "rangeMaps": [ 2071 | { 2072 | "from": "null", 2073 | "text": "N/A", 2074 | "to": "null" 2075 | } 2076 | ], 2077 | "sparkline": { 2078 | "fillColor": "rgba(31, 118, 189, 0.18)", 2079 | "full": false, 2080 | "lineColor": "rgb(31, 120, 193)", 2081 | "show": false, 2082 | "ymax": null, 2083 | "ymin": null 2084 | }, 2085 | "tableColumn": "", 2086 | "targets": [ 2087 | { 2088 | "groupBy": [ 2089 | { 2090 | "params": [ 2091 | "$interval" 2092 | ], 2093 | "type": "time" 2094 | } 2095 | ], 2096 | "measurement": "power", 2097 | "orderByTime": "ASC", 2098 | "policy": "default", 2099 | "query": "SELECT last(\"accumulatedCost\") + (last(\"accumulatedConsumption\") * (41.91 / 100)) + ((287.5 / 30.5) / 24) FROM \"power\" WHERE $timeFilter GROUP BY time($interval)", 2100 | "rawQuery": true, 2101 | "refId": "A", 2102 | "resultFormat": "time_series", 2103 | "select": [ 2104 | [ 2105 | { 2106 | "params": [ 2107 | "accumulatedConsumption" 2108 | ], 2109 | "type": "field" 2110 | }, 2111 | { 2112 | "params": [], 2113 | "type": "last" 2114 | }, 2115 | { 2116 | "params": [ 2117 | "+0.4191+9.5" 2118 | ], 2119 | "type": "math" 2120 | } 2121 | ] 2122 | ], 2123 | "tags": [] 2124 | } 2125 | ], 2126 | "thresholds": "", 2127 | "timeFrom": null, 2128 | "timeShift": null, 2129 | "title": "Total cost today", 2130 | "type": "singlestat", 2131 | "valueFontSize": "80%", 2132 | "valueMaps": [ 2133 | { 2134 | "op": "=", 2135 | "text": "N/A", 2136 | "value": "null" 2137 | } 2138 | ], 2139 | "valueName": "current" 2140 | } 2141 | ], 2142 | "refresh": "10s", 2143 | "schemaVersion": 19, 2144 | "style": "dark", 2145 | "tags": [], 2146 | "templating": { 2147 | "list": [] 2148 | }, 2149 | "time": { 2150 | "from": "now-24h", 2151 | "to": "now" 2152 | }, 2153 | "timepicker": { 2154 | "refresh_intervals": [ 2155 | "5s", 2156 | "10s", 2157 | "30s", 2158 | "1m", 2159 | "5m", 2160 | "15m", 2161 | "30m", 2162 | "1h", 2163 | "2h", 2164 | "1d" 2165 | ] 2166 | }, 2167 | "timezone": "", 2168 | "title": "Power", 2169 | "uid": "JdFnx-cZk", 2170 | "version": 33 2171 | } 2172 | ``` 2173 | 2174 |

2175 | 2176 | ## License 2177 | 2178 | [MIT](https://choosealicense.com/licenses/mit/) 2179 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-midnight -------------------------------------------------------------------------------- /examples/current-energy-price.gql: -------------------------------------------------------------------------------- 1 | {viewer{homes{currentSubscription{priceInfo{current{total energy tax startsAt}}}}}} -------------------------------------------------------------------------------- /examples/grafana/home-power-dashboard.json: -------------------------------------------------------------------------------- 1 | { 2 | "annotations": { 3 | "list": [ 4 | { 5 | "builtIn": 1, 6 | "datasource": "-- Grafana --", 7 | "enable": true, 8 | "hide": true, 9 | "iconColor": "rgba(0, 211, 255, 1)", 10 | "name": "Annotations & Alerts", 11 | "type": "dashboard" 12 | } 13 | ] 14 | }, 15 | "editable": true, 16 | "gnetId": null, 17 | "graphTooltip": 0, 18 | "id": 1, 19 | "links": [], 20 | "panels": [ 21 | { 22 | "gridPos": { 23 | "h": 5, 24 | "w": 4, 25 | "x": 0, 26 | "y": 0 27 | }, 28 | "id": 6, 29 | "options": { 30 | "fieldOptions": { 31 | "calcs": [ 32 | "lastNotNull" 33 | ], 34 | "defaults": { 35 | "mappings": [], 36 | "max": 260, 37 | "min": 200, 38 | "thresholds": [ 39 | { 40 | "color": "red", 41 | "value": null 42 | }, 43 | { 44 | "color": "dark-red", 45 | "value": 200 46 | }, 47 | { 48 | "color": "yellow", 49 | "value": 210 50 | }, 51 | { 52 | "color": "green", 53 | "value": 220 54 | }, 55 | { 56 | "color": "green", 57 | "value": 230 58 | }, 59 | { 60 | "color": "#EAB839", 61 | "value": 240 62 | }, 63 | { 64 | "color": "dark-red", 65 | "value": 250 66 | } 67 | ], 68 | "unit": "volt" 69 | }, 70 | "override": {}, 71 | "values": false 72 | }, 73 | "orientation": "auto", 74 | "showThresholdLabels": true, 75 | "showThresholdMarkers": true 76 | }, 77 | "pluginVersion": "6.3.5", 78 | "targets": [ 79 | { 80 | "groupBy": [ 81 | { 82 | "params": [ 83 | "$interval" 84 | ], 85 | "type": "time" 86 | }, 87 | { 88 | "params": [ 89 | "previous" 90 | ], 91 | "type": "fill" 92 | } 93 | ], 94 | "measurement": "power", 95 | "orderByTime": "ASC", 96 | "policy": "default", 97 | "query": "SELECT last(\"voltagePhase1\") FROM \"power\" WHERE $timeFilter", 98 | "rawQuery": false, 99 | "refId": "A", 100 | "resultFormat": "time_series", 101 | "select": [ 102 | [ 103 | { 104 | "params": [ 105 | "voltagePhase1" 106 | ], 107 | "type": "field" 108 | }, 109 | { 110 | "params": [], 111 | "type": "last" 112 | } 113 | ] 114 | ], 115 | "tags": [] 116 | } 117 | ], 118 | "timeFrom": null, 119 | "timeShift": null, 120 | "title": "Voltage - Phase 1", 121 | "type": "gauge" 122 | }, 123 | { 124 | "gridPos": { 125 | "h": 5, 126 | "w": 4, 127 | "x": 4, 128 | "y": 0 129 | }, 130 | "id": 7, 131 | "options": { 132 | "fieldOptions": { 133 | "calcs": [ 134 | "lastNotNull" 135 | ], 136 | "defaults": { 137 | "mappings": [], 138 | "max": 260, 139 | "min": 200, 140 | "thresholds": [ 141 | { 142 | "color": "red", 143 | "value": null 144 | }, 145 | { 146 | "color": "dark-red", 147 | "value": 200 148 | }, 149 | { 150 | "color": "yellow", 151 | "value": 210 152 | }, 153 | { 154 | "color": "green", 155 | "value": 220 156 | }, 157 | { 158 | "color": "green", 159 | "value": 230 160 | }, 161 | { 162 | "color": "#EAB839", 163 | "value": 240 164 | }, 165 | { 166 | "color": "dark-red", 167 | "value": 250 168 | } 169 | ], 170 | "unit": "volt" 171 | }, 172 | "override": {}, 173 | "values": false 174 | }, 175 | "orientation": "auto", 176 | "showThresholdLabels": true, 177 | "showThresholdMarkers": true 178 | }, 179 | "pluginVersion": "6.3.5", 180 | "targets": [ 181 | { 182 | "groupBy": [ 183 | { 184 | "params": [ 185 | "$interval" 186 | ], 187 | "type": "time" 188 | }, 189 | { 190 | "params": [ 191 | "previous" 192 | ], 193 | "type": "fill" 194 | } 195 | ], 196 | "measurement": "power", 197 | "orderByTime": "ASC", 198 | "policy": "default", 199 | "refId": "A", 200 | "resultFormat": "time_series", 201 | "select": [ 202 | [ 203 | { 204 | "params": [ 205 | "voltagePhase2" 206 | ], 207 | "type": "field" 208 | }, 209 | { 210 | "params": [], 211 | "type": "last" 212 | } 213 | ] 214 | ], 215 | "tags": [] 216 | } 217 | ], 218 | "timeFrom": null, 219 | "timeShift": null, 220 | "title": "Voltage - Phase 2", 221 | "type": "gauge" 222 | }, 223 | { 224 | "gridPos": { 225 | "h": 5, 226 | "w": 4, 227 | "x": 8, 228 | "y": 0 229 | }, 230 | "id": 8, 231 | "options": { 232 | "fieldOptions": { 233 | "calcs": [ 234 | "lastNotNull" 235 | ], 236 | "defaults": { 237 | "mappings": [], 238 | "max": 260, 239 | "min": 200, 240 | "thresholds": [ 241 | { 242 | "color": "red", 243 | "value": null 244 | }, 245 | { 246 | "color": "dark-red", 247 | "value": 200 248 | }, 249 | { 250 | "color": "yellow", 251 | "value": 210 252 | }, 253 | { 254 | "color": "green", 255 | "value": 220 256 | }, 257 | { 258 | "color": "green", 259 | "value": 230 260 | }, 261 | { 262 | "color": "#EAB839", 263 | "value": 240 264 | }, 265 | { 266 | "color": "dark-red", 267 | "value": 250 268 | } 269 | ], 270 | "unit": "volt" 271 | }, 272 | "override": {}, 273 | "values": false 274 | }, 275 | "orientation": "auto", 276 | "showThresholdLabels": true, 277 | "showThresholdMarkers": true 278 | }, 279 | "pluginVersion": "6.3.5", 280 | "targets": [ 281 | { 282 | "groupBy": [ 283 | { 284 | "params": [ 285 | "$interval" 286 | ], 287 | "type": "time" 288 | }, 289 | { 290 | "params": [ 291 | "previous" 292 | ], 293 | "type": "fill" 294 | } 295 | ], 296 | "measurement": "power", 297 | "orderByTime": "ASC", 298 | "policy": "default", 299 | "refId": "A", 300 | "resultFormat": "time_series", 301 | "select": [ 302 | [ 303 | { 304 | "params": [ 305 | "voltagePhase3" 306 | ], 307 | "type": "field" 308 | }, 309 | { 310 | "params": [], 311 | "type": "last" 312 | } 313 | ] 314 | ], 315 | "tags": [] 316 | } 317 | ], 318 | "timeFrom": null, 319 | "timeShift": null, 320 | "title": "Voltage - Phase 3", 321 | "type": "gauge" 322 | }, 323 | { 324 | "gridPos": { 325 | "h": 13, 326 | "w": 4, 327 | "x": 12, 328 | "y": 0 329 | }, 330 | "id": 4, 331 | "interval": "", 332 | "options": { 333 | "displayMode": "lcd", 334 | "fieldOptions": { 335 | "calcs": [ 336 | "lastNotNull" 337 | ], 338 | "defaults": { 339 | "decimals": 2, 340 | "mappings": [], 341 | "max": 50, 342 | "min": 0, 343 | "thresholds": [ 344 | { 345 | "color": "green", 346 | "value": null 347 | }, 348 | { 349 | "color": "yellow", 350 | "value": 25 351 | }, 352 | { 353 | "color": "red", 354 | "value": 40 355 | } 356 | ], 357 | "title": "", 358 | "unit": "amp" 359 | }, 360 | "override": {}, 361 | "values": false 362 | }, 363 | "orientation": "vertical" 364 | }, 365 | "pluginVersion": "6.3.5", 366 | "targets": [ 367 | { 368 | "alias": "Phase 1", 369 | "groupBy": [], 370 | "measurement": "power", 371 | "orderByTime": "ASC", 372 | "policy": "default", 373 | "refId": "A", 374 | "resultFormat": "time_series", 375 | "select": [ 376 | [ 377 | { 378 | "params": [ 379 | "currentL1" 380 | ], 381 | "type": "field" 382 | } 383 | ] 384 | ], 385 | "tags": [] 386 | }, 387 | { 388 | "alias": "Phase 2", 389 | "groupBy": [], 390 | "measurement": "power", 391 | "orderByTime": "ASC", 392 | "policy": "default", 393 | "refId": "B", 394 | "resultFormat": "time_series", 395 | "select": [ 396 | [ 397 | { 398 | "params": [ 399 | "currentL2" 400 | ], 401 | "type": "field" 402 | } 403 | ] 404 | ], 405 | "tags": [] 406 | }, 407 | { 408 | "alias": "Phase 3", 409 | "groupBy": [], 410 | "measurement": "power", 411 | "orderByTime": "ASC", 412 | "policy": "default", 413 | "refId": "C", 414 | "resultFormat": "time_series", 415 | "select": [ 416 | [ 417 | { 418 | "params": [ 419 | "currentL3" 420 | ], 421 | "type": "field" 422 | } 423 | ] 424 | ], 425 | "tags": [] 426 | } 427 | ], 428 | "timeFrom": null, 429 | "timeShift": null, 430 | "title": "Phase current", 431 | "type": "bargauge" 432 | }, 433 | { 434 | "cacheTimeout": null, 435 | "colorBackground": false, 436 | "colorPostfix": false, 437 | "colorPrefix": false, 438 | "colorValue": true, 439 | "colors": [ 440 | "#299c46", 441 | "rgba(237, 129, 40, 0.89)", 442 | "#d44a3a" 443 | ], 444 | "format": "watt", 445 | "gauge": { 446 | "maxValue": 100, 447 | "minValue": 0, 448 | "show": false, 449 | "thresholdLabels": false, 450 | "thresholdMarkers": true 451 | }, 452 | "gridPos": { 453 | "h": 4, 454 | "w": 4, 455 | "x": 16, 456 | "y": 0 457 | }, 458 | "id": 10, 459 | "interval": null, 460 | "links": [], 461 | "mappingType": 1, 462 | "mappingTypes": [ 463 | { 464 | "name": "value to text", 465 | "value": 1 466 | }, 467 | { 468 | "name": "range to text", 469 | "value": 2 470 | } 471 | ], 472 | "maxDataPoints": 100, 473 | "nullPointMode": "connected", 474 | "nullText": null, 475 | "options": {}, 476 | "pluginVersion": "6.3.5", 477 | "postfix": "", 478 | "postfixFontSize": "50%", 479 | "prefix": "", 480 | "prefixFontSize": "50%", 481 | "rangeMaps": [ 482 | { 483 | "from": "null", 484 | "text": "N/A", 485 | "to": "null" 486 | } 487 | ], 488 | "sparkline": { 489 | "fillColor": "rgb(3, 94, 107)", 490 | "full": false, 491 | "lineColor": "rgb(31, 120, 193)", 492 | "show": false, 493 | "ymax": null, 494 | "ymin": null 495 | }, 496 | "tableColumn": "", 497 | "targets": [ 498 | { 499 | "groupBy": [ 500 | { 501 | "params": [ 502 | "$__interval" 503 | ], 504 | "type": "time" 505 | }, 506 | { 507 | "params": [ 508 | "null" 509 | ], 510 | "type": "fill" 511 | } 512 | ], 513 | "measurement": "power", 514 | "orderByTime": "ASC", 515 | "policy": "default", 516 | "refId": "A", 517 | "resultFormat": "time_series", 518 | "select": [ 519 | [ 520 | { 521 | "params": [ 522 | "power" 523 | ], 524 | "type": "field" 525 | }, 526 | { 527 | "params": [], 528 | "type": "last" 529 | } 530 | ] 531 | ], 532 | "tags": [] 533 | } 534 | ], 535 | "thresholds": "5000,10000", 536 | "timeFrom": null, 537 | "timeShift": null, 538 | "title": "Current power", 539 | "type": "singlestat", 540 | "valueFontSize": "100%", 541 | "valueMaps": [ 542 | { 543 | "op": "=", 544 | "text": "N/A", 545 | "value": "null" 546 | } 547 | ], 548 | "valueName": "current" 549 | }, 550 | { 551 | "cacheTimeout": null, 552 | "colorBackground": false, 553 | "colorValue": false, 554 | "colors": [ 555 | "#299c46", 556 | "rgba(237, 129, 40, 0.89)", 557 | "#d44a3a" 558 | ], 559 | "decimals": 2, 560 | "format": "kwatth", 561 | "gauge": { 562 | "maxValue": 100, 563 | "minValue": 0, 564 | "show": false, 565 | "thresholdLabels": false, 566 | "thresholdMarkers": true 567 | }, 568 | "gridPos": { 569 | "h": 4, 570 | "w": 4, 571 | "x": 20, 572 | "y": 0 573 | }, 574 | "id": 17, 575 | "interval": null, 576 | "links": [], 577 | "mappingType": 1, 578 | "mappingTypes": [ 579 | { 580 | "name": "value to text", 581 | "value": 1 582 | }, 583 | { 584 | "name": "range to text", 585 | "value": 2 586 | } 587 | ], 588 | "maxDataPoints": 100, 589 | "nullPointMode": "connected", 590 | "nullText": null, 591 | "options": {}, 592 | "postfix": "", 593 | "postfixFontSize": "50%", 594 | "prefix": "", 595 | "prefixFontSize": "50%", 596 | "rangeMaps": [ 597 | { 598 | "from": "null", 599 | "text": "N/A", 600 | "to": "null" 601 | } 602 | ], 603 | "sparkline": { 604 | "fillColor": "rgba(31, 118, 189, 0.18)", 605 | "full": false, 606 | "lineColor": "rgb(31, 120, 193)", 607 | "show": false, 608 | "ymax": null, 609 | "ymin": null 610 | }, 611 | "tableColumn": "", 612 | "targets": [ 613 | { 614 | "groupBy": [ 615 | { 616 | "params": [ 617 | "$__interval" 618 | ], 619 | "type": "time" 620 | }, 621 | { 622 | "params": [ 623 | "null" 624 | ], 625 | "type": "fill" 626 | } 627 | ], 628 | "measurement": "power", 629 | "orderByTime": "ASC", 630 | "policy": "default", 631 | "refId": "A", 632 | "resultFormat": "time_series", 633 | "select": [ 634 | [ 635 | { 636 | "params": [ 637 | "accumulatedConsumption" 638 | ], 639 | "type": "field" 640 | }, 641 | { 642 | "params": [], 643 | "type": "last" 644 | } 645 | ] 646 | ], 647 | "tags": [] 648 | } 649 | ], 650 | "thresholds": "", 651 | "timeFrom": null, 652 | "timeShift": null, 653 | "title": "Consumption today", 654 | "type": "singlestat", 655 | "valueFontSize": "80%", 656 | "valueMaps": [ 657 | { 658 | "op": "=", 659 | "text": "N/A", 660 | "value": "null" 661 | } 662 | ], 663 | "valueName": "current" 664 | }, 665 | { 666 | "cacheTimeout": null, 667 | "colorBackground": false, 668 | "colorPostfix": false, 669 | "colorPrefix": false, 670 | "colorValue": true, 671 | "colors": [ 672 | "#299c46", 673 | "rgba(237, 129, 40, 0.89)", 674 | "#d44a3a" 675 | ], 676 | "format": "watt", 677 | "gauge": { 678 | "maxValue": 100, 679 | "minValue": 0, 680 | "show": false, 681 | "thresholdLabels": false, 682 | "thresholdMarkers": true 683 | }, 684 | "gridPos": { 685 | "h": 3, 686 | "w": 4, 687 | "x": 16, 688 | "y": 4 689 | }, 690 | "id": 11, 691 | "interval": null, 692 | "links": [], 693 | "mappingType": 1, 694 | "mappingTypes": [ 695 | { 696 | "name": "value to text", 697 | "value": 1 698 | }, 699 | { 700 | "name": "range to text", 701 | "value": 2 702 | } 703 | ], 704 | "maxDataPoints": 100, 705 | "nullPointMode": "connected", 706 | "nullText": null, 707 | "options": {}, 708 | "pluginVersion": "6.3.5", 709 | "postfix": "", 710 | "postfixFontSize": "50%", 711 | "prefix": "", 712 | "prefixFontSize": "50%", 713 | "rangeMaps": [ 714 | { 715 | "from": "null", 716 | "text": "N/A", 717 | "to": "null" 718 | } 719 | ], 720 | "sparkline": { 721 | "fillColor": "rgb(3, 94, 107)", 722 | "full": false, 723 | "lineColor": "rgb(31, 120, 193)", 724 | "show": false, 725 | "ymax": null, 726 | "ymin": null 727 | }, 728 | "tableColumn": "", 729 | "targets": [ 730 | { 731 | "groupBy": [ 732 | { 733 | "params": [ 734 | "$__interval" 735 | ], 736 | "type": "time" 737 | }, 738 | { 739 | "params": [ 740 | "null" 741 | ], 742 | "type": "fill" 743 | } 744 | ], 745 | "measurement": "power", 746 | "orderByTime": "ASC", 747 | "policy": "default", 748 | "refId": "A", 749 | "resultFormat": "time_series", 750 | "select": [ 751 | [ 752 | { 753 | "params": [ 754 | "averagePower" 755 | ], 756 | "type": "field" 757 | }, 758 | { 759 | "params": [], 760 | "type": "last" 761 | } 762 | ] 763 | ], 764 | "tags": [] 765 | } 766 | ], 767 | "thresholds": "5000,10000", 768 | "timeFrom": null, 769 | "timeShift": null, 770 | "title": "Average power", 771 | "type": "singlestat", 772 | "valueFontSize": "80%", 773 | "valueMaps": [ 774 | { 775 | "op": "=", 776 | "text": "N/A", 777 | "value": "null" 778 | } 779 | ], 780 | "valueName": "current" 781 | }, 782 | { 783 | "cacheTimeout": null, 784 | "colorBackground": false, 785 | "colorValue": false, 786 | "colors": [ 787 | "#299c46", 788 | "rgba(237, 129, 40, 0.89)", 789 | "#d44a3a" 790 | ], 791 | "decimals": 2, 792 | "format": "currencyNOK", 793 | "gauge": { 794 | "maxValue": 100, 795 | "minValue": 0, 796 | "show": false, 797 | "thresholdLabels": false, 798 | "thresholdMarkers": true 799 | }, 800 | "gridPos": { 801 | "h": 3, 802 | "w": 4, 803 | "x": 20, 804 | "y": 4 805 | }, 806 | "id": 20, 807 | "interval": null, 808 | "links": [], 809 | "mappingType": 1, 810 | "mappingTypes": [ 811 | { 812 | "name": "value to text", 813 | "value": 1 814 | }, 815 | { 816 | "name": "range to text", 817 | "value": 2 818 | } 819 | ], 820 | "maxDataPoints": 100, 821 | "nullPointMode": "connected", 822 | "nullText": null, 823 | "options": {}, 824 | "postfix": "", 825 | "postfixFontSize": "50%", 826 | "prefix": "", 827 | "prefixFontSize": "50%", 828 | "rangeMaps": [ 829 | { 830 | "from": "null", 831 | "text": "N/A", 832 | "to": "null" 833 | } 834 | ], 835 | "sparkline": { 836 | "fillColor": "rgba(31, 118, 189, 0.18)", 837 | "full": false, 838 | "lineColor": "rgb(31, 120, 193)", 839 | "show": false, 840 | "ymax": null, 841 | "ymin": null 842 | }, 843 | "tableColumn": "", 844 | "targets": [ 845 | { 846 | "groupBy": [ 847 | { 848 | "params": [ 849 | "$__interval" 850 | ], 851 | "type": "time" 852 | }, 853 | { 854 | "params": [ 855 | "previous" 856 | ], 857 | "type": "fill" 858 | } 859 | ], 860 | "measurement": "energy", 861 | "orderByTime": "ASC", 862 | "policy": "default", 863 | "query": "SELECT last(\"total\") + (41.91 / 100) + ((287.5 / 30.5) / 24) FROM \"energy\" WHERE $timeFilter GROUP BY time($__interval) fill(previous)\n-- Nettleie: 41.91 øre/KWh\n-- Månedlig fastpris: 287,50", 864 | "rawQuery": true, 865 | "refId": "A", 866 | "resultFormat": "time_series", 867 | "select": [ 868 | [ 869 | { 870 | "params": [ 871 | "total" 872 | ], 873 | "type": "field" 874 | }, 875 | { 876 | "params": [], 877 | "type": "mean" 878 | } 879 | ] 880 | ], 881 | "tags": [] 882 | } 883 | ], 884 | "thresholds": "", 885 | "timeFrom": null, 886 | "timeShift": null, 887 | "title": "Current price / KWh", 888 | "type": "singlestat", 889 | "valueFontSize": "80%", 890 | "valueMaps": [ 891 | { 892 | "op": "=", 893 | "text": "N/A", 894 | "value": "null" 895 | } 896 | ], 897 | "valueName": "current" 898 | }, 899 | { 900 | "aliasColors": {}, 901 | "bars": false, 902 | "dashLength": 10, 903 | "dashes": false, 904 | "decimals": 2, 905 | "description": "", 906 | "fill": 1, 907 | "fillGradient": 4, 908 | "gridPos": { 909 | "h": 8, 910 | "w": 12, 911 | "x": 0, 912 | "y": 5 913 | }, 914 | "id": 2, 915 | "interval": "", 916 | "legend": { 917 | "alignAsTable": false, 918 | "avg": false, 919 | "current": true, 920 | "hideEmpty": false, 921 | "hideZero": false, 922 | "max": false, 923 | "min": false, 924 | "rightSide": false, 925 | "show": true, 926 | "total": false, 927 | "values": true 928 | }, 929 | "lines": true, 930 | "linewidth": 1, 931 | "nullPointMode": "connected", 932 | "options": { 933 | "dataLinks": [] 934 | }, 935 | "percentage": false, 936 | "pointradius": 2, 937 | "points": false, 938 | "renderer": "flot", 939 | "seriesOverrides": [ 940 | { 941 | "alias": "Power", 942 | "yaxis": 2 943 | }, 944 | { 945 | "alias": "Price", 946 | "yaxis": 1 947 | } 948 | ], 949 | "spaceLength": 10, 950 | "stack": false, 951 | "steppedLine": false, 952 | "targets": [ 953 | { 954 | "alias": "Power", 955 | "groupBy": [ 956 | { 957 | "params": [ 958 | "$__interval" 959 | ], 960 | "type": "time" 961 | }, 962 | { 963 | "params": [ 964 | "linear" 965 | ], 966 | "type": "fill" 967 | } 968 | ], 969 | "hide": false, 970 | "measurement": "power", 971 | "orderByTime": "ASC", 972 | "policy": "default", 973 | "refId": "A", 974 | "resultFormat": "time_series", 975 | "select": [ 976 | [ 977 | { 978 | "params": [ 979 | "power" 980 | ], 981 | "type": "field" 982 | }, 983 | { 984 | "params": [], 985 | "type": "last" 986 | } 987 | ] 988 | ], 989 | "tags": [] 990 | }, 991 | { 992 | "alias": "Price", 993 | "groupBy": [ 994 | { 995 | "params": [ 996 | "$__interval" 997 | ], 998 | "type": "time" 999 | }, 1000 | { 1001 | "params": [ 1002 | "previous" 1003 | ], 1004 | "type": "fill" 1005 | } 1006 | ], 1007 | "measurement": "energy", 1008 | "orderByTime": "ASC", 1009 | "policy": "default", 1010 | "refId": "B", 1011 | "resultFormat": "time_series", 1012 | "select": [ 1013 | [ 1014 | { 1015 | "params": [ 1016 | "total" 1017 | ], 1018 | "type": "field" 1019 | }, 1020 | { 1021 | "params": [], 1022 | "type": "mean" 1023 | } 1024 | ] 1025 | ], 1026 | "tags": [] 1027 | } 1028 | ], 1029 | "thresholds": [], 1030 | "timeFrom": null, 1031 | "timeRegions": [], 1032 | "timeShift": null, 1033 | "title": "Power consumprion", 1034 | "tooltip": { 1035 | "shared": true, 1036 | "sort": 0, 1037 | "value_type": "individual" 1038 | }, 1039 | "type": "graph", 1040 | "xaxis": { 1041 | "buckets": null, 1042 | "mode": "time", 1043 | "name": null, 1044 | "show": true, 1045 | "values": [] 1046 | }, 1047 | "yaxes": [ 1048 | { 1049 | "format": "currencyNOK", 1050 | "label": "Price", 1051 | "logBase": 1, 1052 | "max": null, 1053 | "min": null, 1054 | "show": true 1055 | }, 1056 | { 1057 | "decimals": null, 1058 | "format": "watt", 1059 | "label": "Energy", 1060 | "logBase": 1, 1061 | "max": null, 1062 | "min": null, 1063 | "show": true 1064 | } 1065 | ], 1066 | "yaxis": { 1067 | "align": false, 1068 | "alignLevel": null 1069 | } 1070 | }, 1071 | { 1072 | "cacheTimeout": null, 1073 | "colorBackground": false, 1074 | "colorPostfix": false, 1075 | "colorPrefix": false, 1076 | "colorValue": true, 1077 | "colors": [ 1078 | "#299c46", 1079 | "rgba(237, 129, 40, 0.89)", 1080 | "#d44a3a" 1081 | ], 1082 | "format": "watt", 1083 | "gauge": { 1084 | "maxValue": 100, 1085 | "minValue": 0, 1086 | "show": false, 1087 | "thresholdLabels": false, 1088 | "thresholdMarkers": true 1089 | }, 1090 | "gridPos": { 1091 | "h": 3, 1092 | "w": 4, 1093 | "x": 16, 1094 | "y": 7 1095 | }, 1096 | "id": 12, 1097 | "interval": null, 1098 | "links": [], 1099 | "mappingType": 1, 1100 | "mappingTypes": [ 1101 | { 1102 | "name": "value to text", 1103 | "value": 1 1104 | }, 1105 | { 1106 | "name": "range to text", 1107 | "value": 2 1108 | } 1109 | ], 1110 | "maxDataPoints": 100, 1111 | "nullPointMode": "connected", 1112 | "nullText": null, 1113 | "options": {}, 1114 | "pluginVersion": "6.3.5", 1115 | "postfix": "", 1116 | "postfixFontSize": "50%", 1117 | "prefix": "", 1118 | "prefixFontSize": "50%", 1119 | "rangeMaps": [ 1120 | { 1121 | "from": "null", 1122 | "text": "N/A", 1123 | "to": "null" 1124 | } 1125 | ], 1126 | "sparkline": { 1127 | "fillColor": "rgb(3, 94, 107)", 1128 | "full": false, 1129 | "lineColor": "rgb(31, 120, 193)", 1130 | "show": false, 1131 | "ymax": null, 1132 | "ymin": null 1133 | }, 1134 | "tableColumn": "", 1135 | "targets": [ 1136 | { 1137 | "groupBy": [ 1138 | { 1139 | "params": [ 1140 | "$__interval" 1141 | ], 1142 | "type": "time" 1143 | }, 1144 | { 1145 | "params": [ 1146 | "null" 1147 | ], 1148 | "type": "fill" 1149 | } 1150 | ], 1151 | "measurement": "power", 1152 | "orderByTime": "ASC", 1153 | "policy": "default", 1154 | "refId": "A", 1155 | "resultFormat": "time_series", 1156 | "select": [ 1157 | [ 1158 | { 1159 | "params": [ 1160 | "minPower" 1161 | ], 1162 | "type": "field" 1163 | }, 1164 | { 1165 | "params": [], 1166 | "type": "last" 1167 | } 1168 | ] 1169 | ], 1170 | "tags": [] 1171 | } 1172 | ], 1173 | "thresholds": "5000,10000", 1174 | "timeFrom": null, 1175 | "timeShift": null, 1176 | "title": "Minimum power", 1177 | "type": "singlestat", 1178 | "valueFontSize": "80%", 1179 | "valueMaps": [ 1180 | { 1181 | "op": "=", 1182 | "text": "N/A", 1183 | "value": "null" 1184 | } 1185 | ], 1186 | "valueName": "current" 1187 | }, 1188 | { 1189 | "cacheTimeout": null, 1190 | "colorBackground": false, 1191 | "colorPostfix": false, 1192 | "colorPrefix": true, 1193 | "colorValue": false, 1194 | "colors": [ 1195 | "#299c46", 1196 | "rgba(237, 129, 40, 0.89)", 1197 | "#d44a3a" 1198 | ], 1199 | "decimals": 2, 1200 | "format": "currencyNOK", 1201 | "gauge": { 1202 | "maxValue": 100, 1203 | "minValue": 0, 1204 | "show": false, 1205 | "thresholdLabels": false, 1206 | "thresholdMarkers": true 1207 | }, 1208 | "gridPos": { 1209 | "h": 3, 1210 | "w": 4, 1211 | "x": 20, 1212 | "y": 7 1213 | }, 1214 | "id": 15, 1215 | "interval": null, 1216 | "links": [], 1217 | "mappingType": 1, 1218 | "mappingTypes": [ 1219 | { 1220 | "name": "value to text", 1221 | "value": 1 1222 | }, 1223 | { 1224 | "name": "range to text", 1225 | "value": 2 1226 | } 1227 | ], 1228 | "maxDataPoints": 100, 1229 | "nullPointMode": "connected", 1230 | "nullText": null, 1231 | "options": {}, 1232 | "pluginVersion": "6.3.5", 1233 | "postfix": "", 1234 | "postfixFontSize": "50%", 1235 | "prefix": "", 1236 | "prefixFontSize": "50%", 1237 | "rangeMaps": [ 1238 | { 1239 | "from": "null", 1240 | "text": "N/A", 1241 | "to": "null" 1242 | } 1243 | ], 1244 | "sparkline": { 1245 | "fillColor": "rgba(31, 118, 189, 0.18)", 1246 | "full": false, 1247 | "lineColor": "rgb(31, 120, 193)", 1248 | "show": false, 1249 | "ymax": null, 1250 | "ymin": null 1251 | }, 1252 | "tableColumn": "", 1253 | "targets": [ 1254 | { 1255 | "groupBy": [ 1256 | { 1257 | "params": [ 1258 | "$interval" 1259 | ], 1260 | "type": "time" 1261 | } 1262 | ], 1263 | "measurement": "power", 1264 | "orderByTime": "ASC", 1265 | "policy": "default", 1266 | "refId": "A", 1267 | "resultFormat": "time_series", 1268 | "select": [ 1269 | [ 1270 | { 1271 | "params": [ 1272 | "accumulatedCost" 1273 | ], 1274 | "type": "field" 1275 | }, 1276 | { 1277 | "params": [], 1278 | "type": "last" 1279 | } 1280 | ] 1281 | ], 1282 | "tags": [] 1283 | } 1284 | ], 1285 | "thresholds": "", 1286 | "timeFrom": null, 1287 | "timeShift": null, 1288 | "title": "Net cost today", 1289 | "type": "singlestat", 1290 | "valueFontSize": "80%", 1291 | "valueMaps": [ 1292 | { 1293 | "op": "=", 1294 | "text": "N/A", 1295 | "value": "null" 1296 | } 1297 | ], 1298 | "valueName": "current" 1299 | }, 1300 | { 1301 | "cacheTimeout": null, 1302 | "colorBackground": false, 1303 | "colorPostfix": false, 1304 | "colorPrefix": false, 1305 | "colorValue": true, 1306 | "colors": [ 1307 | "#299c46", 1308 | "rgba(237, 129, 40, 0.89)", 1309 | "#d44a3a" 1310 | ], 1311 | "format": "watt", 1312 | "gauge": { 1313 | "maxValue": 100, 1314 | "minValue": 0, 1315 | "show": false, 1316 | "thresholdLabels": false, 1317 | "thresholdMarkers": true 1318 | }, 1319 | "gridPos": { 1320 | "h": 3, 1321 | "w": 4, 1322 | "x": 16, 1323 | "y": 10 1324 | }, 1325 | "id": 13, 1326 | "interval": null, 1327 | "links": [], 1328 | "mappingType": 1, 1329 | "mappingTypes": [ 1330 | { 1331 | "name": "value to text", 1332 | "value": 1 1333 | }, 1334 | { 1335 | "name": "range to text", 1336 | "value": 2 1337 | } 1338 | ], 1339 | "maxDataPoints": 100, 1340 | "nullPointMode": "connected", 1341 | "nullText": null, 1342 | "options": {}, 1343 | "pluginVersion": "6.3.5", 1344 | "postfix": "", 1345 | "postfixFontSize": "50%", 1346 | "prefix": "", 1347 | "prefixFontSize": "50%", 1348 | "rangeMaps": [ 1349 | { 1350 | "from": "null", 1351 | "text": "N/A", 1352 | "to": "null" 1353 | } 1354 | ], 1355 | "sparkline": { 1356 | "fillColor": "rgb(3, 94, 107)", 1357 | "full": false, 1358 | "lineColor": "rgb(31, 120, 193)", 1359 | "show": false, 1360 | "ymax": null, 1361 | "ymin": null 1362 | }, 1363 | "tableColumn": "", 1364 | "targets": [ 1365 | { 1366 | "groupBy": [ 1367 | { 1368 | "params": [ 1369 | "$__interval" 1370 | ], 1371 | "type": "time" 1372 | }, 1373 | { 1374 | "params": [ 1375 | "null" 1376 | ], 1377 | "type": "fill" 1378 | } 1379 | ], 1380 | "measurement": "power", 1381 | "orderByTime": "ASC", 1382 | "policy": "default", 1383 | "refId": "A", 1384 | "resultFormat": "time_series", 1385 | "select": [ 1386 | [ 1387 | { 1388 | "params": [ 1389 | "maxPower" 1390 | ], 1391 | "type": "field" 1392 | }, 1393 | { 1394 | "params": [], 1395 | "type": "last" 1396 | } 1397 | ] 1398 | ], 1399 | "tags": [] 1400 | } 1401 | ], 1402 | "thresholds": "5000,10000", 1403 | "timeFrom": null, 1404 | "timeShift": null, 1405 | "title": "Maximum power", 1406 | "type": "singlestat", 1407 | "valueFontSize": "80%", 1408 | "valueMaps": [ 1409 | { 1410 | "op": "=", 1411 | "text": "N/A", 1412 | "value": "null" 1413 | } 1414 | ], 1415 | "valueName": "current" 1416 | }, 1417 | { 1418 | "cacheTimeout": null, 1419 | "colorBackground": false, 1420 | "colorPostfix": false, 1421 | "colorPrefix": false, 1422 | "colorValue": false, 1423 | "colors": [ 1424 | "#299c46", 1425 | "rgba(237, 129, 40, 0.89)", 1426 | "#d44a3a" 1427 | ], 1428 | "decimals": 2, 1429 | "format": "currencyNOK", 1430 | "gauge": { 1431 | "maxValue": 100, 1432 | "minValue": 0, 1433 | "show": false, 1434 | "thresholdLabels": false, 1435 | "thresholdMarkers": true 1436 | }, 1437 | "gridPos": { 1438 | "h": 3, 1439 | "w": 4, 1440 | "x": 20, 1441 | "y": 10 1442 | }, 1443 | "id": 18, 1444 | "interval": null, 1445 | "links": [], 1446 | "mappingType": 1, 1447 | "mappingTypes": [ 1448 | { 1449 | "name": "value to text", 1450 | "value": 1 1451 | }, 1452 | { 1453 | "name": "range to text", 1454 | "value": 2 1455 | } 1456 | ], 1457 | "maxDataPoints": 100, 1458 | "nullPointMode": "connected", 1459 | "nullText": null, 1460 | "options": {}, 1461 | "pluginVersion": "6.3.5", 1462 | "postfix": "", 1463 | "postfixFontSize": "50%", 1464 | "prefix": "", 1465 | "prefixFontSize": "50%", 1466 | "rangeMaps": [ 1467 | { 1468 | "from": "null", 1469 | "text": "N/A", 1470 | "to": "null" 1471 | } 1472 | ], 1473 | "sparkline": { 1474 | "fillColor": "rgba(31, 118, 189, 0.18)", 1475 | "full": false, 1476 | "lineColor": "rgb(31, 120, 193)", 1477 | "show": false, 1478 | "ymax": null, 1479 | "ymin": null 1480 | }, 1481 | "tableColumn": "", 1482 | "targets": [ 1483 | { 1484 | "groupBy": [ 1485 | { 1486 | "params": [ 1487 | "$interval" 1488 | ], 1489 | "type": "time" 1490 | } 1491 | ], 1492 | "measurement": "power", 1493 | "orderByTime": "ASC", 1494 | "policy": "default", 1495 | "query": "SELECT last(\"accumulatedCost\") + (last(\"accumulatedConsumption\") * (41.91 / 100)) + ((287.5 / 30.5) / 24) FROM \"power\" WHERE $timeFilter GROUP BY time($interval)", 1496 | "rawQuery": true, 1497 | "refId": "A", 1498 | "resultFormat": "time_series", 1499 | "select": [ 1500 | [ 1501 | { 1502 | "params": [ 1503 | "accumulatedConsumption" 1504 | ], 1505 | "type": "field" 1506 | }, 1507 | { 1508 | "params": [], 1509 | "type": "last" 1510 | }, 1511 | { 1512 | "params": [ 1513 | "+0.4191+9.5" 1514 | ], 1515 | "type": "math" 1516 | } 1517 | ] 1518 | ], 1519 | "tags": [] 1520 | } 1521 | ], 1522 | "thresholds": "", 1523 | "timeFrom": null, 1524 | "timeShift": null, 1525 | "title": "Total cost today", 1526 | "type": "singlestat", 1527 | "valueFontSize": "80%", 1528 | "valueMaps": [ 1529 | { 1530 | "op": "=", 1531 | "text": "N/A", 1532 | "value": "null" 1533 | } 1534 | ], 1535 | "valueName": "current" 1536 | } 1537 | ], 1538 | "refresh": "10s", 1539 | "schemaVersion": 19, 1540 | "style": "dark", 1541 | "tags": [], 1542 | "templating": { 1543 | "list": [] 1544 | }, 1545 | "time": { 1546 | "from": "now-24h", 1547 | "to": "now" 1548 | }, 1549 | "timepicker": { 1550 | "refresh_intervals": [ 1551 | "5s", 1552 | "10s", 1553 | "30s", 1554 | "1m", 1555 | "5m", 1556 | "15m", 1557 | "30m", 1558 | "1h", 1559 | "2h", 1560 | "1d" 1561 | ] 1562 | }, 1563 | "timezone": "", 1564 | "title": "Power", 1565 | "uid": "JdFnx-cZk", 1566 | "version": 33 1567 | } -------------------------------------------------------------------------------- /examples/homes.gql: -------------------------------------------------------------------------------- 1 | {viewer{homes{id size appNickname appAvatar address{address1 address2 address3 postalCode city country latitude longitude}}}} -------------------------------------------------------------------------------- /examples/images/tibber-api-endpoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bisand/node-red-contrib-tibber-api/b7bf25fe2fc1947d22ace2241119de30843e81ce/examples/images/tibber-api-endpoint.png -------------------------------------------------------------------------------- /examples/images/tibber-feed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bisand/node-red-contrib-tibber-api/b7bf25fe2fc1947d22ace2241119de30843e81ce/examples/images/tibber-feed.png -------------------------------------------------------------------------------- /examples/images/tibber-notify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bisand/node-red-contrib-tibber-api/b7bf25fe2fc1947d22ace2241119de30843e81ce/examples/images/tibber-notify.png -------------------------------------------------------------------------------- /examples/images/tibber-query.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bisand/node-red-contrib-tibber-api/b7bf25fe2fc1947d22ace2241119de30843e81ce/examples/images/tibber-query.png -------------------------------------------------------------------------------- /examples/node-red-home-power.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "683fd7.e63da028", 4 | "type": "tab", 5 | "label": "Home Energy", 6 | "disabled": false, 7 | "info": "" 8 | }, 9 | { 10 | "id": "b970f3b0.3ff74", 11 | "type": "tibber-feed", 12 | "z": "683fd7.e63da028", 13 | "name": "", 14 | "active": true, 15 | "apiEndpointRef": "d4450078.a5f12", 16 | "homeId": "96a14971-525a-4420-aae9-e5aedaa129ff", 17 | "timestamp": "1", 18 | "power": "1", 19 | "lastMeterConsumption": "1", 20 | "accumulatedConsumption": "1", 21 | "accumulatedProduction": "1", 22 | "accumulatedConsumptionLastHour": true, 23 | "accumulatedProductionLastHour": true, 24 | "accumulatedCost": "1", 25 | "accumulatedReward": "1", 26 | "currency": "1", 27 | "minPower": "1", 28 | "averagePower": "1", 29 | "maxPower": "1", 30 | "powerProduction": "1", 31 | "minPowerProduction": "1", 32 | "maxPowerProduction": "1", 33 | "lastMeterProduction": "1", 34 | "powerFactor": "1", 35 | "voltagePhase1": "1", 36 | "voltagePhase2": "1", 37 | "voltagePhase3": "1", 38 | "currentL1": "1", 39 | "currentL2": "1", 40 | "currentL3": "1", 41 | "signalStrength": true, 42 | "x": 140, 43 | "y": 300, 44 | "wires": [ 45 | [ 46 | "1491f46.f317b0c" 47 | ] 48 | ] 49 | }, 50 | { 51 | "id": "4d0b020a.94fbac", 52 | "type": "debug", 53 | "z": "683fd7.e63da028", 54 | "name": "", 55 | "active": false, 56 | "tosidebar": true, 57 | "console": false, 58 | "tostatus": false, 59 | "complete": "false", 60 | "x": 590, 61 | "y": 360, 62 | "wires": [] 63 | }, 64 | { 65 | "id": "2773a5f1.d99aca", 66 | "type": "tibber-query", 67 | "z": "683fd7.e63da028", 68 | "name": "", 69 | "active": true, 70 | "apiEndpointRef": "d4450078.a5f12", 71 | "x": 370, 72 | "y": 100, 73 | "wires": [ 74 | [ 75 | "4a25248d.5e506c" 76 | ] 77 | ] 78 | }, 79 | { 80 | "id": "983cd36.d80383", 81 | "type": "inject", 82 | "z": "683fd7.e63da028", 83 | "name": "Get Home Id", 84 | "props": [ 85 | { 86 | "p": "payload", 87 | "v": "{ viewer { homes { id address { address1 address2 address3 postalCode city country latitude longitude } } } }", 88 | "vt": "str" 89 | }, 90 | { 91 | "p": "topic", 92 | "v": "", 93 | "vt": "str" 94 | } 95 | ], 96 | "repeat": "", 97 | "crontab": "", 98 | "once": false, 99 | "onceDelay": 0.1, 100 | "topic": "", 101 | "payload": "{ viewer { homes { id address { address1 address2 address3 postalCode city country latitude longitude } } } }", 102 | "payloadType": "str", 103 | "x": 150, 104 | "y": 100, 105 | "wires": [ 106 | [ 107 | "2773a5f1.d99aca" 108 | ] 109 | ] 110 | }, 111 | { 112 | "id": "4a25248d.5e506c", 113 | "type": "debug", 114 | "z": "683fd7.e63da028", 115 | "name": "", 116 | "active": true, 117 | "tosidebar": true, 118 | "console": false, 119 | "tostatus": false, 120 | "complete": "false", 121 | "x": 550, 122 | "y": 100, 123 | "wires": [] 124 | }, 125 | { 126 | "id": "e0404127.1a2f8", 127 | "type": "http request", 128 | "z": "683fd7.e63da028", 129 | "name": "", 130 | "method": "POST", 131 | "ret": "txt", 132 | "paytoqs": false, 133 | "url": "http://influxdb:8086/write?precision=s&consistency=any&db=test", 134 | "tls": "", 135 | "proxy": "", 136 | "authType": "", 137 | "x": 590, 138 | "y": 300, 139 | "wires": [ 140 | [ 141 | "4d0b020a.94fbac" 142 | ] 143 | ] 144 | }, 145 | { 146 | "id": "1491f46.f317b0c", 147 | "type": "function", 148 | "z": "683fd7.e63da028", 149 | "name": "Transform payload", 150 | "func": "let p = msg.payload;\n\nif (!p.voltagePhase1)\n return null;\n\nfor (var prop in p) {\n if (!p[prop])\n p[prop] = 0;\n}\n\n// Meassurement\nlet data = \"power\";\n\n// Tag set\ndata += \",location=test\";\ndata += \",currency=\" + p.currency;\n\n// Field set\ndata += \" power=\" + p.power;\ndata += \",lastMeterConsumption=\" + p.lastMeterConsumption;\ndata += \",accumulatedConsumption=\" + p.accumulatedConsumption;\ndata += \",accumulatedProduction=\" + p.accumulatedProduction;\ndata += \",accumulatedCost=\" + p.accumulatedCost;\ndata += \",accumulatedReward=\" + p.accumulatedReward;\ndata += \",minPower=\" + p.minPower;\ndata += \",averagePower=\" + p.averagePower;\ndata += \",maxPower=\" + p.maxPower;\ndata += \",powerProduction=\" + p.powerProduction;\ndata += \",minPowerProduction=\" + p.minPowerProduction;\ndata += \",maxPowerProduction=\" + p.maxPowerProduction;\ndata += \",lastMeterProduction=\" + p.lastMeterProduction;\ndata += \",powerFactor=\" + p.powerFactor;\ndata += \",voltagePhase1=\" + p.voltagePhase1;\ndata += \",voltagePhase2=\" + p.voltagePhase2;\ndata += \",voltagePhase3=\" + p.voltagePhase3;\ndata += \",currentL1=\" + p.currentL1;\ndata += \",currentL2=\" + p.currentL2;\ndata += \",currentL3=\" + p.currentL3;\n\nmsg.payload = data;\n\nreturn msg;\n", 151 | "outputs": 1, 152 | "noerr": 0, 153 | "x": 390, 154 | "y": 300, 155 | "wires": [ 156 | [ 157 | "e0404127.1a2f8" 158 | ] 159 | ] 160 | }, 161 | { 162 | "id": "4286466c.a02e08", 163 | "type": "http request", 164 | "z": "683fd7.e63da028", 165 | "name": "", 166 | "method": "POST", 167 | "ret": "txt", 168 | "paytoqs": false, 169 | "url": "http://influxdb:8086/query?q=CREATE%20DATABASE%20%22test%22", 170 | "tls": "", 171 | "proxy": "", 172 | "authType": "", 173 | "x": 370, 174 | "y": 40, 175 | "wires": [ 176 | [ 177 | "d102d972.8fb0c8" 178 | ] 179 | ] 180 | }, 181 | { 182 | "id": "b24ffef4.c3ca", 183 | "type": "inject", 184 | "z": "683fd7.e63da028", 185 | "name": "Create test database", 186 | "repeat": "", 187 | "crontab": "", 188 | "once": false, 189 | "onceDelay": 0.1, 190 | "topic": "", 191 | "payload": "", 192 | "payloadType": "str", 193 | "x": 170, 194 | "y": 40, 195 | "wires": [ 196 | [ 197 | "4286466c.a02e08" 198 | ] 199 | ] 200 | }, 201 | { 202 | "id": "d102d972.8fb0c8", 203 | "type": "debug", 204 | "z": "683fd7.e63da028", 205 | "name": "", 206 | "active": true, 207 | "tosidebar": true, 208 | "console": false, 209 | "tostatus": false, 210 | "complete": "false", 211 | "x": 550, 212 | "y": 40, 213 | "wires": [] 214 | }, 215 | { 216 | "id": "165b29ab.c7bef6", 217 | "type": "tibber-query", 218 | "z": "683fd7.e63da028", 219 | "name": "", 220 | "active": true, 221 | "apiEndpointRef": "d4450078.a5f12", 222 | "x": 370, 223 | "y": 180, 224 | "wires": [ 225 | [ 226 | "9f49c320.526db" 227 | ] 228 | ] 229 | }, 230 | { 231 | "id": "425b3d0d.8f10d4", 232 | "type": "inject", 233 | "z": "683fd7.e63da028", 234 | "name": "Daily energy prices", 235 | "props": [ 236 | { 237 | "p": "payload", 238 | "v": "{ viewer { homes { currentSubscription { priceInfo { today { total energy tax startsAt currency level } } } } } }", 239 | "vt": "str" 240 | }, 241 | { 242 | "p": "topic", 243 | "v": "", 244 | "vt": "str" 245 | } 246 | ], 247 | "repeat": "", 248 | "crontab": "30 00 * * *", 249 | "once": false, 250 | "onceDelay": 0.1, 251 | "topic": "", 252 | "payload": "{ viewer { homes { currentSubscription { priceInfo { today { total energy tax startsAt currency level } } } } } }", 253 | "payloadType": "str", 254 | "x": 180, 255 | "y": 180, 256 | "wires": [ 257 | [ 258 | "165b29ab.c7bef6" 259 | ] 260 | ] 261 | }, 262 | { 263 | "id": "810b8faa.9656a", 264 | "type": "debug", 265 | "z": "683fd7.e63da028", 266 | "name": "", 267 | "active": true, 268 | "tosidebar": true, 269 | "console": false, 270 | "tostatus": false, 271 | "complete": "payload", 272 | "targetType": "msg", 273 | "x": 550, 274 | "y": 240, 275 | "wires": [] 276 | }, 277 | { 278 | "id": "9f49c320.526db", 279 | "type": "function", 280 | "z": "683fd7.e63da028", 281 | "name": "Transform energy price", 282 | "func": "let pl = msg.payload;\n\nlet prices = pl.viewer.homes[0].currentSubscription.priceInfo.today;\n\n// Meassurement\nlet data = \"\";\n\nfor(let i = 0; i < prices.length; i++)\n{\n let p = prices[i];\n data += \"energy\";\n\n // Tag set\n data += \",location=test\";\n data += \",currency=\" + p.currency;\n \n // Field set\n data += \" total=\" + p.total;\n data += \",energy=\" + p.energy;\n data += \",tax=\" + p.tax;\n data += \",level=\\\"\" + p.level + \"\\\"\";\n data += \" \" + new Date(p.startsAt).getTime() / 1000 + \"\";\n data += \"\\n\";\n}\n\nmsg.payload = data;\n\nreturn msg;", 283 | "outputs": 1, 284 | "noerr": 0, 285 | "x": 590, 286 | "y": 180, 287 | "wires": [ 288 | [ 289 | "c478abbd.5715e8" 290 | ] 291 | ] 292 | }, 293 | { 294 | "id": "c478abbd.5715e8", 295 | "type": "http request", 296 | "z": "683fd7.e63da028", 297 | "name": "", 298 | "method": "POST", 299 | "ret": "txt", 300 | "paytoqs": false, 301 | "url": "http://influxdb:8086/write?precision=s&consistency=any&db=test", 302 | "tls": "", 303 | "proxy": "", 304 | "authType": "", 305 | "x": 370, 306 | "y": 240, 307 | "wires": [ 308 | [ 309 | "810b8faa.9656a" 310 | ] 311 | ] 312 | }, 313 | { 314 | "id": "d4450078.a5f12", 315 | "type": "tibber-api-endpoint", 316 | "queryUrl": "https://api.tibber.com/v1-beta/gql", 317 | "feedConnectionTimeout": "30", 318 | "feedTimeout": "60", 319 | "queryRequestTimeout": "30", 320 | "name": "Demo" 321 | } 322 | ] -------------------------------------------------------------------------------- /examples/node-red-tibber-test-flow.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "15652aa.fd5c4d5", 4 | "type": "tab", 5 | "label": "Tibber Test Flow", 6 | "disabled": false, 7 | "info": "" 8 | }, 9 | { 10 | "id": "3a621e1.6c980e2", 11 | "type": "inject", 12 | "z": "15652aa.fd5c4d5", 13 | "name": "", 14 | "props": [ 15 | { 16 | "p": "payload", 17 | "v": "{viewer{homes{id size appNickname appAvatar address{address1 address2 address3 postalCode city country latitude longitude}}}}", 18 | "vt": "str" 19 | }, 20 | { 21 | "p": "topic", 22 | "v": "", 23 | "vt": "str" 24 | } 25 | ], 26 | "repeat": "", 27 | "crontab": "", 28 | "once": false, 29 | "onceDelay": 0.1, 30 | "topic": "", 31 | "payload": "{viewer{homes{id size appNickname appAvatar address{address1 address2 address3 postalCode city country latitude longitude}}}}", 32 | "payloadType": "str", 33 | "x": 130, 34 | "y": 80, 35 | "wires": [ 36 | [ 37 | "4d90c0d9.a283f" 38 | ] 39 | ] 40 | }, 41 | { 42 | "id": "d98c9051.ec2cb", 43 | "type": "debug", 44 | "z": "15652aa.fd5c4d5", 45 | "name": "", 46 | "active": true, 47 | "tosidebar": true, 48 | "console": false, 49 | "tostatus": false, 50 | "complete": "false", 51 | "x": 570, 52 | "y": 80, 53 | "wires": [] 54 | }, 55 | { 56 | "id": "1f5b698b.c40ec6", 57 | "type": "tibber-feed", 58 | "z": "15652aa.fd5c4d5", 59 | "name": "", 60 | "active": true, 61 | "apiEndpointRef": "d4450078.a5f12", 62 | "homeId": "96a14971-525a-4420-aae9-e5aedaa129ff", 63 | "timestamp": "1", 64 | "power": "1", 65 | "lastMeterConsumption": "1", 66 | "accumulatedConsumption": "1", 67 | "accumulatedProduction": "1", 68 | "accumulatedConsumptionLastHour": true, 69 | "accumulatedProductionLastHour": true, 70 | "accumulatedCost": "1", 71 | "accumulatedReward": "1", 72 | "currency": "1", 73 | "minPower": "1", 74 | "averagePower": "1", 75 | "maxPower": "1", 76 | "powerProduction": "1", 77 | "minPowerProduction": "1", 78 | "maxPowerProduction": "1", 79 | "lastMeterProduction": "1", 80 | "powerFactor": "1", 81 | "voltagePhase1": "1", 82 | "voltagePhase2": "1", 83 | "voltagePhase3": "1", 84 | "currentL1": "1", 85 | "currentL2": "1", 86 | "currentL3": "1", 87 | "signalStrength": true, 88 | "x": 120, 89 | "y": 180, 90 | "wires": [ 91 | [ 92 | "3eb3b3f1.899ecc" 93 | ] 94 | ] 95 | }, 96 | { 97 | "id": "3eb3b3f1.899ecc", 98 | "type": "debug", 99 | "z": "15652aa.fd5c4d5", 100 | "name": "", 101 | "active": false, 102 | "tosidebar": true, 103 | "console": false, 104 | "tostatus": false, 105 | "complete": "false", 106 | "x": 350, 107 | "y": 180, 108 | "wires": [] 109 | }, 110 | { 111 | "id": "4d90c0d9.a283f", 112 | "type": "tibber-query", 113 | "z": "15652aa.fd5c4d5", 114 | "name": "", 115 | "active": true, 116 | "apiEndpointRef": "d4450078.a5f12", 117 | "x": 350, 118 | "y": 80, 119 | "wires": [ 120 | [ 121 | "d98c9051.ec2cb" 122 | ] 123 | ] 124 | }, 125 | { 126 | "id": "fb875b11.4c9c18", 127 | "type": "tibber-notify", 128 | "z": "15652aa.fd5c4d5", 129 | "name": "", 130 | "active": true, 131 | "apiEndpointRef": "d4450078.a5f12", 132 | "notifyTitle": "", 133 | "notifyMessage": "", 134 | "notifyScreen": "", 135 | "x": 330, 136 | "y": 300, 137 | "wires": [] 138 | }, 139 | { 140 | "id": "1f3d8f53.3561c1", 141 | "type": "inject", 142 | "z": "15652aa.fd5c4d5", 143 | "name": "", 144 | "props": [ 145 | { 146 | "p": "payload", 147 | "v": "{\"title\":\"Test\",\"message\":\"This is a simple test\",\"screen\":\"HOME\"}", 148 | "vt": "json" 149 | }, 150 | { 151 | "p": "topic", 152 | "v": "", 153 | "vt": "str" 154 | } 155 | ], 156 | "repeat": "", 157 | "crontab": "", 158 | "once": false, 159 | "onceDelay": 0.1, 160 | "topic": "", 161 | "payload": "{\"title\":\"Test\",\"message\":\"This is a simple test\",\"screen\":\"HOME\"}", 162 | "payloadType": "json", 163 | "x": 120, 164 | "y": 300, 165 | "wires": [ 166 | [ 167 | "fb875b11.4c9c18" 168 | ] 169 | ] 170 | }, 171 | { 172 | "id": "8ab553e09f0322b7", 173 | "type": "tibber-data", 174 | "z": "15652aa.fd5c4d5", 175 | "name": "GetHome", 176 | "active": true, 177 | "apiEndpointRef": "d4450078.a5f12", 178 | "queryName": "getHome", 179 | "homeId": "96a14971-525a-4420-aae9-e5aedaa129ff", 180 | "energyResolution": "DAILY", 181 | "lastCount": 10, 182 | "x": 320, 183 | "y": 420, 184 | "wires": [ 185 | [ 186 | "47dc9e1949e5cbe2" 187 | ] 188 | ] 189 | }, 190 | { 191 | "id": "6dfb2ea9d13e4447", 192 | "type": "inject", 193 | "z": "15652aa.fd5c4d5", 194 | "name": "", 195 | "props": [ 196 | { 197 | "p": "payload" 198 | }, 199 | { 200 | "p": "topic", 201 | "vt": "str" 202 | } 203 | ], 204 | "repeat": "", 205 | "crontab": "", 206 | "once": false, 207 | "onceDelay": 0.1, 208 | "topic": "", 209 | "payload": "", 210 | "payloadType": "date", 211 | "x": 120, 212 | "y": 420, 213 | "wires": [ 214 | [ 215 | "8ab553e09f0322b7" 216 | ] 217 | ] 218 | }, 219 | { 220 | "id": "47dc9e1949e5cbe2", 221 | "type": "debug", 222 | "z": "15652aa.fd5c4d5", 223 | "name": "debug 2", 224 | "active": true, 225 | "tosidebar": true, 226 | "console": false, 227 | "tostatus": false, 228 | "complete": "false", 229 | "statusVal": "", 230 | "statusType": "auto", 231 | "x": 540, 232 | "y": 420, 233 | "wires": [] 234 | }, 235 | { 236 | "id": "d4450078.a5f12", 237 | "type": "tibber-api-endpoint", 238 | "queryUrl": "https://api.tibber.com/v1-beta/gql", 239 | "feedConnectionTimeout": "30", 240 | "feedTimeout": "60", 241 | "queryRequestTimeout": "30", 242 | "name": "Demo" 243 | } 244 | ] -------------------------------------------------------------------------------- /examples/send-push-notification.gql: -------------------------------------------------------------------------------- 1 | mutation{sendPushNotification(input: {title: "Notification through API", message: "Hello from me!!", screenToOpen: CONSUMPTION}){successful pushedToNumberOfDevices}} -------------------------------------------------------------------------------- /node-red-default-settings.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This is the default settings file provided by Node-RED. 3 | * 4 | * It can contain any valid JavaScript code that will get run when Node-RED 5 | * is started. 6 | * 7 | * Lines that start with // are commented out. 8 | * Each entry should be separated from the entries above and below by a comma ',' 9 | * 10 | * For more information about individual settings, refer to the documentation: 11 | * https://nodered.org/docs/user-guide/runtime/configuration 12 | * 13 | * The settings are split into the following sections: 14 | * - Flow File and User Directory Settings 15 | * - Security 16 | * - Server Settings 17 | * - Runtime Settings 18 | * - Editor Settings 19 | * - Node Settings 20 | * 21 | **/ 22 | 23 | module.exports = { 24 | 25 | /******************************************************************************* 26 | * Flow File and User Directory Settings 27 | * - flowFile 28 | * - credentialSecret 29 | * - flowFilePretty 30 | * - userDir 31 | * - nodesDir 32 | ******************************************************************************/ 33 | 34 | /** The file containing the flows. If not set, defaults to flows_.json **/ 35 | flowFile: 'flows.json', 36 | 37 | /** By default, credentials are encrypted in storage using a generated key. To 38 | * specify your own secret, set the following property. 39 | * If you want to disable encryption of credentials, set this property to false. 40 | * Note: once you set this property, do not change it - doing so will prevent 41 | * node-red from being able to decrypt your existing credentials and they will be 42 | * lost. 43 | */ 44 | //credentialSecret: "a-secret-key", 45 | 46 | /** By default, the flow JSON will be formatted over multiple lines making 47 | * it easier to compare changes when using version control. 48 | * To disable pretty-printing of the JSON set the following property to false. 49 | */ 50 | flowFilePretty: true, 51 | 52 | /** By default, all user data is stored in a directory called `.node-red` under 53 | * the user's home directory. To use a different location, the following 54 | * property can be used 55 | */ 56 | //userDir: '/home/nol/.node-red/', 57 | 58 | /** Node-RED scans the `nodes` directory in the userDir to find local node files. 59 | * The following property can be used to specify an additional directory to scan. 60 | */ 61 | //nodesDir: '/home/nol/.node-red/nodes', 62 | 63 | /******************************************************************************* 64 | * Security 65 | * - adminAuth 66 | * - https 67 | * - httpsRefreshInterval 68 | * - requireHttps 69 | * - httpNodeAuth 70 | * - httpStaticAuth 71 | ******************************************************************************/ 72 | 73 | /** To password protect the Node-RED editor and admin API, the following 74 | * property can be used. See https://nodered.org/docs/security.html for details. 75 | */ 76 | //adminAuth: { 77 | // type: "credentials", 78 | // users: [{ 79 | // username: "admin", 80 | // password: "$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.", 81 | // permissions: "*" 82 | // }] 83 | //}, 84 | 85 | /** The following property can be used to enable HTTPS 86 | * This property can be either an object, containing both a (private) key 87 | * and a (public) certificate, or a function that returns such an object. 88 | * See http://nodejs.org/api/https.html#https_https_createserver_options_requestlistener 89 | * for details of its contents. 90 | */ 91 | 92 | /** Option 1: static object */ 93 | //https: { 94 | // key: require("fs").readFileSync('privkey.pem'), 95 | // cert: require("fs").readFileSync('cert.pem') 96 | //}, 97 | 98 | /** Option 2: function that returns the HTTP configuration object */ 99 | // https: function() { 100 | // // This function should return the options object, or a Promise 101 | // // that resolves to the options object 102 | // return { 103 | // key: require("fs").readFileSync('privkey.pem'), 104 | // cert: require("fs").readFileSync('cert.pem') 105 | // } 106 | // }, 107 | 108 | /** If the `https` setting is a function, the following setting can be used 109 | * to set how often, in hours, the function will be called. That can be used 110 | * to refresh any certificates. 111 | */ 112 | //httpsRefreshInterval : 12, 113 | 114 | /** The following property can be used to cause insecure HTTP connections to 115 | * be redirected to HTTPS. 116 | */ 117 | //requireHttps: true, 118 | 119 | /** To password protect the node-defined HTTP endpoints (httpNodeRoot), 120 | * including node-red-dashboard, or the static content (httpStatic), the 121 | * following properties can be used. 122 | * The `pass` field is a bcrypt hash of the password. 123 | * See https://nodered.org/docs/security.html#generating-the-password-hash 124 | */ 125 | //httpNodeAuth: {user:"user",pass:"$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN."}, 126 | //httpStaticAuth: {user:"user",pass:"$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN."}, 127 | 128 | /******************************************************************************* 129 | * Server Settings 130 | * - uiPort 131 | * - uiHost 132 | * - apiMaxLength 133 | * - httpServerOptions 134 | * - httpAdminRoot 135 | * - httpAdminMiddleware 136 | * - httpAdminCookieOptions 137 | * - httpNodeRoot 138 | * - httpNodeCors 139 | * - httpNodeMiddleware 140 | * - httpStatic 141 | * - httpStaticRoot 142 | * - httpStaticCors 143 | ******************************************************************************/ 144 | 145 | /** the tcp port that the Node-RED web server is listening on */ 146 | uiPort: process.env.PORT || 1880, 147 | 148 | /** By default, the Node-RED UI accepts connections on all IPv4 interfaces. 149 | * To listen on all IPv6 addresses, set uiHost to "::", 150 | * The following property can be used to listen on a specific interface. For 151 | * example, the following would only allow connections from the local machine. 152 | */ 153 | //uiHost: "127.0.0.1", 154 | 155 | /** The maximum size of HTTP request that will be accepted by the runtime api. 156 | * Default: 5mb 157 | */ 158 | //apiMaxLength: '5mb', 159 | 160 | /** The following property can be used to pass custom options to the Express.js 161 | * server used by Node-RED. For a full list of available options, refer 162 | * to http://expressjs.com/en/api.html#app.settings.table 163 | */ 164 | //httpServerOptions: { }, 165 | 166 | /** By default, the Node-RED UI is available at http://localhost:1880/ 167 | * The following property can be used to specify a different root path. 168 | * If set to false, this is disabled. 169 | */ 170 | //httpAdminRoot: '/admin', 171 | 172 | /** The following property can be used to add a custom middleware function 173 | * in front of all admin http routes. For example, to set custom http 174 | * headers. It can be a single function or an array of middleware functions. 175 | */ 176 | // httpAdminMiddleware: function(req,res,next) { 177 | // // Set the X-Frame-Options header to limit where the editor 178 | // // can be embedded 179 | // //res.set('X-Frame-Options', 'sameorigin'); 180 | // next(); 181 | // }, 182 | 183 | /** The following property can be used to set addition options on the session 184 | * cookie used as part of adminAuth authentication system 185 | * Available options are documented here: https://www.npmjs.com/package/express-session#cookie 186 | */ 187 | // httpAdminCookieOptions: { }, 188 | 189 | /** Some nodes, such as HTTP In, can be used to listen for incoming http requests. 190 | * By default, these are served relative to '/'. The following property 191 | * can be used to specify a different root path. If set to false, this is 192 | * disabled. 193 | */ 194 | //httpNodeRoot: '/red-nodes', 195 | 196 | /** The following property can be used to configure cross-origin resource sharing 197 | * in the HTTP nodes. 198 | * See https://github.com/troygoode/node-cors#configuration-options for 199 | * details on its contents. The following is a basic permissive set of options: 200 | */ 201 | //httpNodeCors: { 202 | // origin: "*", 203 | // methods: "GET,PUT,POST,DELETE" 204 | //}, 205 | 206 | /** If you need to set an http proxy please set an environment variable 207 | * called http_proxy (or HTTP_PROXY) outside of Node-RED in the operating system. 208 | * For example - http_proxy=http://myproxy.com:8080 209 | * (Setting it here will have no effect) 210 | * You may also specify no_proxy (or NO_PROXY) to supply a comma separated 211 | * list of domains to not proxy, eg - no_proxy=.acme.co,.acme.co.uk 212 | */ 213 | 214 | /** The following property can be used to add a custom middleware function 215 | * in front of all http in nodes. This allows custom authentication to be 216 | * applied to all http in nodes, or any other sort of common request processing. 217 | * It can be a single function or an array of middleware functions. 218 | */ 219 | //httpNodeMiddleware: function(req,res,next) { 220 | // // Handle/reject the request, or pass it on to the http in node by calling next(); 221 | // // Optionally skip our rawBodyParser by setting this to true; 222 | // //req.skipRawBodyParser = true; 223 | // next(); 224 | //}, 225 | 226 | /** When httpAdminRoot is used to move the UI to a different root path, the 227 | * following property can be used to identify a directory of static content 228 | * that should be served at http://localhost:1880/. 229 | * When httpStaticRoot is set differently to httpAdminRoot, there is no need 230 | * to move httpAdminRoot 231 | */ 232 | //httpStatic: '/home/nol/node-red-static/', //single static source 233 | /** 234 | * OR multiple static sources can be created using an array of objects... 235 | * Each object can also contain an options object for further configuration. 236 | * See https://expressjs.com/en/api.html#express.static for available options. 237 | * They can also contain an option `cors` object to set specific Cross-Origin 238 | * Resource Sharing rules for the source. `httpStaticCors` can be used to 239 | * set a default cors policy across all static routes. 240 | */ 241 | //httpStatic: [ 242 | // {path: '/home/nol/pics/', root: "/img/"}, 243 | // {path: '/home/nol/reports/', root: "/doc/"}, 244 | // {path: '/home/nol/videos/', root: "/vid/", options: {maxAge: '1d'}} 245 | //], 246 | 247 | /** 248 | * All static routes will be appended to httpStaticRoot 249 | * e.g. if httpStatic = "/home/nol/docs" and httpStaticRoot = "/static/" 250 | * then "/home/nol/docs" will be served at "/static/" 251 | * e.g. if httpStatic = [{path: '/home/nol/pics/', root: "/img/"}] 252 | * and httpStaticRoot = "/static/" 253 | * then "/home/nol/pics/" will be served at "/static/img/" 254 | */ 255 | //httpStaticRoot: '/static/', 256 | 257 | /** The following property can be used to configure cross-origin resource sharing 258 | * in the http static routes. 259 | * See https://github.com/troygoode/node-cors#configuration-options for 260 | * details on its contents. The following is a basic permissive set of options: 261 | */ 262 | //httpStaticCors: { 263 | // origin: "*", 264 | // methods: "GET,PUT,POST,DELETE" 265 | //}, 266 | 267 | /** The following property can be used to modify proxy options */ 268 | // proxyOptions: { 269 | // mode: "legacy", // legacy mode is for non-strict previous proxy determination logic (node-red < v4 compatible) 270 | // }, 271 | 272 | /******************************************************************************* 273 | * Runtime Settings 274 | * - lang 275 | * - runtimeState 276 | * - diagnostics 277 | * - logging 278 | * - contextStorage 279 | * - exportGlobalContextKeys 280 | * - externalModules 281 | ******************************************************************************/ 282 | 283 | /** Uncomment the following to run node-red in your preferred language. 284 | * Available languages include: en-US (default), ja, de, zh-CN, zh-TW, ru, ko 285 | * Some languages are more complete than others. 286 | */ 287 | // lang: "de", 288 | 289 | /** Configure diagnostics options 290 | * - enabled: When `enabled` is `true` (or unset), diagnostics data will 291 | * be available at http://localhost:1880/diagnostics 292 | * - ui: When `ui` is `true` (or unset), the action `show-system-info` will 293 | * be available to logged in users of node-red editor 294 | */ 295 | diagnostics: { 296 | /** enable or disable diagnostics endpoint. Must be set to `false` to disable */ 297 | enabled: true, 298 | /** enable or disable diagnostics display in the node-red editor. Must be set to `false` to disable */ 299 | ui: true, 300 | }, 301 | /** Configure runtimeState options 302 | * - enabled: When `enabled` is `true` flows runtime can be Started/Stopped 303 | * by POSTing to available at http://localhost:1880/flows/state 304 | * - ui: When `ui` is `true`, the action `core:start-flows` and 305 | * `core:stop-flows` will be available to logged in users of node-red editor 306 | * Also, the deploy menu (when set to default) will show a stop or start button 307 | */ 308 | runtimeState: { 309 | /** enable or disable flows/state endpoint. Must be set to `false` to disable */ 310 | enabled: false, 311 | /** show or hide runtime stop/start options in the node-red editor. Must be set to `false` to hide */ 312 | ui: false, 313 | }, 314 | /** Configure the logging output */ 315 | logging: { 316 | /** Only console logging is currently supported */ 317 | console: { 318 | /** Level of logging to be recorded. Options are: 319 | * fatal - only those errors which make the application unusable should be recorded 320 | * error - record errors which are deemed fatal for a particular request + fatal errors 321 | * warn - record problems which are non fatal + errors + fatal errors 322 | * info - record information about the general running of the application + warn + error + fatal errors 323 | * debug - record information which is more verbose than info + info + warn + error + fatal errors 324 | * trace - record very detailed logging + debug + info + warn + error + fatal errors 325 | * off - turn off all logging (doesn't affect metrics or audit) 326 | */ 327 | level: "info", 328 | /** Whether or not to include metric events in the log output */ 329 | metrics: false, 330 | /** Whether or not to include audit events in the log output */ 331 | audit: false 332 | } 333 | }, 334 | 335 | /** Context Storage 336 | * The following property can be used to enable context storage. The configuration 337 | * provided here will enable file-based context that flushes to disk every 30 seconds. 338 | * Refer to the documentation for further options: https://nodered.org/docs/api/context/ 339 | */ 340 | //contextStorage: { 341 | // default: { 342 | // module:"localfilesystem" 343 | // }, 344 | //}, 345 | 346 | /** `global.keys()` returns a list of all properties set in global context. 347 | * This allows them to be displayed in the Context Sidebar within the editor. 348 | * In some circumstances it is not desirable to expose them to the editor. The 349 | * following property can be used to hide any property set in `functionGlobalContext` 350 | * from being list by `global.keys()`. 351 | * By default, the property is set to false to avoid accidental exposure of 352 | * their values. Setting this to true will cause the keys to be listed. 353 | */ 354 | exportGlobalContextKeys: false, 355 | 356 | /** Configure how the runtime will handle external npm modules. 357 | * This covers: 358 | * - whether the editor will allow new node modules to be installed 359 | * - whether nodes, such as the Function node are allowed to have their 360 | * own dynamically configured dependencies. 361 | * The allow/denyList options can be used to limit what modules the runtime 362 | * will install/load. It can use '*' as a wildcard that matches anything. 363 | */ 364 | externalModules: { 365 | // autoInstall: false, /** Whether the runtime will attempt to automatically install missing modules */ 366 | // autoInstallRetry: 30, /** Interval, in seconds, between reinstall attempts */ 367 | // palette: { /** Configuration for the Palette Manager */ 368 | // allowInstall: true, /** Enable the Palette Manager in the editor */ 369 | // allowUpdate: true, /** Allow modules to be updated in the Palette Manager */ 370 | // allowUpload: true, /** Allow module tgz files to be uploaded and installed */ 371 | // allowList: ['*'], 372 | // denyList: [], 373 | // allowUpdateList: ['*'], 374 | // denyUpdateList: [] 375 | // }, 376 | // modules: { /** Configuration for node-specified modules */ 377 | // allowInstall: true, 378 | // allowList: [], 379 | // denyList: [] 380 | // } 381 | }, 382 | 383 | 384 | /******************************************************************************* 385 | * Editor Settings 386 | * - disableEditor 387 | * - editorTheme 388 | ******************************************************************************/ 389 | 390 | /** The following property can be used to disable the editor. The admin API 391 | * is not affected by this option. To disable both the editor and the admin 392 | * API, use either the httpRoot or httpAdminRoot properties 393 | */ 394 | //disableEditor: false, 395 | 396 | /** Customising the editor 397 | * See https://nodered.org/docs/user-guide/runtime/configuration#editor-themes 398 | * for all available options. 399 | */ 400 | editorTheme: { 401 | /** The following property can be used to set a custom theme for the editor. 402 | * See https://github.com/node-red-contrib-themes/theme-collection for 403 | * a collection of themes to chose from. 404 | */ 405 | //theme: "", 406 | 407 | /** To disable the 'Welcome to Node-RED' tour that is displayed the first 408 | * time you access the editor for each release of Node-RED, set this to false 409 | */ 410 | //tours: false, 411 | 412 | palette: { 413 | /** The following property can be used to order the categories in the editor 414 | * palette. If a node's category is not in the list, the category will get 415 | * added to the end of the palette. 416 | * If not set, the following default order is used: 417 | */ 418 | //categories: ['subflows', 'common', 'function', 'network', 'sequence', 'parser', 'storage'], 419 | }, 420 | 421 | projects: { 422 | /** To enable the Projects feature, set this value to true */ 423 | enabled: false, 424 | workflow: { 425 | /** Set the default projects workflow mode. 426 | * - manual - you must manually commit changes 427 | * - auto - changes are automatically committed 428 | * This can be overridden per-user from the 'Git config' 429 | * section of 'User Settings' within the editor 430 | */ 431 | mode: "manual" 432 | } 433 | }, 434 | 435 | codeEditor: { 436 | /** Select the text editor component used by the editor. 437 | * As of Node-RED V3, this defaults to "monaco", but can be set to "ace" if desired 438 | */ 439 | lib: "monaco", 440 | options: { 441 | /** The follow options only apply if the editor is set to "monaco" 442 | * 443 | * theme - must match the file name of a theme in 444 | * packages/node_modules/@node-red/editor-client/src/vendor/monaco/dist/theme 445 | * e.g. "tomorrow-night", "upstream-sunburst", "github", "my-theme" 446 | */ 447 | // theme: "vs", 448 | /** other overrides can be set e.g. fontSize, fontFamily, fontLigatures etc. 449 | * for the full list, see https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.IStandaloneEditorConstructionOptions.html 450 | */ 451 | //fontSize: 14, 452 | //fontFamily: "Cascadia Code, Fira Code, Consolas, 'Courier New', monospace", 453 | //fontLigatures: true, 454 | } 455 | }, 456 | 457 | markdownEditor: { 458 | mermaid: { 459 | /** enable or disable mermaid diagram in markdown document 460 | */ 461 | enabled: true 462 | } 463 | }, 464 | 465 | multiplayer: { 466 | /** To enable the Multiplayer feature, set this value to true */ 467 | enabled: false 468 | }, 469 | }, 470 | 471 | /******************************************************************************* 472 | * Node Settings 473 | * - fileWorkingDirectory 474 | * - functionGlobalContext 475 | * - functionExternalModules 476 | * - functionTimeout 477 | * - nodeMessageBufferMaxLength 478 | * - ui (for use with Node-RED Dashboard) 479 | * - debugUseColors 480 | * - debugMaxLength 481 | * - debugStatusLength 482 | * - execMaxBufferSize 483 | * - httpRequestTimeout 484 | * - mqttReconnectTime 485 | * - serialReconnectTime 486 | * - socketReconnectTime 487 | * - socketTimeout 488 | * - tcpMsgQueueSize 489 | * - inboundWebSocketTimeout 490 | * - tlsConfigDisableLocalFiles 491 | * - webSocketNodeVerifyClient 492 | ******************************************************************************/ 493 | 494 | /** The working directory to handle relative file paths from within the File nodes 495 | * defaults to the working directory of the Node-RED process. 496 | */ 497 | //fileWorkingDirectory: "", 498 | 499 | /** Allow the Function node to load additional npm modules directly */ 500 | functionExternalModules: true, 501 | 502 | /** Default timeout, in seconds, for the Function node. 0 means no timeout is applied */ 503 | functionTimeout: 0, 504 | 505 | /** The following property can be used to set predefined values in Global Context. 506 | * This allows extra node modules to be made available with in Function node. 507 | * For example, the following: 508 | * functionGlobalContext: { os:require('os') } 509 | * will allow the `os` module to be accessed in a Function node using: 510 | * global.get("os") 511 | */ 512 | functionGlobalContext: { 513 | // os:require('os'), 514 | }, 515 | 516 | /** The maximum number of messages nodes will buffer internally as part of their 517 | * operation. This applies across a range of nodes that operate on message sequences. 518 | * defaults to no limit. A value of 0 also means no limit is applied. 519 | */ 520 | //nodeMessageBufferMaxLength: 0, 521 | 522 | /** If you installed the optional node-red-dashboard you can set it's path 523 | * relative to httpNodeRoot 524 | * Other optional properties include 525 | * readOnly:{boolean}, 526 | * middleware:{function or array}, (req,res,next) - http middleware 527 | * ioMiddleware:{function or array}, (socket,next) - socket.io middleware 528 | */ 529 | //ui: { path: "ui" }, 530 | 531 | /** Colourise the console output of the debug node */ 532 | //debugUseColors: true, 533 | 534 | /** The maximum length, in characters, of any message sent to the debug sidebar tab */ 535 | debugMaxLength: 1000, 536 | 537 | /** The maximum length, in characters, of status messages under the debug node */ 538 | //debugStatusLength: 32, 539 | 540 | /** Maximum buffer size for the exec node. Defaults to 10Mb */ 541 | //execMaxBufferSize: 10000000, 542 | 543 | /** Timeout in milliseconds for HTTP request connections. Defaults to 120s */ 544 | //httpRequestTimeout: 120000, 545 | 546 | /** Retry time in milliseconds for MQTT connections */ 547 | mqttReconnectTime: 15000, 548 | 549 | /** Retry time in milliseconds for Serial port connections */ 550 | serialReconnectTime: 15000, 551 | 552 | /** Retry time in milliseconds for TCP socket connections */ 553 | //socketReconnectTime: 10000, 554 | 555 | /** Timeout in milliseconds for TCP server socket connections. Defaults to no timeout */ 556 | //socketTimeout: 120000, 557 | 558 | /** Maximum number of messages to wait in queue while attempting to connect to TCP socket 559 | * defaults to 1000 560 | */ 561 | //tcpMsgQueueSize: 2000, 562 | 563 | /** Timeout in milliseconds for inbound WebSocket connections that do not 564 | * match any configured node. Defaults to 5000 565 | */ 566 | //inboundWebSocketTimeout: 5000, 567 | 568 | /** To disable the option for using local files for storing keys and 569 | * certificates in the TLS configuration node, set this to true. 570 | */ 571 | //tlsConfigDisableLocalFiles: true, 572 | 573 | /** The following property can be used to verify WebSocket connection attempts. 574 | * This allows, for example, the HTTP request headers to be checked to ensure 575 | * they include valid authentication information. 576 | */ 577 | //webSocketNodeVerifyClient: function(info) { 578 | // /** 'info' has three properties: 579 | // * - origin : the value in the Origin header 580 | // * - req : the HTTP request 581 | // * - secure : true if req.connection.authorized or req.connection.encrypted is set 582 | // * 583 | // * The function should return true if the connection should be accepted, false otherwise. 584 | // * 585 | // * Alternatively, if this function is defined to accept a second argument, callback, 586 | // * it can be used to verify the client asynchronously. 587 | // * The callback takes three arguments: 588 | // * - result : boolean, whether to accept the connection or not 589 | // * - code : if result is false, the HTTP error status to return 590 | // * - reason: if result is false, the HTTP reason string to return 591 | // */ 592 | //}, 593 | } 594 | -------------------------------------------------------------------------------- /nodes/tibber-api-endpoint.html: -------------------------------------------------------------------------------- 1 | 2 | 78 | 79 | -------------------------------------------------------------------------------- /nodes/tibber-api-endpoint.js: -------------------------------------------------------------------------------- 1 | const { version } = require('./version.js') 2 | 3 | module.exports = function (RED) { 4 | function TibberApiEndpointNode(config) { 5 | RED.nodes.createNode(this, config); 6 | 7 | if (this.credentials && !this.credentials.accessToken && config.apiKey) { 8 | RED.nodes.addCredentials(this.id, { accessToken: config.apiKey }); 9 | } 10 | 11 | // delete properties, just in case. 12 | delete config.apiKey; 13 | delete this.apiKey; 14 | 15 | this.queryUrl = config.queryUrl; 16 | this.feedTimeout = config.feedTimeout; 17 | this.feedConnectionTimeout = config.feedConnectionTimeout; 18 | this.queryRequestTimeout = config.queryRequestTimeout; 19 | this.userAgent = `bisand/node-red-contrib-tibber-api/${version}`; 20 | 21 | this.on('export', () => { 22 | alert('EXPORT!'); 23 | }); 24 | } 25 | RED.nodes.registerType('tibber-api-endpoint', TibberApiEndpointNode, { 26 | credentials: { 27 | accessToken: { 28 | type: 'text', 29 | }, 30 | }, 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /nodes/tibber-data.html: -------------------------------------------------------------------------------- 1 | 41 | 42 | 86 | 87 | 90 | -------------------------------------------------------------------------------- /nodes/tibber-data.js: -------------------------------------------------------------------------------- 1 | const TibberQuery = require('tibber-api').TibberQuery; 2 | 3 | module.exports = function(RED) { 4 | function TibberDataNode(config) { 5 | RED.nodes.createNode(this, config); 6 | config.apiEndpoint = RED.nodes.getNode(config.apiEndpointRef); 7 | 8 | this._config = config; 9 | 10 | var credentials = RED.nodes.getCredentials(config.apiEndpointRef); 11 | if (!config.apiEndpoint.queryUrl || !credentials || !credentials.accessToken) { 12 | this.error('Missing mandatory parameters (queryUrl and/or accessToken)'); 13 | return; 14 | } 15 | 16 | // Assign access token to api key to meintain compatibility. This will not cause the access token to be exported. 17 | config.apiEndpoint.apiKey = credentials.accessToken; 18 | this.client = new TibberQuery(config); 19 | 20 | this.on('input', async (msg) => { 21 | var message = msg; 22 | var queryName = this._config.queryName ? this._config.queryName : msg.payload.queryName; 23 | var homeId = this._config.homeId ? this._config.homeId : msg.payload.homeId; 24 | var energyResolution = this._config.energyResolution ? this._config.energyResolution : msg.payload.energyResolution; 25 | var lastCount = Number(this._config.lastCount ? this._config.lastCount : msg.payload.lastCount); 26 | 27 | // Preserve default values. 28 | energyResolution = energyResolution ? energyResolution : 'HOURLY'; 29 | if (isNaN(lastCount)) { 30 | lastCount = 10; 31 | } 32 | 33 | var payload = {}; 34 | switch (queryName) { 35 | case 'getHome': 36 | try { 37 | payload = await this.client.getHome(homeId); 38 | } catch (error) { 39 | payload = error; 40 | } 41 | break; 42 | case 'getHomeComplete': 43 | try { 44 | payload = await this.client.getHomeComplete(homeId); 45 | } catch (error) { 46 | payload = error; 47 | } 48 | break; 49 | case 'getHomes': 50 | try { 51 | payload = await this.client.getHomes(); 52 | } catch (error) { 53 | payload = error; 54 | } 55 | break; 56 | case 'getHomesComplete': 57 | try { 58 | payload = await this.client.getHomesComplete(); 59 | } catch (error) { 60 | payload = error; 61 | } 62 | break; 63 | case 'getCurrentEnergyPrice': 64 | try { 65 | payload = await this.client.getCurrentEnergyPrice(homeId); 66 | } catch (error) { 67 | payload = error; 68 | } 69 | break; 70 | case 'getCurrentEnergyPrices': 71 | try { 72 | payload = await this.client.getCurrentEnergyPrices(); 73 | } catch (error) { 74 | payload = error; 75 | } 76 | break; 77 | case 'getTodaysEnergyPrices': 78 | try { 79 | payload = await this.client.getTodaysEnergyPrices(homeId); 80 | } catch (error) { 81 | payload = error; 82 | } 83 | break; 84 | case 'getTomorrowsEnergyPrices': 85 | try { 86 | payload = await this.client.getTomorrowsEnergyPrices(homeId); 87 | } catch (error) { 88 | payload = error; 89 | } 90 | break; 91 | case 'getConsumption': 92 | try { 93 | payload = await this.client.getConsumption(energyResolution, lastCount, homeId ? homeId : undefined); 94 | } catch (error) { 95 | payload = error; 96 | } 97 | break; 98 | default: 99 | payload = { error: 'Unknown query: ' + queryName }; 100 | break; 101 | } 102 | if (payload) { 103 | message.payload = payload; 104 | this.send(message); 105 | } 106 | }); 107 | } 108 | 109 | RED.nodes.registerType('tibber-data', TibberDataNode); 110 | }; 111 | -------------------------------------------------------------------------------- /nodes/tibber-feed.html: -------------------------------------------------------------------------------- 1 | 121 | 122 | 249 | 250 | -------------------------------------------------------------------------------- /nodes/tibber-feed.js: -------------------------------------------------------------------------------- 1 | const TibberFeed = require('tibber-api').TibberFeed; 2 | const TibberQuery = require('tibber-api').TibberQuery; 3 | const StatusEnum = Object.freeze({ 'unknown': -1, 'disconnected': 0, 'waiting': 1, 'connecting': 2, 'connected': 100 }); 4 | 5 | // Defensive helper 6 | function getFeedNodeRegistry(feed) { 7 | if (!feed) return new Set(); 8 | if (!feed._nodeRegistry) feed._nodeRegistry = new Set(); 9 | return feed._nodeRegistry; 10 | } 11 | 12 | module.exports = function (RED) { 13 | function TibberFeedNode(config) { 14 | RED.nodes.createNode(this, config); 15 | const _config = config; 16 | _config.apiEndpoint = RED.nodes.getNode(_config.apiEndpointRef); 17 | _config.reconnectDelay = _config.reconnectDelay || 5000; 18 | this._config = _config; 19 | 20 | this.log('TibberFeedNode created'); 21 | 22 | this._connectionDelay = -1; 23 | this._lastStatus = StatusEnum.unknown; 24 | this._setStatus = status => { 25 | if (status !== this._lastStatus) { 26 | this.log(`Status changed: ${this._lastStatus} -> ${status}`); 27 | switch (status) { 28 | case StatusEnum.unknown: 29 | this.status({ fill: "grey", shape: "ring", text: "unknown" }); 30 | break; 31 | case StatusEnum.disconnected: 32 | this.status({ fill: "red", shape: "ring", text: "disconnected" }); 33 | break; 34 | case StatusEnum.waiting: 35 | this.status({ fill: "yellow", shape: "ring", text: "waiting" }); 36 | break; 37 | case StatusEnum.connecting: 38 | this.status({ fill: "green", shape: "ring", text: "connecting" }); 39 | break; 40 | case StatusEnum.connected: 41 | this.status({ fill: "green", shape: "dot", text: "connected" }); 42 | break; 43 | default: 44 | break; 45 | } 46 | this._lastStatus = status; 47 | } 48 | }; 49 | 50 | this._onConnecting = data => { 51 | for (const node of getFeedNodeRegistry(this._feed)) { 52 | node._setStatus(StatusEnum.connecting); 53 | node.log(`Connecting: ${JSON.stringify(data)}`); 54 | } 55 | } 56 | this._onConnectionTimeout = data => { 57 | for (const node of getFeedNodeRegistry(this._feed)) { 58 | node._setStatus(StatusEnum.waiting); 59 | node.log(`Connection Timeout: ${JSON.stringify(data)}`); 60 | } 61 | } 62 | this._onConnected = data => { 63 | for (const node of getFeedNodeRegistry(this._feed)) { 64 | node._setStatus(StatusEnum.connected); 65 | node.log(`Connected: ${JSON.stringify(data)}`); 66 | } 67 | } 68 | this._onConnectionAck = data => { 69 | for (const node of getFeedNodeRegistry(this._feed)) { 70 | node._setStatus(StatusEnum.connected); 71 | node.log(`Connected: ${JSON.stringify(data)}`); 72 | } 73 | } 74 | this._onData = data => { 75 | for (const node of getFeedNodeRegistry(this._feed)) { 76 | if (node && node._config && node._config.active && node._feed && node._feed.connected) { 77 | if (node._lastStatus !== StatusEnum.connected) 78 | node._setStatus(StatusEnum.connected); 79 | node._mapAndsend({ payload: data }); 80 | } else if (node && node._setStatus) { 81 | node._setStatus(StatusEnum.disconnected); 82 | } 83 | } 84 | } 85 | this._onHeartbeatTimeout = data => { 86 | for (const node of getFeedNodeRegistry(this._feed)) { 87 | node._setStatus(StatusEnum.waiting); 88 | node.log(`Heartbeat Timeout: ${JSON.stringify(data)}`); 89 | } 90 | } 91 | this._onHeartbeatReconnect = data => { 92 | for (const node of getFeedNodeRegistry(this._feed)) { 93 | node._setStatus(StatusEnum.connecting); 94 | node.log(`Heartbeat Reconnect: ${JSON.stringify(data)}`); 95 | } 96 | } 97 | 98 | // Add a property to track the reconnect timer 99 | this._reconnectTimer = null; 100 | 101 | this._onDisconnected = data => { 102 | for (const node of getFeedNodeRegistry(this._feed)) { 103 | node._setStatus(StatusEnum.disconnected); 104 | node.log(`Disconnected: ${JSON.stringify(data)}`); 105 | 106 | // Only proceed if node._config exists and node is active 107 | if (node._config && node._config.active) { 108 | const delay = node._config.reconnectDelay || 5000; 109 | const seconds = delay / 1000; 110 | if (node._reconnectTimer) clearTimeout(node._reconnectTimer); 111 | node.log(`Scheduling reconnect in ${seconds} seconds...`); 112 | node._reconnectTimer = setTimeout(() => { 113 | if (node._config && node._config.active && node._feed && !node._feed.connected) { 114 | node.log('Attempting reconnect...'); 115 | node.connect(); 116 | } 117 | }, delay); 118 | } 119 | } 120 | } 121 | 122 | this._onError = data => { 123 | for (const node of getFeedNodeRegistry(this._feed)) { 124 | node.error('TibberFeed error: ' + JSON.stringify(data)); 125 | } 126 | } 127 | this._onWarn = data => { 128 | for (const node of getFeedNodeRegistry(this._feed)) { 129 | node.warn(data); 130 | } 131 | } 132 | this._onLog = data => { 133 | for (const node of getFeedNodeRegistry(this._feed)) { 134 | node.log(data); 135 | } 136 | } 137 | 138 | this._setStatus(StatusEnum.disconnected); 139 | 140 | const credentials = RED.nodes.getCredentials(_config.apiEndpointRef); 141 | if (!_config.apiEndpoint?.queryUrl || !credentials || !credentials.accessToken || !_config.homeId) { 142 | this.error('Missing mandatory parameters. Execution will halt. Please reconfigure and publish again.'); 143 | return; 144 | } 145 | 146 | if (!_config.active) { 147 | this.log('Node is not active, skipping initialization.'); 148 | return; 149 | } 150 | 151 | // Assign access token to api key to maintain compatibility. 152 | const key = _config.apiEndpoint.apiKey = credentials.accessToken; 153 | const home = _config.homeId; 154 | const feedTimeout = (_config.apiEndpoint.feedTimeout ? _config.apiEndpoint.feedTimeout : 60) * 1000; 155 | const feedConnectionTimeout = (_config.apiEndpoint.feedConnectionTimeout ? _config.apiEndpoint.feedConnectionTimeout : 30) * 1000; 156 | const queryRequestTimeout = (_config.apiEndpoint.queryRequestTimeout ? _config.apiEndpoint.queryRequestTimeout : 30) * 1000; 157 | 158 | // Only one TibberFeed per key+home 159 | if (!TibberFeedNode.instances[key]) { 160 | TibberFeedNode.instances[key] = {}; 161 | } 162 | if (!TibberFeedNode.instances[key][home]) { 163 | this.debug(`Creating new TibberFeed for key=${key}, home=${home}`); 164 | TibberFeedNode.instances[key][home] = new TibberFeed(new TibberQuery(_config), feedTimeout, true); 165 | this.debug('TibberFeed instance created:', TibberFeedNode.instances[key][home]); 166 | } else { 167 | this.log(`Reusing existing TibberFeed for key=${key}, home=${home}`); 168 | } 169 | this._feed = TibberFeedNode.instances[key][home]; 170 | this._feed.config = _config; 171 | this._feed.feedIdleTimeout = feedTimeout; 172 | this._feed.feedConnectionTimeout = feedConnectionTimeout; 173 | this._feed.queryRequestTimeout = queryRequestTimeout; 174 | 175 | // Register this node instance in the feed's registry 176 | const nodeRegistry = getFeedNodeRegistry(this._feed); 177 | nodeRegistry.add(this); 178 | this.debug(`Node registered. Registry size: ${nodeRegistry.size}`); 179 | 180 | // Only add event listeners once per feed instance 181 | if (!this._feed._eventHandlersRegistered) { 182 | this.debug('Registering event handlers for TibberFeed'); 183 | this._feed.on('connecting', this._onConnecting); 184 | this._feed.on('connection_timeout', this._onConnectionTimeout); 185 | this._feed.on('connected', this._onConnected); 186 | this._feed.on('connection_ack', this._onConnectionAck); 187 | this._feed.on('data', this._onData); 188 | this._feed.on('heartbeat_timeout', this._onHeartbeatTimeout); 189 | this._feed.on('heartbeat_reconnect', this._onHeartbeatReconnect); 190 | this._feed.on('disconnected', this._onDisconnected); 191 | this._feed.on('error', this._onError); 192 | this._feed.on('warn', this._onWarn); 193 | this._feed.on('log', this._onLog); 194 | this._feed._eventHandlersRegistered = true; 195 | } 196 | 197 | this._mapAndsend = (msg) => { 198 | const returnMsg = { payload: {} }; 199 | if (msg && msg.payload) 200 | for (const property in msg.payload) { 201 | if (_config[property]) 202 | returnMsg.payload[property] = msg.payload[property]; 203 | } 204 | this.send(returnMsg); 205 | } 206 | 207 | this.connect = () => { 208 | this._setStatus(StatusEnum.connecting); 209 | this.debug('Calling _feed.connect()'); 210 | try { 211 | this._feed.connect(); 212 | this.debug('Called _feed.connect() successfully'); 213 | } catch (err) { 214 | this.error('Error calling _feed.connect(): ' + err.message); 215 | } 216 | }; 217 | 218 | // Only connect if this is the first node for this feed 219 | if (nodeRegistry.size === 1) { 220 | this._setStatus(StatusEnum.waiting); 221 | this.log('Preparing to connect to Tibber...'); 222 | this._connectionDelay = setTimeout(() => { 223 | this.connect(); 224 | }, 1000); 225 | } else { 226 | this.log('Feed already connected or connecting.'); 227 | } 228 | 229 | this.on('close', (removed, done) => { 230 | clearTimeout(this._connectionDelay); 231 | if (this._reconnectTimer) clearTimeout(this._reconnectTimer); 232 | if (!this._feed) { 233 | done(); 234 | return; 235 | } 236 | 237 | // Remove this node from the registry 238 | const nodeRegistry = getFeedNodeRegistry(this._feed); 239 | nodeRegistry.delete(this); 240 | this.log(`Node unregistered. Registry size: ${nodeRegistry.size}`); 241 | 242 | // If no more nodes are using this feed, clean up 243 | if (nodeRegistry.size === 0) { 244 | this.log('Disconnecting from Tibber feed...'); 245 | this._feed.close(); 246 | nodeRegistry.clear(); 247 | } 248 | 249 | if (typeof this._feed.off === 'function' && this._feed._eventHandlersRegistered) { 250 | this.debug('Unregistering event handlers for TibberFeed'); 251 | this._feed.off('connecting', this._onConnecting); 252 | this._feed.off('connection_timeout', this._onConnectionTimeout); 253 | this._feed.off('connected', this._onConnected); 254 | this._feed.off('connection_ack', this._onConnectionAck); 255 | this._feed.off('data', this._onData); 256 | this._feed.off('heartbeat_timeout', this._onHeartbeatTimeout); 257 | this._feed.off('heartbeat_reconnect', this._onHeartbeatReconnect); 258 | this._feed.off('disconnected', this._onDisconnected); 259 | this._feed.off('error', this._onError); 260 | this._feed.off('warn', this._onWarn); 261 | this._feed.off('log', this._onLog); 262 | } 263 | this._feed._eventHandlersRegistered = false; 264 | 265 | this._setStatus(StatusEnum.disconnected); 266 | this.log('Done.'); 267 | done(); 268 | }); 269 | } 270 | TibberFeedNode.instances = {}; 271 | 272 | RED.nodes.registerType("tibber-feed", TibberFeedNode); 273 | }; -------------------------------------------------------------------------------- /nodes/tibber-notify.html: -------------------------------------------------------------------------------- 1 | 32 | 33 | 58 | 59 | 62 | -------------------------------------------------------------------------------- /nodes/tibber-notify.js: -------------------------------------------------------------------------------- 1 | const TibberQuery = require("tibber-api").TibberQuery; 2 | 3 | module.exports = function (RED) { 4 | function TibberNotifyNode(config) { 5 | RED.nodes.createNode(this, config); 6 | config.apiEndpoint = RED.nodes.getNode(config.apiEndpointRef); 7 | this._config = config; 8 | 9 | var credentials = RED.nodes.getCredentials(config.apiEndpointRef); 10 | if (!config.apiEndpoint.queryUrl || !credentials || !credentials.accessToken) { 11 | this.error("Missing mandatory parameters (queryUrl and/or accessToken)"); 12 | return; 13 | } 14 | 15 | // Assign access token to api key to meintain compatibility. This will not cause the access token to be exported. 16 | config.apiEndpoint.apiKey = credentials.accessToken; 17 | this.client = new TibberQuery(config); 18 | 19 | this.on("input", async (msg) => { 20 | var title = this._config.notifyTitle 21 | ? this._config.notifyTitle 22 | : msg.payload.title; 23 | var message = this._config.notifyMessage 24 | ? this._config.notifyMessage 25 | : msg.payload.message; 26 | var screen = this._config.notifyScreen 27 | ? this._config.notifyScreen 28 | : msg.payload.screen; 29 | screen = screen ? screen : "HOME"; 30 | 31 | if (!title || !message) { 32 | this.error("Missing mandatory parameters (title and/or message)"); 33 | return; 34 | } 35 | 36 | var query = 37 | 'mutation{sendPushNotification(input: {title: "' + 38 | title + 39 | '", message: "' + 40 | message + 41 | '", screenToOpen: ' + 42 | screen + 43 | "}){successful pushedToNumberOfDevices}}"; 44 | try { 45 | var result = await this.client.query(query); 46 | if (result.error) { 47 | this.error(JSON.stringify(result)); 48 | } else { 49 | this.log(JSON.stringify(result)); 50 | } 51 | } catch (error) { 52 | this.error(error); 53 | } 54 | }); 55 | } 56 | 57 | RED.nodes.registerType("tibber-notify", TibberNotifyNode); 58 | }; 59 | -------------------------------------------------------------------------------- /nodes/tibber-query.html: -------------------------------------------------------------------------------- 1 | 22 | 23 | 33 | 34 | 37 | -------------------------------------------------------------------------------- /nodes/tibber-query.js: -------------------------------------------------------------------------------- 1 | const TibberQuery = require('tibber-api').TibberQuery; 2 | 3 | module.exports = function (RED) { 4 | function TibberQueryNode(config) { 5 | RED.nodes.createNode(this, config); 6 | config.apiEndpoint = RED.nodes.getNode(config.apiEndpointRef); 7 | this._config = config; 8 | 9 | var credentials = RED.nodes.getCredentials(config.apiEndpointRef); 10 | if (!config.apiEndpoint.queryUrl || !credentials || !credentials.accessToken) { 11 | this.error('Missing mandatory parameters (queryUrl and/or accessToken)'); 12 | return; 13 | } 14 | 15 | // Assign access token to api key to meintain compatibility. This will not cause the access token to be exported. 16 | config.apiEndpoint.apiKey = credentials.accessToken; 17 | this.client = new TibberQuery(config); 18 | 19 | this.on('input', async (msg) => { 20 | var message = msg; 21 | try { 22 | var payload = await this.client.query(message.payload); 23 | message.payload = payload; 24 | this.send(message); 25 | } catch (error) { 26 | this.error(error); 27 | } 28 | }); 29 | 30 | } 31 | 32 | RED.nodes.registerType("tibber-query", TibberQueryNode); 33 | }; 34 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-red-contrib-tibber-api", 3 | "version": "6.3.2", 4 | "description": "Node Red module for integrating with Tibber api", 5 | "repository": { 6 | "url": "git+https://github.com/bisand/node-red-contrib-tibber-api.git" 7 | }, 8 | "bugs": { 9 | "url": "https://github.com/bisand/node-red-contrib-tibber-api/issues" 10 | }, 11 | "dependencies": { 12 | "tibber-api": "^5.4.2" 13 | }, 14 | "devDependencies": { 15 | "eslint": "^9.27.0", 16 | "mkver": "^3.0.2", 17 | "mocha": "^11.3.0", 18 | "node-red": "^4.0.9" 19 | }, 20 | "directories": { 21 | "examples": "./examples", 22 | "nodes": "./nodes" 23 | }, 24 | "scripts": { 25 | "prepack": "mkver ./nodes/version.js", 26 | "test": "mocha tests/test*.js", 27 | "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", 28 | "lint": "eslint -c .eslintrc.json .", 29 | "prepare": "", 30 | "preversion": "npm test", 31 | "version": "", 32 | "postversion": "", 33 | "start": "node node_modules/node-red/red.js -v -u . -s node-red-default-settings.js", 34 | "debug": "node --nolazy --inspect-brk=9229 node_modules/node-red/red.js -v -u . -s node-red-default-settings.js" 35 | }, 36 | "keywords": [ 37 | "node-red", 38 | "tibber", 39 | "iot", 40 | "power", 41 | "home-automation", 42 | "smarthome", 43 | "energy" 44 | ], 45 | "author": "André Biseth", 46 | "license": "MIT", 47 | "node-red": { 48 | "version": ">=2.0.0", 49 | "nodes": { 50 | "tibber-api-endpoint": "nodes/tibber-api-endpoint.js", 51 | "tibber-feed": "nodes/tibber-feed.js", 52 | "tibber-query": "nodes/tibber-query.js", 53 | "tibber-data": "nodes/tibber-data.js", 54 | "tibber-notify": "nodes/tibber-notify.js" 55 | } 56 | }, 57 | "engines": { 58 | "node": ">=14.0.0" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /tests/test-tibber-api-endpoint.js: -------------------------------------------------------------------------------- 1 | /* eslint-env mocha */ 2 | let UrlTools = require('tibber-api').UrlTools; 3 | let assert = require('assert'); 4 | const urlTools = new UrlTools(); 5 | 6 | describe('tibber-api-endpoint', function () { 7 | describe('Validate Url', function () { 8 | it('Websocket url should be valid', function () { 9 | let isValid = urlTools.validateUrl("wss://api.tibber.com/v1-beta/gql/subscriptions"); 10 | assert.ok(isValid); 11 | }); 12 | it('Query url should be valid', function () { 13 | let isValid = urlTools.validateUrl("https://api.tibber.com/v1-beta/gql"); 14 | assert.ok(isValid); 15 | }); 16 | it('Websocket url should be invalid', function () { 17 | let isValid = urlTools.validateUrl("wss//api.tibber.com/v1-beta/gql/subscriptions"); 18 | assert.ok(!isValid); 19 | }); 20 | it('Query url should be invalid', function () { 21 | let isValid = urlTools.validateUrl("https//api.tibber.com/v1-beta/gql"); 22 | assert.ok(!isValid); 23 | }); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /tests/test-tibber-feed.js: -------------------------------------------------------------------------------- 1 | /* eslint-env mocha */ 2 | const { TibberQueryBase, TibberFeed } = require('tibber-api'); 3 | const assert = require('assert'); 4 | const WebSocket = require('ws'); 5 | 6 | class FakeTibberQuery extends TibberQueryBase { 7 | /** 8 | * Constructor 9 | * Create an instace of TibberQuery class 10 | * @param config IConfig object 11 | * @see IConfig 12 | */ 13 | constructor(config) { 14 | super(config); 15 | } 16 | 17 | async getWebsocketSubscriptionUrl() { 18 | return new URL(this.config.apiEndpoint.queryUrl); 19 | } 20 | 21 | async getRealTimeEnabled(homeId) { 22 | return homeId !== undefined; 23 | } 24 | } 25 | 26 | 27 | describe('TibberFeed', function () { 28 | let server = undefined; 29 | 30 | before(function () { 31 | server = new WebSocket.Server({ port: 1337 }); 32 | server.on('connection', function (socket) { 33 | socket.on('message', function (msg) { 34 | let obj = JSON.parse(msg); 35 | if (obj.type == 'connection_init' && obj.payload.token === '1337') { 36 | obj.type = 'connection_ack'; 37 | socket.send(JSON.stringify(obj)); 38 | } else if (obj.type == 'subscribe' 39 | && obj.payload.query 40 | && obj.payload.query.startsWith('subscription($homeId:ID!){liveMeasurement(homeId:$homeId){') 41 | && obj.payload.variables 42 | && obj.payload.variables.homeId === '1337') { 43 | obj = { 44 | id: obj.id, 45 | type: 'next', 46 | payload: { data: { liveMeasurement: { value: 1337 } } }, 47 | }; 48 | socket.send(JSON.stringify(obj)); 49 | } else if (obj.type == 'subscribe' 50 | && obj.payload.query 51 | && obj.payload.query.startsWith('subscription($homeId:ID!){liveMeasurement(homeId:$homeId){') 52 | && obj.payload.variables 53 | && obj.payload.variables.homeId === '42') { 54 | obj = { 55 | id: obj.id, 56 | type: 'next', 57 | payload: { data: { liveMeasurement: { value: 42 } } }, 58 | }; 59 | socket.send(JSON.stringify(obj)); 60 | } 61 | }); 62 | socket.on('close', function () { }); 63 | }); 64 | }); 65 | 66 | after(function () { 67 | if (server) { 68 | for (const client of server.clients) { 69 | client.close(); 70 | console.log('Closed client.'); 71 | } 72 | server.close(); 73 | server = null; 74 | } 75 | }); 76 | 77 | describe('create', function () { 78 | it('Should be created', function () { 79 | const query = new FakeTibberQuery({ 80 | apiEndpoint: { 81 | queryUrl: 'ws://localhost:1337', 82 | apiKey: '1337', 83 | }, 84 | homeId: '1337', 85 | active: true, 86 | }); 87 | let feed = new TibberFeed(query); 88 | assert.ok(feed); 89 | }); 90 | }); 91 | 92 | describe('connect', function () { 93 | it('Should be connected', function (done) { 94 | this.timeout(5000); 95 | const query = new FakeTibberQuery({ 96 | apiEndpoint: { 97 | queryUrl: 'ws://localhost:1337', 98 | apiKey: '1337', 99 | }, 100 | homeId: '1337', 101 | active: true, 102 | }); 103 | const feed = new TibberFeed(query); 104 | feed.on('connection_ack', function (data) { 105 | assert.ok(data); 106 | assert.equal(data.payload.token, '1337'); 107 | feed.close(); 108 | done(); 109 | }); 110 | feed.connect(); 111 | }); 112 | }); 113 | 114 | describe('receive', function () { 115 | it('Should receive data', function (done) { 116 | this.timeout(5000); 117 | const query = new FakeTibberQuery({ 118 | apiEndpoint: { 119 | queryUrl: 'ws://localhost:1337', 120 | apiKey: '1337', 121 | }, 122 | homeId: '1337', 123 | active: true, 124 | }); 125 | const feed = new TibberFeed(query); 126 | feed.on('data', function (data) { 127 | assert.ok(data); 128 | assert.equal(data.value, 1337); 129 | feed.close(); 130 | done(); 131 | }); 132 | feed.connect(); 133 | }); 134 | }); 135 | 136 | describe('receive', function () { 137 | it('Should receive data from two homes', function (done) { 138 | this.timeout(5000); 139 | let done1, done2 = false; 140 | const query1 = new FakeTibberQuery({ 141 | apiEndpoint: { 142 | queryUrl: 'ws://localhost:1337', 143 | apiKey: '1337', 144 | }, 145 | homeId: '1337', 146 | active: true, 147 | }); 148 | const feed1 = new TibberFeed(query1); 149 | const query2 = new FakeTibberQuery({ 150 | apiEndpoint: { 151 | queryUrl: 'ws://localhost:1337', 152 | apiKey: '1337', 153 | }, 154 | homeId: '42', 155 | active: true, 156 | }); 157 | const feed2 = new TibberFeed(query2); 158 | feed1.on('data', function (data) { 159 | assert.ok(data); 160 | assert.equal(data.value, 1337); 161 | feed1.close(); 162 | done1 = true; 163 | }); 164 | feed2.on('data', function (data) { 165 | assert.ok(data); 166 | assert.equal(data.value, 42); 167 | feed2.close(); 168 | done2 = true; 169 | }); 170 | feed2.connect(); 171 | feed1.connect(); 172 | let interval = setInterval(() => { 173 | if (done1 && done2) { 174 | clearInterval(interval); 175 | done(); 176 | } 177 | }, 100); 178 | }); 179 | }); 180 | 181 | describe('active', function () { 182 | it('Should be active', function () { 183 | const query = new FakeTibberQuery({ 184 | apiEndpoint: { 185 | queryUrl: 'ws://localhost:1337', 186 | apiKey: '1337', 187 | }, 188 | homeId: '1337', 189 | active: true, 190 | }); 191 | const feed = new TibberFeed(query); 192 | assert.equal(feed.active, true); 193 | }); 194 | }); 195 | 196 | describe('inactive', function () { 197 | it('Should be inactive', function () { 198 | const query = new FakeTibberQuery({ 199 | apiEndpoint: { 200 | queryUrl: 'ws://localhost:1337', 201 | apiKey: '1337', 202 | }, 203 | homeId: '1337', 204 | active: false, 205 | }); 206 | let feed = new TibberFeed(query); 207 | assert.equal(feed.active, false); 208 | }); 209 | }); 210 | 211 | describe('timeout', function () { 212 | it('Should timeout after 3 sec', function (done) { 213 | this.timeout(10000); 214 | const query = new FakeTibberQuery( 215 | { 216 | apiEndpoint: { 217 | queryUrl: 'ws://localhost:1337', 218 | apiKey: '1337', 219 | }, 220 | homeId: '1337', 221 | active: true, 222 | }, 223 | ); 224 | let called = false; 225 | const feed = new TibberFeed(query, 3000); 226 | feed.on('connection_ack', function (data) { 227 | assert.ok(data); 228 | feed.heartbeat(); 229 | }); 230 | feed.on('disconnected', function (data) { 231 | assert.ok(data); 232 | if (!called) { 233 | called = true; 234 | feed.active = false; 235 | feed.close(); 236 | done(); 237 | } 238 | }); 239 | feed.connect(); 240 | }); 241 | }); 242 | 243 | describe('reconnect', function () { 244 | it('Should reconnect 3 times after 5 sec. timeout', function (done) { 245 | this.timeout(60000); 246 | const query = new FakeTibberQuery( 247 | { 248 | apiEndpoint: { 249 | queryUrl: 'ws://localhost:1337', 250 | apiKey: '1337', 251 | }, 252 | homeId: '1337', 253 | active: true, 254 | }, 255 | ); 256 | let callCount = 0; 257 | const feed = new TibberFeed(query, 1000); 258 | feed.on('connection_ack', function (data) { 259 | assert.ok(data); 260 | assert.equal(data.payload.token, '1337'); 261 | }); 262 | feed.on('disconnected', function (data) { 263 | assert.ok(data); 264 | if (++callCount == 3) { 265 | feed.active = false; 266 | feed.close(); 267 | done(); 268 | } 269 | }); 270 | feed.connect(); 271 | }); 272 | }); 273 | }); 274 | -------------------------------------------------------------------------------- /tests/test-tibber-query.js: -------------------------------------------------------------------------------- 1 | /* eslint-env mocha */ 2 | let TibberQuery = require("tibber-api").TibberQuery; 3 | let assert = require("assert"); 4 | describe("TibberQuery", function() { 5 | describe("create", function() { 6 | it("Should be created", function() { 7 | let query = new TibberQuery({ 8 | apiEndpoint: { queryUrl: "https://test.com", apiKey: "1337" }, 9 | active: false 10 | }); 11 | assert.ok(query); 12 | }); 13 | }); 14 | describe("inactive", function() { 15 | it("Should be inactive", function() { 16 | let query = new TibberQuery({ 17 | apiEndpoint: { queryUrl: "https://test.com", apiKey: "1337" }, 18 | active: false 19 | }); 20 | assert.equal(query.active, false); 21 | }); 22 | }); 23 | }); 24 | --------------------------------------------------------------------------------