Merge branch 'tmp' into dev

This commit is contained in:
hpanther
2020-10-30 13:57:52 +01:00
9 changed files with 420205 additions and 8 deletions

View File

@@ -1,7 +0,0 @@
# Configuration for weekly-digest - https://github.com/apps/weekly-digest
publishDay: sun
canPublishIssues: true
canPublishPullRequests: true
canPublishContributors: true
canPublishStargazers: true
canPublishCommits: true

419870
cscope.out Normal file

File diff suppressed because one or more lines are too long

9
doc/how-to Domoticz.txt Normal file
View File

@@ -0,0 +1,9 @@
Copy the nefit directory + its content to your ../domoticz/plugin directory
You can now select ""Nefit EMS-ESP with Proddy firmware" as new hardware in Domoticz
Don't forget to tick "accept new hardware devices" or click "allow for 5 minutes" in Settings first
Enter your MQTT server address and click "add"
The plugin will create 3 new devices:
- room temperature (as measured in the thermostat) under "temperature"
- system pressure under "utility"
- a device to set the thermostat (change temperature setting) under "utility"

113
doc/nefit/mqtt.py Normal file
View File

@@ -0,0 +1,113 @@
# Based on https://github.com/emontnemery/domoticz_mqtt_discovery
import Domoticz
import time
class MqttClient:
Address = ""
Port = ""
mqttConn = None
isConnected = False
mqttConnectedCb = None
mqttDisconnectedCb = None
mqttPublishCb = None
def __init__(self, destination, port, mqttConnectedCb, mqttDisconnectedCb, mqttPublishCb, mqttSubackCb):
Domoticz.Debug("MqttClient::__init__")
self.Address = destination
self.Port = port
self.mqttConnectedCb = mqttConnectedCb
self.mqttDisconnectedCb = mqttDisconnectedCb
self.mqttPublishCb = mqttPublishCb
self.mqttSubackCb = mqttSubackCb
self.Open()
def __str__(self):
Domoticz.Debug("MqttClient::__str__")
if (self.mqttConn != None):
return str(self.mqttConn)
else:
return "None"
def Open(self):
Domoticz.Debug("MqttClient::Open")
if (self.mqttConn != None):
self.Close()
self.isConnected = False
self.mqttConn = Domoticz.Connection(Name=self.Address, Transport="TCP/IP", Protocol="MQTT", Address=self.Address, Port=self.Port)
self.mqttConn.Connect()
def Connect(self):
Domoticz.Debug("MqttClient::Connect")
if (self.mqttConn == None):
self.Open()
else:
ID = 'Domoticz_'+str(int(time.time()))
Domoticz.Log("MQTT CONNECT ID: '" + ID + "'")
self.mqttConn.Send({'Verb': 'CONNECT', 'ID': ID})
def Ping(self):
Domoticz.Debug("MqttClient::Ping")
if (self.mqttConn == None or not self.isConnected):
self.Open()
else:
self.mqttConn.Send({'Verb': 'PING'})
def Publish(self, topic, payload, retain = 0):
Domoticz.Log("MqttClient::Publish " + topic + " (" + payload + ")")
if (self.mqttConn == None or not self.isConnected):
self.Open()
else:
self.mqttConn.Send({'Verb': 'PUBLISH', 'Topic': topic, 'Payload': bytearray(payload, 'utf-8'), 'Retain': retain})
def Subscribe(self, topics):
Domoticz.Debug("MqttClient::Subscribe")
subscriptionlist = []
for topic in topics:
subscriptionlist.append({'Topic':topic, 'QoS':0})
if (self.mqttConn == None or not self.isConnected):
self.Open()
else:
self.mqttConn.Send({'Verb': 'SUBSCRIBE', 'Topics': subscriptionlist})
def Close(self):
Domoticz.Log("MqttClient::Close")
#TODO: Disconnect from server
self.mqttConn = None
self.isConnected = False
def onConnect(self, Connection, Status, Description):
Domoticz.Debug("MqttClient::onConnect")
if (Status == 0):
Domoticz.Log("Successful connect to: "+Connection.Address+":"+Connection.Port)
self.Connect()
else:
Domoticz.Log("Failed to connect to: "+Connection.Address+":"+Connection.Port+", Description: "+Description)
def onDisconnect(self, Connection):
Domoticz.Log("MqttClient::onDisonnect Disconnected from: "+Connection.Address+":"+Connection.Port)
self.Close()
# TODO: Reconnect?
if self.mqttDisconnectedCb != None:
self.mqttDisconnectedCb()
def onMessage(self, Connection, Data):
topic = ''
if 'Topic' in Data:
topic = Data['Topic']
payloadStr = ''
if 'Payload' in Data:
payloadStr = Data['Payload'].decode('utf8','replace')
payloadStr = str(payloadStr.encode('unicode_escape'))
if Data['Verb'] == "CONNACK":
self.isConnected = True
if self.mqttConnectedCb != None:
self.mqttConnectedCb()
if Data['Verb'] == "SUBACK":
if self.mqttSubackCb != None:
self.mqttSubackCb()
if Data['Verb'] == "PUBLISH":
if self.mqttPublishCb != None:
self.mqttPublishCb(topic, Data['Payload'])

