smart-energy-monitor/docs/shelly-monitor/README.md

127 lines
3.5 KiB
Markdown
Raw Normal View History

2023-02-27 17:11:53 +01:00
# Shelly Plug (S)
2023-02-20 17:42:40 +01:00
2023-02-27 17:11:53 +01:00
Shelly Plugs S are quite cheap but relatively accurate to measure power consumptions less than 2.5 kW.
![Shelly Plug](../images/shelly_plug_s_1-1.jpg)
2023-02-27 16:22:59 +01:00
## Flash Tasmota
There's an OpenSource project to flash Tasmota on Shelly Plugs: [mg2x](https://github.com/arendst/mgos-to-tasmota).
2023-02-27 16:22:59 +01:00
Locate your Shellie's IP adress (in my case: 192.168.2.150) and update it "over the air" with the Tasmota firmware:
2023-02-27 16:22:59 +01:00
http://192.168.2.150/ota?url=http://ota.tasmota.com/tasmota/shelly/mg2tasmota-ShellyPlugS.zip
2023-02-27 17:25:56 +01:00
Your Shelly will return a JSON object that looks like that:
2023-02-27 16:22:59 +01:00
```
{
"status": "updating",
"has_update": false,
"new_version": "20230109-114426/v1.12.2-g32055ee",
"old_version": "20230109-114426/v1.12.2-g32055ee"
}
```
2023-02-27 17:01:27 +01:00
After a while your Shelly Plug S should be flashed with Tasmota firmware.
2023-02-27 16:22:59 +01:00
> Just be patient. This took longer than five minutes in my DSL connected network.
2023-02-27 17:01:27 +01:00
The Shelly Plus S will create create a new Wifi.
2023-02-27 17:01:27 +01:00
![Tasmota Wifi](../images/wifi.png)
2023-02-27 17:01:27 +01:00
Join that Wifi and configure the device: http://192.164.4.1/
2023-02-27 17:01:27 +01:00
![Join Wifi](../images/configure-wifi.png)
2023-02-27 17:01:27 +01:00
You can configure it as a BlitzWolf SHP product.
2023-02-27 17:01:27 +01:00
Then it offers you power measurement and a programmable toogle.
![BlitzWolf](../images/blitzwolf.png)
2023-02-27 16:22:59 +01:00
It should be configurable just like our [plant monitor](../plant-monitor/README.md).
2023-02-27 17:01:27 +01:00
Just enable MQTT and enter a shorter telemetry period.
![MQTT](../images/mqtt.png) ![Telemetry period](../images/telemetry-period.png)
2023-02-27 17:01:27 +01:00
It will post MQTT messages unter a topic `tele/tasmota_891E97/SENSOR` like this one:
```
{
"Time": "2023-02-27T16:45:07",
"ENERGY": {
"TotalStartTime": "2023-02-27T16:33:06",
"Total": 0.004,
"Yesterday": 0,
"Today": 0.004,
"Period": 0,
"Power": 34,
"ApparentPower": 44,
"ReactivePower": 27,
"Factor": 0.79,
"Voltage": 253,
"Current": 0.172
}
}
```
We now can consume this messages in Node-RED, store them in InfluxDB and build a dashboard in Grafana.
2023-02-27 17:01:27 +01:00
### InfluxDB Bucket
2023-02-27 17:32:07 +01:00
I created a bucket called `shelly`in InfluxDB, so we can store the messages in this bucket.
2023-02-27 17:01:27 +01:00
### Node-RED
I create a usual flow in Node-RED. A MQTT node fetches the values.
2023-02-27 17:01:27 +01:00
![Node-RED](../images/node-red.png)
2023-02-27 17:01:27 +01:00
The message is fed into a filter function to only store usefull information:
2023-02-27 17:01:27 +01:00
```ini
2023-02-27 17:01:27 +01:00
return {
payload: {
power: Number(msg.payload.ENERGY.Power),
2023-02-27 17:21:01 +01:00
voltage: Number(msg.payload.ENERGY.Voltage),
2023-02-27 17:01:27 +01:00
current: Number(msg.payload.ENERGY.Current)
}
};
```
2023-02-27 17:01:27 +01:00
The `payload` will be stored in InfluxDB in the bucket "shelly".
### InfluxDB Data Explorer
In Influx DB Data Explorer you can query the stored data.
![Data Explorer](../images/data-explorer.png)
2023-02-27 17:01:27 +01:00
The query created by Data Explorer looks like that:
2023-02-27 17:01:27 +01:00
```flux
2023-02-27 17:01:27 +01:00
from(bucket: "shelly")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "msg")
2023-02-27 17:21:01 +01:00
|> filter(fn: (r) => r["_field"] == "power" or r["_field"] == "voltage" or r["_field"] == "current")
2023-02-27 17:01:27 +01:00
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "mean")
```
### Grafana
Using this query you can crate a dashboard in Grafana.
![Grafana](.../images/grafana.png)
2023-02-27 17:28:38 +01:00
## Links
- [Pinout for the ESP8266 based Shelly Plug-S Smart Plug
](https://faulty.cloud/blog/shelly-plug-s-pinout)
- [Youtube video: Upgrade Shelly Switches | Easy NO Soldering Smart Garage Door Opener](https://www.youtube.com/watch?v=_oRr8FZyyQ0)
- [mg2x](https://github.com/arendst/mgos-to-tasmota)
- [Shelly Plug S Power Monitoring Plug Tasmota template](https://templates.blakadder.com/shelly_plug_S.html)