- platform: homeassistant
name: "Total Power from SmartMeter"
entity_id: sensor.sdm72d_m_system_power_total # Power Entity from SmartMeter
on_value:
then:
- logger.log:
level: DEBUG
format: 'Power value changed from %d to %d Deziwatt [dW]'
args: ['id(power_t0)', 'int(x*10.0)']
- globals.set:
id: power_t0
value: !lambda 'return int(x*10.0);'
interval:
- interval: 1s
then:
- lambda: !lambda |-
ESP_LOGD("main", "Growatt AC Power: %f ", id(GrowattPower));
int16_t powerOffset = 500; // Export offset (-50 W)
int16_t powerMax = 10000; // 6000 dW = 600 W (if Growatt MIC 600TL-X)
static int16_t relOutputPower = 10; // Max output active power (0 - 100 %) // 10 % => ~60 W (if Growatt MIC 600TL-X)
static int16_t calOutputPower = 0;
static int16_t consumePower = 0;
static int16_t GroPower = 0;
static int16_t PowerSet = 0;
relOutputPower = id(power_t0)/100 + id(GrowattPower) / powerMax * 1000;
calOutputPower = id(power_t0)/100 + id(GrowattPower) / powerMax * 1000;
consumePower = id(power_t0)/10 + id(GrowattPower);
PowerSet = relOutputPower / 1000.0 * powerMax;
if (relOutputPower > 100) relOutputPower = 100.0; // Maximum should be allways 100 %
if (relOutputPower < 0) relOutputPower = 0; // Ensure non-negative value
PowerSet = relOutputPower / 1000.0 * powerMax;
ESP_LOGD("main", "Relative Output Power: %d percent", relOutputPower);
ESP_LOGD("main", "Calculated Output Power: %d percent", calOutputPower);
ESP_LOGD("main", "Set Output Power to: %d Watt", PowerSet);
ESP_LOGD("main", "Real Consumed Power: %d Watt", consumePower);
esphome::modbus_controller::ModbusController *controller = id(growatt);
uint16_t reg = 3; // Register: Max output active power (in %)
modbus_controller::ModbusCommandItem setOutputPower_command = modbus_controller::ModbusCommandItem::create_write_single_command(controller, reg, relOutputPower);
controller->queue_command(setOutputPower_command);