Skip to content

Commit

Permalink
[Request] Show actual power limiter state in live view #134
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Mar 10, 2023
1 parent 7952bec commit 01a2ffa
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 5 deletions.
8 changes: 5 additions & 3 deletions include/PowerLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@
#include <Hoymiles.h>
#include <memory>

enum PowerLimiterStates {
typedef enum {
STATE_DISCOVER = 0,
STATE_OFF,
STATE_CONSUME_SOLAR_POWER_ONLY,
STATE_NORMAL_OPERATION
};
} plStates;


class PowerLimiterClass {
public:
void init();
void loop();
plStates getPowerLimiterState();
uint16_t getLastRequestedPowewrLimit();
void onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total);

private:
uint32_t _lastCommandSent;
uint32_t _lastLoop;
uint32_t _lastPowerMeterUpdate;
uint16_t _lastRequestedPowerLimit;
u_int8_t _plState = STATE_DISCOVER;
plStates _plState = STATE_DISCOVER;

float _powerMeter1Power;
float _powerMeter2Power;
Expand Down
8 changes: 8 additions & 0 deletions src/PowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ void PowerLimiterClass::loop()
}
}

plStates PowerLimiterClass::getPowerLimiterState() {
return _plState;
}

uint16_t PowerLimiterClass::getLastRequestedPowewrLimit() {
return _lastRequestedPowerLimit;
}

bool PowerLimiterClass::canUseDirectSolarPower()
{
CONFIG_T& config = Configuration.get();
Expand Down
8 changes: 8 additions & 0 deletions src/WebApi_ws_vedirect_live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "MessageOutput.h"
#include "WebApi.h"
#include "defaults.h"
#include "PowerLimiter.h"

WebApiWsVedirectLiveClass::WebApiWsVedirectLiveClass()
: _ws("/vedirectlivedata")
Expand Down Expand Up @@ -120,6 +121,13 @@ void WebApiWsVedirectLiveClass::generateJsonResponse(JsonVariant& root)
root["H23"]["v"] = VeDirect.veFrame.H23;
root["H23"]["u"] = "W";

// power limiter state
if (Configuration.get().PowerLimiter_Enabled)
root["PLSTATE"] = PowerLimiter.getPowerLimiterState();
else
root["PLSTATE"] = -1;
root["PLLIMIT"] = PowerLimiter.getLastRequestedPowewrLimit();

if (VeDirect.getLastUpdate() > _newestVedirectTimestamp) {
_newestVedirectTimestamp = VeDirect.getLastUpdate();
}
Expand Down
31 changes: 31 additions & 0 deletions webapp/src/components/VedirectView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@
</div>
</div>
</div>
<div class="btn-group me-2" role="group">
<button type="button"
class="btn btn-sm" v-tooltip :title="$t('vedirecthome.PowerLimiterState')">
<div v-if="vedirectData.PLSTATE == 0">
<BIconXCircleFill style="font-size:24px;" />
</div>
<div v-else-if="vedirectData.PLSTATE == 1">
<BIconBatteryCharging style="font-size:24px;" />
</div>
<div v-else-if="vedirectData.PLSTATE == 2">
<BIconSun style="font-size:24px;" />
</div>
<div v-else-if="vedirectData.PLSTATE == 3">
<BIconBatteryHalf style="font-size:24px;" />
</div>
<span v-if="vedirectData.PLSTATE != -1"
class="position-absolute top-0 start-100 translate-middle badge rounded-pill text-bg-info">
{{ vedirectData.PLLIMIT }} W
</span>
</button>
</div>
</div>
<div class="card-body">
<div class="row flex-row flex-wrap align-items-start g-3">
Expand Down Expand Up @@ -178,10 +199,20 @@
import { defineComponent } from 'vue';
import type { Vedirect } from '@/types/VedirectLiveDataStatus';
import { handleResponse, authHeader, authUrl } from '@/utils/authentication';
import {
BIconSun,
BIconBatteryCharging,
BIconBatteryHalf,
BIconXCircleFill
} from 'bootstrap-icons-vue';
export default defineComponent({
components: {
BIconSun,
BIconBatteryCharging,
BIconBatteryHalf,
BIconXCircleFill
},
data() {
return {
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
"YieldToday": "Ertrag heute",
"MaximumPowerToday": "Maximale Leistung heute",
"YieldYesterday": "Ertrag gestern",
"MaximumPowerYesterday": "Maximale Leistung gestern"
"MaximumPowerYesterday": "Maximale Leistung gestern",
"PowerLimiterState": "Power limiter Status [aus (laden), nur die Sonne nutzen, Nutzung der Batterie]"
},
"eventlog": {
"Start": "Begin",
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
"YieldToday": "Yield today",
"MaximumPowerToday": "Maximum power today",
"YieldYesterday": "Yield yesterday",
"MaximumPowerYesterday": "Maximum power yesterday"
"MaximumPowerYesterday": "Maximum power yesterday",
"PowerLimiterState": "Power limiter state [off (charging), solar passthrough, on battery]"
},
"eventlog": {
"Start": "Start",
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/types/VedirectLiveDataStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ export interface Vedirect {
H21: ValueObject;
H22: ValueObject;
H23: ValueObject;
PLSTATE: number;
PLLIMIT: number;
}

0 comments on commit 01a2ffa

Please sign in to comment.