169
doc/nefit/plugin.py Normal file
View File

@@ -0,0 +1,169 @@
"""
<plugin key="nefit" name="Nefit EMS-ESP with Proddy firmware" version="0.0.1">
<description>
Plugin to control Nefit EMS-ESP with '<a href="https://github.com/proddy/EMS-ESP"> Proddy</a>' firmware<br/>
<br/>
Automatically creates Domoticz devices for connected device.<br/>
Do not forget to "Accept new Hardware Devices" on first run<br/>
</description>
<params>
<param field="Address" label="MQTT Server address" width="300px" required="true" default="127.0.0.1"/>
<param field="Port" label="Port" width="300px" required="true" default="1883"/>
<param field="Mode6" label="Debug" width="75px">
<options>
<option label="Extra verbose" value="Verbose+"/>
<option label="Verbose" value="Verbose"/>
<option label="True" value="Debug"/>
<option label="False" value="Normal" default="true" />
</options>
</param>
</params>
</plugin>
"""
import Domoticz
import json
import time
from mqtt import MqttClient
class Thermostat:
def checkDevices(self):
if 1 not in Devices:
Domoticz.Debug("Create Temperature Device")
Domoticz.Device(Name="Woonkamer", Unit=1, Type=80, Subtype=5).Create()
if 2 not in Devices:
Domoticz.Debug("Create System Pressure Device")
Domoticz.Device(Name="System Pressure", Unit=2, Type=243, Subtype=9).Create()
if 3 not in Devices:
Domoticz.Debug("Create Thermostat Device")
Domoticz.Device(Name="Nefit", Unit=3, Type=242, Subtype=1).Create()
def onMqttMessage(self, topic, payload):
if "sysPress" in payload:
pressure=payload["sysPress"]
Domoticz.Debug("System Pressure: {}".format(pressure))
Devices[2].Update(nValue=1, sValue=str(pressure))
if "currtemp" in payload:
temp=round(float(payload["currtemp"]),1)
Domoticz.Debug("Current temp: {}".format(temp))
if Devices[1].sValue != temp:
Devices[1].Update(nValue=1, sValue=str(temp))
if "seltemp" in payload:
temp=payload["seltemp"]
Domoticz.Debug("Temp setting: {}".format(temp))
if Devices[3].sValue != temp:
Devices[3].Update(nValue=1, sValue=str(temp))
def onCommand(self, mqttClient, unit, command, level, color):
topic = "ems-esp/thermostat_cmd"
if (command == "Set Level"):
#MQTT command syntax for setting the temperature: {"cmd":"temp", "data":<temp>, "hc":1}
cmdstr = chr(123) + chr(34) + "cmd" +chr(34) + ":" + chr(34) + "temp" + chr(34) + ", " #that's {"cmd":"temp",
cmdstr = cmdstr + chr(34) + "data" + chr(34) + ":" + str(level) +", " #that adds "data":<temp>,
cmdstr = cmdstr + chr(34) + "hc" + chr(34) + ":1" + chr(125) #that adds "hc":1}
mqttClient.Publish(topic, cmdstr)
class BasePlugin:
mqttClient = None
def onStart(self):
self.debugging = Parameters["Mode6"]
if self.debugging == "Verbose+":
Domoticz.Debugging(2+4+8+16+64)
if self.debugging == "Verbose":
Domoticz.Debugging(2+4+8+16+64)
if self.debugging == "Debug":
Domoticz.Debugging(2+4+8)
self.controller = Thermostat()
self.controller.checkDevices()
self.topics = list(["ems-esp/thermostat_data1", "ems-esp/boiler_data", "ems-esp/STATE"])
self.mqttserveraddress = Parameters["Address"].replace(" ", "")
self.mqttserverport = Parameters["Port"].replace(" ", "")
self.mqttClient = MqttClient(self.mqttserveraddress, self.mqttserverport, self.onMQTTConnected, self.onMQTTDisconnected, self.onMQTTPublish, self.onMQTTSubscribed)
def checkDevices(self):
Domoticz.Log("checkDevices called")
def onStop(self):
Domoticz.Log("onStop called")
def onCommand(self, Unit, Command, Level, Color):
Domoticz.Debug("Command: " + Command + " (" + str(Level))
self.controller.onCommand(self.mqttClient, Unit, Command, Level, Color)
def onConnect(self, Connection, Status, Description):
self.mqttClient.onConnect(Connection, Status, Description)
def onDisconnect(self, Connection):
self.mqttClient.onDisconnect(Connection)
def onMessage(self, Connection, Data):
self.mqttClient.onMessage(Connection, Data)
def onHeartbeat(self):
Domoticz.Debug("Heartbeating...")
# Reconnect if connection has dropped
if self.mqttClient.mqttConn is None or (not self.mqttClient.mqttConn.Connecting() and not self.mqttClient.mqttConn.Connected() or not self.mqttClient.isConnected):
Domoticz.Debug("Reconnecting")
self.mqttClient.Open()
else:
self.mqttClient.Ping()
def onMQTTConnected(self):
Domoticz.Debug("onMQTTConnected")
self.mqttClient.Subscribe(self.topics)
def onMQTTDisconnected(self):
Domoticz.Debug("onMQTTDisconnected")
def onMQTTSubscribed(self):
Domoticz.Debug("onMQTTSubscribed")
def onMQTTPublish(self, topic, rawmessage):
Domoticz.Debug("MQTT message: " + topic + " " + str(rawmessage))
message = ""
try:
message = json.loads(rawmessage.decode('utf8'))
except ValueError:
message = rawmessage.decode('utf8')
if (topic in self.topics):
self.controller.onMqttMessage(topic, message)
global _plugin
_plugin = BasePlugin()
def onStart():
global _plugin
_plugin.onStart()
def onStop():
global _plugin
_plugin.onStop()
def onConnect(Connection, Status, Description):
global _plugin
_plugin.onConnect(Connection, Status, Description)
def onDisconnect(Connection):
global _plugin
_plugin.onDisconnect(Connection)
def onMessage(Connection, Data):
global _plugin
_plugin.onMessage(Connection, Data)
def onCommand(Unit, Command, Level, Color):
global _plugin
_plugin.onCommand(Unit, Command, Level, Color)
def onHeartbeat():
global _plugin
_plugin.onHeartbeat()

