Servus miteinander,
ich hab vor kurzem unseren Deye 12k installieren lassen und wollte diesen natürlich in unser SmartHome (iobroker) einbinden. Readonly war das Ganze auch keinerlei Problem.
Einfach einen ESP32 mit Modbus-Adapter auf Lochraster gelötet, ein kleines Display dazu, das Ganze in ein Hutschienen-Leergehäuse gepackt, verdrahtet, ESPHome drauf und fertig. Easy going
Nur der Schreib-Anteil (WR Konfiguration aus dem iobroker heraus anpassen) war nicht ganz trivial - hier ist die Einbindung von MQTT bzw. ESPHome in iobroker noch nicht so ganz toll.
Den ESPHome Adapter in iobroker wollte ich nicht verwenden, da dieser noch nicht "stable" ist und anscheinend auch nicht mehr aktiv maintained wird. Deswegen - plain MQTT.
ESPHome hat die kleine Eigenheit, dass gelesene Werte unter topic_name/state
landen. Will man einen Wert beschreiben, muss man topic_name/command
ansprechen & befüllen.
Direkt aus der Visualisierung aus IOBroker heraus ist das Ganze so leider nicht kompatibel - deswegen musste ich mir mit einem kleinen Script weiterhelfen. Selbiges tut genau das - alle relevanten /state
topics mittels standard-iobroker-Funktionen auslesen, den wert aus /state
in /command
schreiben mittels sendTo('mqtt...
und somit die Grundlage für die Verwendung in der Visualisierung zu legen.
Vielleicht kanns ja noch jemand brauchen - deswegen hier das iobroker Script.
Gruezie
Domi
/*
Copyright © 2025 DaDomi / ScrewThisBanana
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Author: ScrewThisBanana
*
* This script for IO Broker is a simple solution to enable iobroker setting configuration entries in a deye inverter
* connected via ESPHome + Modbus Adapter
*
* Prerequisites:
* Working MQTT Server (e. g. Mosquitto)
* Connected ESPHome Device (via MQTT)
* Working MQTT Client in IOBroker
*
* Description:
* This script reads all ".state" entries from the mqtt adapters states
* Foreach found ".state", a new ".command" state is sent to mqtt (containing the current value from ".state" to
* prevent overwriting things in the inverter). This ".command" state now enables other adapters writing values
* to ESPHome
*/
schedule('*/60 * * * *', run);
function run(){
$("mqtt.0.deye12.**.state").each(item => // iterate over all deye state entries
addCommandId(item)
.catch(reason => log(
JSON.stringify(reason))
)
);
};
async function addCommandId(stateId: string){
let itemId = stateId.substring(0, stateId.length - ".state".length); // remove .state
let commandId = itemId+".command"; // add .command
if($(commandId).length == 0){ // create "command" topic if it does not yet exist
let state = await $(stateId).getStateAsync();
if(!commandId.includes(".homeassistant.")
&& (commandId.includes('.number.') || commandId.includes(".select."))){ // create command for numbers & selects - other datapoints are readonly
let topic = commandId.substring("mqtt.0.".length).replaceAll(".", "/"); // topic = my/topic, not mqtt.0.my.topic
log(topic);
sendTo('mqtt.0', 'sendMessage2Client', {topic: topic, message: state.val});
}
}
}