Demand Shaper/MQTT Help

I read on twitter about a smart plug and I was intrigued. I wondered if I could integrate into emoncms. I read about Demand Shaper and was more intrigued.

I bought one of these: https://kettlecompanion.com/product/power-metering-smart-plug/
because a couple of people on twitter had them for energy monitoring.

It runs tasmota. Tasmota control a sonof smart switch, but I don’t know how similar that is to this one’s default configuration 2nice up111.

I’ve connected it to my network and can control it.

I’ve read various guides on the openenergymonitor website, e.g.

Quoting:

Installation Options:

  1. Use pre-built emonSD SD card image for a RaspberryPi
    Download the latest image here:
    emonSD pre built SD card Download & Change Log · openenergymonitor/emonpi Wiki · GitHub
  2. Install full emoncms system including demandshaper module using EmonScripts
    Just run our automated emoncms installation script on a target system of choice, see:
    GitHub - openenergymonitor/EmonScripts: Emoncms Stack Installation and Update scripts
  3. Install demandshaper module within an existing emoncms installation

I have an emonpi. I’ve got an up to date copy of the master branch installed, so that seems that option 1 is where I’m at, but I looked at https://github.com/emoncms/demandshaper/blob/master/docs/manual-install.md

I didn’t do the steps listed, but as far as I could see, there’s a copy of demandshaper installed, and I assume it’s up-to-date as my installed master branch is up-to-date.

The last step

Optional: Enable the periodic UDP broadcast script on the emonbase/emonpi:

crontab -e
* * * * * php /opt/openenergymonitor/emonpi/UDPBroadcast/broadcast.php 2>&1

doesn’t see to be in place, but I don’t know if it’s important.

I then followed https://guide.openenergymonitor.org/integrations/demandshaper-sonoff/

As I said, I’ve got the plug connected to my network, and can control it by its webpage that appears if I browse to its IP address.

So, skipping down to

Pairing the Smart Plug with your emonBase/emonPi

I’ve sat and waited a while for the plug to appear on the demand shaper page, but it doesn’t.
Now, I expect that the most likely reason is that I haven’t set up the plug properly. Also, I don’t know much about the mosquito protocol (MQTT) that runs it, but I am wondering if I need to change how it is installed.

I believe a “broker” is needed to communicate between the smartplug and the emoncms.

I can see though running

ps -Af | grep “mosquitto”

in a ssh shell, that mosquitto is running, presumably as a broker. I get

/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Looking around the openenergymonitor pages some more, I found
https://guide.openenergymonitor.org/technical/mqtt/

Testing mqtt, I installed mosquitto-clients both on my linux laptop and on emonpi.

running

mosquitto_sub -v -u ‘emonpi’ -P ‘emonpimqtt2016’ -t ‘emon/#’

on the pi and

mosquitto_sub -h IP_ADDRESS -v -u ‘emonpi’ -P ‘emonpimqtt2016’ -t ‘emon/#’

on my laptop (with the Pi’s IP address substituted) shows temperatures, power, vrms etc so it seems to be working.

I’ve tweaked the smartplug’s mqtt base topic and full topic to “emon” and “emon/emonesp” respectively, as I found in one mqtt.cpp from the smartplug firmware at https://github.com/openenergymonitor/EmonESP

However, in the same git, sonoff.md says to control the plug using

emon/smartplug1/status

I know the plug is publishing to the emoncms mosquito, due to this heavily cut sample from the command line.

mosquitto_sub -v -u ‘emonpi’ -P ‘emonpimqtt2016’ -t ‘emon/#’
emon/emonesp/LWT Offline
emon/emonpi/power1 248
emon/emonpi/t1 19.900000000000002
emon/emonesp/LWT Online
emon/emonesp/cmnd/POWER (null)
emon/emonesp/INFO1 {“Info1”:{“Module”:“2NICE UP111”,“Version”:“12.1.1(tasmota)”,“FallbackTopic”:“cmnd/DVES_B186E8_fb/”,“GroupTopic”:“emon/emonesp/cmnd/”}}
emon/emonesp/INFO2 {“Info2”:{“WebServerMode”:“Admin”,“Hostname”:“emon-1768”,“IPAddress”:“192.168.0.51”}}
emon/emonesp/INFO3 {“Info3”:{“RestartReason”:“Software/System restart”,“BootCount”:30}}
emon/emonesp/RESULT {“POWER”:“OFF”}
emon/emonesp/POWER OFF
emon/emonpi/power1 252
emon/emonpi/t1 19.900000000000002
emon/emonesp/STATE {“Time”:“2022-10-19T22:59:56”,“Uptime”:“0T00:00:10”,“UptimeSec”:10,“Heap”:26,“SleepMode”:“Dynamic”,“Sleep”:50,“LoadAvg”:19,“MqttCount”:1,“POWER”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“CheezyWhatsits”,“BSSId”:“30:23:03:DF:F4:41”,“Channel”:2,“Mode”:“11n”,“RSSI”:58,“Signal”:-71,“LinkCount”:1,“Downtime”:“0T00:00:03”}}
emon/emonesp/SENSOR {“Time”:“2022-10-19T22:59:56”,“ENERGY”:{“TotalStartTime”:“2022-10-16T14:23:25”,“Total”:0.008,“Yesterday”:0.000,“Today”:0.008,“Period”: 0,“Power”: 0,“ApparentPower”: 0,“ReactivePower”: 0,“Factor”:0.00,“Voltage”: 0,“Current”:0.000}}
emon/emonpi/power1 255
emon/emonpi/t1 20
emon/emonesp/RESULT {“POWER”:“ON”}
emon/emonesp/POWER ON
emon/emonesp/RESULT {“POWER”:“OFF”}
emon/emonesp/POWER OFF

As you can see, some pi settings (many deleted), and some emon/emonesp settings, including when I manually turn it on and off.

Are my mqtt topics right in the plug?
If so, why doesn’t it show up in DemandShaper?
How can I make it appear in DemandShaper?
Or is this impossible?

Any help much appreciated.

Steve

I asked something similar in DemandShaper new device integration - #9 by mjr but got nowhere, so I installed domoticz to control the switches and it works, more or less.