Giter Club home page Giter Club logo

st-mq's Introduction

SmartThings MQTT tools with kWh spot price query (Nordic + Baltic)

This tool can be run as a standalone app (see below) or as a Home Assistant add-on. The tool uses MQTT communication, so it can be used with any home automation system that can receive MQTT messages, not just SmartThings. However, the setup instructions are provided only for SmartThings.

Nordpool kWh spot price control for SmartThings

The mqtt-control.js nodejs script obtains Nordic and Baltic electricity prices from Entso-E Transparency platform API or Elering API backup API (works only for fi, ee, lt, and lv country codes), and publishes an MQTT message through an MQTT broker to the MQTTDevices edge driver installed on SmartThings. The script stores data in ./share/st-mq/st-mq.csv which can be plotted with the html chart tool. The file ./share/st-mq/st-mq.csv has the following format:

unix_time,price,heat_on,temp_in,temp_out

NOTE! The device running mqtt-control.js should be connected to the same local area network as the MQTT broker and the SmartThings hub.

Easee API query script

The Easee API query script stores the respective user's Easee Charger and Easee Equalizer data into ./share/st-mq/easee.csv. The stored data contains electric current for three phases for Easee Charger (charger consumption) and Easee Equalizer (total home consumption). This data can also be plotted with the html chart tool. The ./share/st-mq/easee.csv has the following format:

unix_time,ch_curr1,ch_curr2,ch_curr3,eq_curr1,eq_curr2,eq_curr3

Installation (standalone)

Install mosquitto MQTT broker, npm, nodejs, and pm2 process manager (optional) if not already installed:

sudo apt update
sudo apt install -y mosquitto nodejs npm pm2

Clone this repo by

git clone https://github.com/hokkanen/st-mq.git

Install npm dependencies locally in the project folder by

cd st-mq
npm i

Setup (standalone)

SmartThings

In SmartThings, install MQTTDevices edge driver, set the correct IP for the device where the MQTT broker is running, and subscribe to from_stmq/heat/action topic and listen for heaton/heatoff messages.

Config

The root directory contains config.json file in which the options section needs to be updated. In the config, fill in geolocation information, temperature-to-heating-hours mapping array, MQTT broker details, and the required API keys and SmartThings device IDs for the temperature sensors. For more information, check the HASS translations file.

To collect consumption data from local Easee devices, Easee authentication and device information is required as well. Giving Easee login credentials in place of the actual tokens works also, ie, "access_token" = "username" and "refresh_token" = "pw". If these authentication details are not provided, Easee consumption data is not collected.

The user-specific Entso-E, OpenWeatherMap, and SmartThings API keys can be obtained freely by registering to these services. If the OpenWeatherMap and SmartThings API keys are not set (ie, these API queries fail), the inside and outside temperatures are simply set to 0 degrees Celsius. However, inside temperature is only used for csv logging, and does not impact the heat adjustment algorithm.

Mosquitto MQTT broker

Set up Mosquitto user name and password by creating a password file with

sudo mosquitto_passwd -c /etc/mosquitto/passwd <username>

Create a user config file with micro editor by

sudo micro /etc/mosquitto/conf.d/myconfig.conf

with the following contents:

# Allow connections from anywhere
listener 1883

# Require credentials for connections
allow_anonymous false
password_file /etc/mosquitto/passwd

Restart Mosquitto to apply the changes:

sudo systemctl restart mosquitto

Running (standalone)

To start all required services, ie, easee-query.js and mqtt-control.js scripts, and a web server for chart/index.html, run scheduler.js in the current terminal instance by

node scheduler.js

To run with pm2 process manager without using the scheduler.js script, use the following (easee-query.js does not have an internal scheduler):

pm2 start ./scripts/mqtt-control.js
pm2 start ./scripts/easee-query.js --cron-restart="*/5 * * * *" --no-autorestart
pm2 start npm -- run dev

The console output uses blue color for mqtt-control.js and green color for easee-query.js (the chart server log is stored in ./share/st-mq/chart-server.log). The chart itself can be accessed with browser at http://localhost:1234.

Create persistent app list (standalone)

Make pm2 restart automatically after reboot by

pm2 startup

and following the instructions. After all desired apps have been started, save the app list by

pm2 save

so the apps will respawn after reboot. After a nodejs upgrade the startup script should be updated by running pm2 unstartup and pm2 startup.

st-mq's People

Contributors

hokkanen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.