3
pio_local.ini.txt Normal file
View File

@@ -0,0 +1,3 @@
upload_protocol = espota
upload_flags = --port=8266 --auth=ems-esp-neo
upload_port = ems-esp.local

BIN
src/.emsdevice.cpp.swp Normal file

Binary file not shown.

View File

@@ -17,6 +17,7 @@
*/ */
#include "solar.h" #include "solar.h"
#include "emsesp.h"
namespace emsesp { namespace emsesp {
@@ -45,7 +46,12 @@ Solar::Solar(uint8_t device_type, uint8_t device_id, uint8_t product_id, const s
register_telegram_type(0x0364, F("SM100Status"), false, [&](std::shared_ptr<const Telegram> t) { process_SM100Status(t); }); register_telegram_type(0x0364, F("SM100Status"), false, [&](std::shared_ptr<const Telegram> t) { process_SM100Status(t); });
register_telegram_type(0x036A, F("SM100Status2"), false, [&](std::shared_ptr<const Telegram> t) { process_SM100Status2(t); }); register_telegram_type(0x036A, F("SM100Status2"), false, [&](std::shared_ptr<const Telegram> t) { process_SM100Status2(t); });
register_telegram_type(0x038E, F("SM100Energy"), true, [&](std::shared_ptr<const Telegram> t) { process_SM100Energy(t); }); register_telegram_type(0x038E, F("SM100Energy"), true, [&](std::shared_ptr<const Telegram> t) { process_SM100Energy(t); });
} register_telegram_type(0x035A, F("SM100Tank1MaxTemp"), false, [&](std::shared_ptr<const Telegram> t) { process_SM100Tank1MaxTemp(t); });
// EMSESP::send_read_request(0x035A, device_id);
// This is a hack right now, need to update TXService to support sending F9 packets
uint8_t msg[]="8B B0 F9 00 11 FF 02 5A 03 00";
msg[sizeof(msg)-2] = EMSESP::rxservice_.calculate_crc(msg, sizeof(msg)-2);
EMSESP::send_raw_telegram((const char*)msg);
} }
if (flags == EMSdevice::EMS_DEVICE_FLAG_ISM) { if (flags == EMSdevice::EMS_DEVICE_FLAG_ISM) {
@@ -66,6 +72,7 @@ void Solar::device_info_web(JsonArray & root) {
print_value_json(root, F("collectorTemp"), nullptr, F_(collectorTemp), F_(degrees), json); print_value_json(root, F("collectorTemp"), nullptr, F_(collectorTemp), F_(degrees), json);
print_value_json(root, F("tankBottomTemp"), nullptr, F_(tankBottomTemp), F_(degrees), json); print_value_json(root, F("tankBottomTemp"), nullptr, F_(tankBottomTemp), F_(degrees), json);
print_value_json(root, F("tankBottomTemp2"), nullptr, F_(tankBottomTemp2), F_(degrees), json); print_value_json(root, F("tankBottomTemp2"), nullptr, F_(tankBottomTemp2), F_(degrees), json);
print_value_json(root, F("tank1MaxTemp"), nullptr, F_(tank1MaxTempCurrent_*10), F_(degrees), json);
print_value_json(root, F("heatExchangerTemp"), nullptr, F_(heatExchangerTemp), F_(degrees), json); print_value_json(root, F("heatExchangerTemp"), nullptr, F_(heatExchangerTemp), F_(degrees), json);
print_value_json(root, F("solarPumpModulation"), nullptr, F_(solarPumpModulation), F_(percent), json); print_value_json(root, F("solarPumpModulation"), nullptr, F_(solarPumpModulation), F_(percent), json);
print_value_json(root, F("cylinderPumpModulation"), nullptr, F_(cylinderPumpModulation), F_(percent), json); print_value_json(root, F("cylinderPumpModulation"), nullptr, F_(cylinderPumpModulation), F_(percent), json);
@@ -100,6 +107,7 @@ void Solar::show_values(uuid::console::Shell & shell) {
print_value_json(shell, F("collectorTemp"), nullptr, F_(collectorTemp), F_(degrees), json); print_value_json(shell, F("collectorTemp"), nullptr, F_(collectorTemp), F_(degrees), json);
print_value_json(shell, F("tankBottomTemp"), nullptr, F_(tankBottomTemp), F_(degrees), json); print_value_json(shell, F("tankBottomTemp"), nullptr, F_(tankBottomTemp), F_(degrees), json);
print_value_json(shell, F("tankBottomTemp2"), nullptr, F_(tankBottomTemp2), F_(degrees), json); print_value_json(shell, F("tankBottomTemp2"), nullptr, F_(tankBottomTemp2), F_(degrees), json);
print_value_json(shell, F("tank1MaxTemp"), nullptr, F_(tank1MaxTempCurrent_*10), F_(degrees), json);
print_value_json(shell, F("heatExchangerTemp"), nullptr, F_(heatExchangerTemp), F_(degrees), json); print_value_json(shell, F("heatExchangerTemp"), nullptr, F_(heatExchangerTemp), F_(degrees), json);
print_value_json(shell, F("solarPumpModulation"), nullptr, F_(solarPumpModulation), F_(percent), json); print_value_json(shell, F("solarPumpModulation"), nullptr, F_(solarPumpModulation), F_(percent), json);
print_value_json(shell, F("cylinderPumpModulation"), nullptr, F_(cylinderPumpModulation), F_(percent), json); print_value_json(shell, F("cylinderPumpModulation"), nullptr, F_(cylinderPumpModulation), F_(percent), json);
@@ -203,6 +211,10 @@ bool Solar::export_values(JsonObject & json) {
json["tankBottomTemp2"] = (float)tankBottomTemp2_ / 10; json["tankBottomTemp2"] = (float)tankBottomTemp2_ / 10;
} }
if (Helpers::hasValue(tank1MaxTempCurrent_)) {
doc["tankMaximumTemp"] = tank1MaxTempCurrent_;
}
if (Helpers::hasValue(heatExchangerTemp_)) { if (Helpers::hasValue(heatExchangerTemp_)) {
json["heatExchangerTemp"] = (float)heatExchangerTemp_ / 10; json["heatExchangerTemp"] = (float)heatExchangerTemp_ / 10;
} }
@@ -268,6 +280,29 @@ void Solar::process_SM10Monitor(std::shared_ptr<const Telegram> telegram) {
changed_ |= telegram->read_value(pumpWorkMin_, 8, 3); changed_ |= telegram->read_value(pumpWorkMin_, 8, 3);
} }
/*
* process_SM100Tank1MaxTemp - type 0x035A EMS+ - for MS/SM100 and MS/SM200
* e.g. B0 10 F9 00 FF 02 5A 03 17 00 00 00 14 00 00 00 3C 00 00 00 5A 00 00 00 59 29 - requested with 90 B0 F9 00 11 FF 02 5A 03 AF
* bytes 0-1 = packet format designator
* bytes 2..5 = minimum value
* bytes 6..9 = default value
* bytes 10..13 = maximum value
* bytes 14..17 = current value
* e.g, FD 3F - requested with 90 B0 F7 00 FF FF 02 5A B0
*/
void Solar::process_SM100Tank1MaxTemp(std::shared_ptr<const Telegram> telegram) {
int16_t designator;
telegram->read_value(designator, 0);
LOG_DEBUG(F("SM100Tank1MaxTemp designator 0x%02X"), designator);
if(designator==0x0317) // The telegram has the right form
{
changed_ |= telegram->read_value(tank1MaxTempMinimum_, 2);
changed_ |= telegram->read_value(tank1MaxTempDefault_, 6);
changed_ |= telegram->read_value(tank1MaxTempMaximum_, 10);
changed_ |= telegram->read_value(tank1MaxTempCurrent_, 14);
}
}
/* /*
* SM100Monitor - type 0x0362 EMS+ - for MS/SM100 and MS/SM200 * SM100Monitor - type 0x0362 EMS+ - for MS/SM100 and MS/SM200
* e.g. B0 0B FF 00 02 62 00 77 01 D4 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 00 F9 80 00 80 9E - for heat exchanger temp * e.g. B0 0B FF 00 02 62 00 77 01 D4 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 00 F9 80 00 80 9E - for heat exchanger temp

View File

@@ -46,6 +46,10 @@ class Solar : public EMSdevice {
static uuid::log::Logger logger_; static uuid::log::Logger logger_;
void register_mqtt_ha_config(bool force); void register_mqtt_ha_config(bool force);
uint32_t tank1MaxTempMinimum_ = EMS_VALUE_ULONG_NOTSET; // Min value for max tank temp
uint32_t tank1MaxTempDefault_ = EMS_VALUE_ULONG_NOTSET; // Default value for max tank temp
uint32_t tank1MaxTempMaximum_ = EMS_VALUE_ULONG_NOTSET; // Max value for max tank temp
uint32_t tank1MaxTempCurrent_ = EMS_VALUE_ULONG_NOTSET; // Current value for max tank temp
int16_t collectorTemp_ = EMS_VALUE_SHORT_NOTSET; // TS1: Temperature sensor for collector array 1 int16_t collectorTemp_ = EMS_VALUE_SHORT_NOTSET; // TS1: Temperature sensor for collector array 1
int16_t tankBottomTemp_ = EMS_VALUE_SHORT_NOTSET; // TS2: Temperature sensor 1 cylinder, bottom (solar thermal system) int16_t tankBottomTemp_ = EMS_VALUE_SHORT_NOTSET; // TS2: Temperature sensor 1 cylinder, bottom (solar thermal system)
int16_t tankBottomTemp2_ = EMS_VALUE_SHORT_NOTSET; // TS5: Temperature sensor 2 cylinder, bottom, or swimming pool (solar thermal system) int16_t tankBottomTemp2_ = EMS_VALUE_SHORT_NOTSET; // TS5: Temperature sensor 2 cylinder, bottom, or swimming pool (solar thermal system)
@@ -70,6 +74,7 @@ class Solar : public EMSdevice {
bool mqtt_ha_config_ = false; // for HA MQTT Discovery bool mqtt_ha_config_ = false; // for HA MQTT Discovery
void process_SM10Monitor(std::shared_ptr<const Telegram> telegram); void process_SM10Monitor(std::shared_ptr<const Telegram> telegram);
void process_SM100Tank1MaxTemp(std::shared_ptr<const Telegram> telegram);
void process_SM100Monitor(std::shared_ptr<const Telegram> telegram); void process_SM100Monitor(std::shared_ptr<const Telegram> telegram);
void process_SM100Monitor2(std::shared_ptr<const Telegram> telegram); void process_SM100Monitor2(std::shared_ptr<const Telegram> telegram);