rasProject_01 / weSweetHome  R. 146 2026-09-26
process control       /     RasPi software         by   weinert-automation
Loading...
Searching...
No Matches
sweetHome2.c File Reference

Common variables and functions for an smart home lab project. More...

#include "sweetHome2.h"
#include "sweetHomeLocal.h"

Functions

void batCntBalStatChg (state_t *const me)
 Battery as controlled ballast SFC state changes.
void batCntLodStatChg (state_t *const me)
 Battery controlled load - SFC state changes.
void batKeepInhTimChg (state_t *const me)
 Inhibit battery keep alive loading timer state change function.
void batUnloadStatChg (state_t *const me)
 Battery unload SFC state changes.
void befRiseTimChg (state_t *const me)
 Before sunrise timer state change callback.
void changeBatLoadPWM (int pwmChg)
 Change battery loader module PWM.
void dawnTimChg (state_t *const me)
 Dawn timer state change callback.
void duskTimChg (state_t *const me)
 Dusk timer state change callback.
void genSunStateText (char *stateText, state_t const *const me, char const *stamp)
 Generate the sun's status text.
void logBatteryState ()
 Log battery state on outLog as line with time stamp.
void mqttClean ()
 End as MQTT client.
int mqttInit ()
 Initialise as MQTT client.
void mqttPlg01Set (uint8_t const on)
 Switch the plug Plug01.
void mqttPlg02Set (uint8_t const on)
 Switch the plug PLG2.
void mqttPlg03Set (uint8_t const on)
 Switch the plug PLG3.
void mqttPlg04Set (uint8_t const on)
 Switch the plug PLG4.
uint8_t pckSwPec (float power)
 Set and get package switch percentage by power.
void setBatLoadPWM (int const pwm)
 Set battery loader module PWM.
void setConsGiv (state_t *const me)
 Power consumer / producer (give away) SFC transition.
uint8_t setPckSwPerc (uint8_t perc)
 Set package switch percentage.
float setPhPckLimit (float powerLimit)
 Set and get package switch power limit.
void solPowStateText (char *stateText, state_t const *const me, char const *stamp)
 Generate solar power status text.
void startBatBallLoad (char const *startCommand)
 Start battery ballast load operation.
void startBatteryKeep (char const *startCommand)
 Start battery keep operation.
void startBatteryLoad (char const *startCommand)
 Start battery normal load operation.
void startBatteryUnl (char const *startCommand)
 Start battery unload operation.
void stopBatteryOps (char const *stopCommand)
 Stop any battery load or unload operation.
void sunriseTimChg (state_t *const me)
 Sunrise timer state change callback.
void sunsetTimChg (state_t *const me)
 Sunset timer state change callback.
void surplStateText (char *stateText, state_t const *const me, char const *stamp)
 Generate surplus power status text.
void switchBatToStepUp (uint8_t const on)
 Switch battery to step up converter.
void switchConsGiv (state_t *const me)
 Power consumer / producer (give away) transition.
void switchHotWpump (uint8_t const on)
 Hot water comfort pump turn on/off.
void switchSolPow (state_t *const me)
 Solar power producer transition.
void switchWouldGiv250W (state_t *const me)
 Would give 250W or more away, the transition.
void switchWouldGivAway (state_t *const me)
 Would give away transition.
unsigned int unldAllowed ()
 Is battery unload allowed by battery state.

Variables

state_t batBalLodSeq
 Battery controlled load as ballast.
state_t batCntLodSeq
 Battery loading and keeping.
state_t batKeepInh
 Inhibit battery keep alive loading.
int batLoadAllowed
 Battery loading allowed.
float batLoadPower
 Battery charging power when valid.
uint8_t batLoadPowValid
 Battery charging power is valid.
volatile int batModPWM
 The actual battery load module's PWM input.
int batUnloadAllowed
 Battery unload allowed.
state_t batUnloadSeq
 Battery controlled unload via inverter.
uint8_t batVoltValid
 The measured battery voltage is valid.
state_t befRiseTimer
 Before sunrise timer.
char clientId [38]
 MQTT client ID.
state_t consumeGiveHyst
 Give away hysteresis.
state_t consumeGiveSFC
 Give away state machine / SFC.
state_t dawnTimer
 Dawn timer.
state_t duskTimer
 Dusk timer.
uint8_t heaterAllowed
 phase packet load enabled (always)
int hippoSwitchMode
 Hippogreiff on/off times.
uint16_t hundredsV
 The battery voltage in 0.01V units.
volatile uint16_t logBatStrCnt
 counter to log battery state if < 3
char messCmdOffPlg [4]
 Message to turn a S20 plug off.
char messCmdOnPlg [4]
 Message to turn a S20 plug on.
char messSttOffPlg [6]
 State message: a S20 plug is now off.
char messSttOnPlg [6]
 State message: a S20 plug is now on.
struct mosquitto * mosq
 MQTT interface state.
int mosqLoopError
 Return value of mosquitto_loop.
char mqttHost [68]
 MQTT broker address or name.
int mqttPort
 MQTT broker port.
volatile uint nologBatCap
 Control logging inhibit charging battery due to capacity limit.
volatile uint8_t phPckCnt
 current switch state duration counter
volatile uint8_t phPckOff
 current phase packet switch OFF duration
volatile uint8_t phPckOn
 current phase packet switch ON duration
volatile uint8_t phPckRelOffDelay
 PPS relay off delay.
volatile uint8_t phPckS2
 heater 2 pps switch state: 0 off; 1 on
volatile uint8_t phPckSw
 phase packet switch state: 0 off; 1 on
volatile uint8_t phPckSwIndex
 Actual index (0..200%) determining power.
volatile uint8_t phPpow2
 heater 2 power * 50% (0:0% .. 2:100%)
float pStdW
 actual power delivery to home
oneWireDevice_t sensors [NUM1W_SENSORS]
 The 1-wire sensors used.
state_t solarPowerHyst
 Solar power producer hysteresis.
char const subTopBatU [10]
 Relative topic to subscribe Ubat (bat/volt).
char const subTopEco3 [14]
 Relative topic for topic for EcoWorthy BT readings.
char const subTopGrow [14]
 Relative topic for Growatt readings.
char subTopStPlg01 [14]
 State sub topic of S20 plug Number 01 to 09.
state_t sunriseTimer
 Sunrise timer.
state_t sunsetTimer
 Sunset timer.
uint16_t tenPromSoC
 The battery state of charge or SOC in 0.01% units.
char const topicSubs [20]
 The MQTT topic to subscribe to.
state_t wouldGive250WHyst
 Would give away 250W hysteresis.
state_t wouldGiveAwayHyst
 Would give away hysteresis.

Detailed Description

Common variables and functions for an smart home lab project.

Copyright (c) 2018 - 2026 Albrecht Weinert
weinert-automation.de a-weinert.de
/ / /\
/ /___ / \ |
\ /____\ /____\ | _|__
\ /\ / \ / \| |
\/ \/ \__/ \__/|_

Revision history

Rev. 148 8.10.2026
Rev. 85 09.01.2018 : new
Rev. 99 29.01.2018 : load module voltage handling added
Rev. 148 16.06.2018 : time handling improved, Hippogreiff relay
Rev. 187 14.10.2018 : Hippogreiff off 2h before sunrise
Rev. 197 03.03.2019 : Plug 2 hippo; Plug04 surplus power
Rev. 199 02.04.2019 : allow battery unload before sunrise as default
Rev. 203 30.04.2019 : timer macro change, sun times & surplus log enhanced
Rev. 206 27.05.2019 : PPS pre relay off delay 5 minutes (en lieu de 3s)
Rev. 209 22.07.2019 : work around a Doxygen bug
Rev. 222 18.03.2020 : noUnloadBat as default
Rev. 232 13.12.2022 : off Hippogreiff 2h earlier
Rev. 248 29.06.2023 : relays reorganised (1 defect & prep. extra heater)
Rev. 252 17.08.2023 : ECar loading ++
Rev. 256 17.03.2024 : flexible /ref Hippogreiff switching times
Rev. 260 06.08.2024 : force battery loading pwm <= BAT_LDMX_PWM
Rev. 84 04.06.2025 : solPowerProd: display OFF corr.; miniJoule->Envertech
Rev. 85 14.06.2025 : miniJoule inverter replaced - cleanup
Rev. 87 03.07.2025 : solarPowerHyst values
Rev. 90 06.08.2025 : battery SOC/% <-> Ubat; load test prep.
Rev. 111 13.01.2026 : battery load and keep changed
Rev. 112 21.01.2026 : inline const -> macro 22.1. auto unload after ball beg.
Rev. 115 08.02.2026 : unload after ballast load changed in batCntBalStatChg
Rev. 115 11.05.2026 : experimental: no ballast increase on heater stupid!
Rev. 116 12.05.2026 : logic fault inhibiting end on Pdel > PDEL_BALEND
Rev. 119 28.05.2026 : battery load and unload SFC partly (!) debugged
Rev. 122 28.06.2026 : battery load and unload SFC debugged
Rev. 131 06.08.2026 : ecoWorthy data by M5Stack-stampS3 (toolch. platformIO)
Rev. 139 06.08.2026 : unload voltage checked before befsun, sunset & dusk
Rev. 144 01.09.2026 : unldAllowed()
void batCntBalStatChg(state_t *const me)
Battery as controlled ballast SFC state changes.
Definition sweetHome2.c:618
state_t solarPowerHyst
Solar power producer hysteresis.
Definition sweetHome2.c:1082
unsigned int unldAllowed()
Is battery unload allowed by battery state.
Definition sweetHome2.c:888
#define PDEL_BALEND
Minimal solar power to leave ballast loading SFC.
Definition sweetHome2.h:223
#define BAT_LDMX_PWM
Battery maximum load PWM setting (LiFePo4).
Definition weBatt.h:469

This file is the addendum to sweetHome.c and sweetHome.h containing those process IO related issues, not necessary for pure HMI or logging related programs.

Function Documentation

◆ switchHotWpump()

void switchHotWpump ( uint8_t const on)

Hot water comfort pump turn on/off.

It turns the hot water comfort circulation pump on respectively off.

Parameters
on!= 0 : on; else, ==0 : off

◆ setPhPckLimit()

float setPhPckLimit ( float powerLimit)

Set and get package switch power limit.

This function sets the PPS power limit in the range 0.0 ... PCK_POWER_LIM_MAX.

Parameters
powerLimitPPS power limit in W
Returns
the (new) power limit

◆ pckSwPec()

uint8_t pckSwPec ( float power)

Set and get package switch percentage by power.

Besides determining an returning the percentage(power), this function sets the process control values via setPckSwPerc() returns its value.

Parameters
powerin W
Returns
the phase packet percentage 0..100

◆ setPckSwPerc()

uint8_t setPckSwPerc ( uint8_t perc)

Set package switch percentage.

This function sets phPckSwIndex by the parameter value in the range 0..200; respectively PCK_POWER_IND_MAX. Additionally it adjusts the current phPckCnt should its value be higher than by the new setting.

On transitions from respectively to 0 the control relay (PCK_POWER_REL) is actuated before respectively after actuating the electronic switch.

This function also sets .phPckpower in valFilVal according to the values in table (array) phPckSwPow.

Parameters
perc0..200; values above PCK_POWER_IND_MAX will have no effect and return the current setting un-altered
Returns
the actual (new) phase packet percentage 0..200

◆ stopBatteryOps()

void stopBatteryOps ( char const * stopCommand)

Stop any battery load or unload operation.

Parameters
stopCommandit is recorded in state_t.controlV of state machine(s) involved; shall have (max.) 6 characters

◆ startBatteryUnl()

void startBatteryUnl ( char const * startCommand)

Start battery unload operation.

Stops all loading and starts unload (if battery charging state allows).

Parameters
startCommandit is recorded in state_t.controlV of state a machine involved; shall have (max.) 6 characters

◆ startBatteryLoad()

void startBatteryLoad ( char const * startCommand)

Start battery normal load operation.

Stops unloading and starts normal battery charging.

Parameters
startCommandit is recorded in state_t.controlV of state a machine involved; shall have (max.) 6 characters

◆ startBatBallLoad()

void startBatBallLoad ( char const * startCommand)

Start battery ballast load operation.

Stops unloading and starts battery charging as ballast.

Parameters
startCommandit is recorded in state_t.controlV of state a machine involved; shall have (max.) 6 characters

◆ startBatteryKeep()

void startBatteryKeep ( char const * startCommand)

Start battery keep operation.

Stops unloading and starts battery charging for a minimal charging state.

Parameters
startCommandit is recorded in state_t.controlV of state a machine involved; shall have (max.) 6 characters

◆ batKeepInhTimChg()

void batKeepInhTimChg ( state_t *const me)

Inhibit battery keep alive loading timer state change function.

It turns the "battery keep alive loading" on when timer ends. see BAT_KEEP_PWM.

Parameters
mepointer to the inhibit battery keep alive loading timer

◆ logBatteryState()

void logBatteryState ( )

Log battery state on outLog as line with time stamp.

Logs the battery voltage in the format

/0123456789x123456789v123456789t123456789q123456789c123456789s123456789S1234567
/ 2019-05-01 11:58:16.600 # battery 1?.05 V, pwmL 000: 13.08V; 1234.6W .
/linefeed

◆ switchBatToStepUp()

void switchBatToStepUp ( uint8_t on)

Switch battery to step up converter.

When the parameter is !=0 respectively ON, this function connects the battery to the step up converter (12V DC to 56V DC) feeding one input of a solar inverter (40..60V DC to 230V ~).

When the parameter is 0 or OFF, the step up converter will be disconnected resp. turned off.

Parameters
ontrue: switch battery to step up converter; 0, false: turn step up converter off.

◆ setBatLoadPWM()

void setBatLoadPWM ( int pwm)

Set battery loader module PWM.

This function sets the battery load module power PWM signal and hence its output voltage. 0 is the lowest and 255 the highest possible setting. While this function allows setting to 0, the highest value is limited to BAT_LDMX_PWM.

Parameters
pwmthe pwm ratio 0: 0%; 255: 100%

◆ changeBatLoadPWM()

void changeBatLoadPWM ( int pwmChg)

Change battery loader module PWM.

This function adds the parameter pwmChg's value to the current one limits the result to BAT_NOLD_PWM ... BAT_LDMX_PWM and sets it (see setBatLoadPWM).

Parameters
pwmChgthe change of the pwm value

◆ batUnloadStatChg()

void batUnloadStatChg ( state_t *const me)

Battery unload SFC state changes.

This sequential function chart (SFC) state machine organises the battery unload via a step up converter module. It's output (approx. 40V) is fed to the input of a low voltage (60V) two input solar inverter (EVT560).
This SFC handles all switching steps and (inhibit) conditions. Used in:

The structure for state machines.
Definition weStateM.h:153
void batUnloadStatChg(state_t *const me)
Battery unload SFC state changes.
Definition sweetHome2.c:419
state_t batUnloadSeq
Battery controlled unload via inverter.
Definition sweetHome2.c:599
#define newSeqCont(N, C, n, m, S)
Define a sequential function chart as state machine.
Definition weStateM.h:907
See also
batCntBalStatChg switchBatToStepUp() batCntLodStatChg()
Parameters
mepointer to the battery unload SFC, never NULL (not checked!)

◆ batCntBalStatChg()

void batCntBalStatChg ( state_t *const me)

Battery as controlled ballast SFC state changes.

This sequential state machine organises the battery load as ballast for surplus energy.

See also
batUnloadSeq setBatLoadPWM() batCntLodStatChg()
Parameters
mepointer to the battery ballast load SFC, never NULL (not checked)

◆ batCntLodStatChg()

void batCntLodStatChg ( state_t *const me)

Battery controlled load - SFC state changes.

This sequential state machine organises the battery loading. Keeping it in good load state by moderate constant voltage (BAT_KEEP_PWM) is not task of this SFC, also not to be confused with batCntBalStatChg, i.e. using battery as storage/ballast.

See also
batCntBalStatChg() batUnloadStatChg()
Parameters
mepointer to the battery unload SFC, never NULL

◆ unldAllowed()

unsigned int unldAllowed ( )

Is battery unload allowed by battery state.

If state of charge or battery voltage prohibit discharging 0 (FALSE) will be returned.

Returns
0: not allowed; 1: allowed by SOC; 2: allowed by voltage, only

◆ befRiseTimChg()

void befRiseTimChg ( state_t *const me)

Before sunrise timer state change callback.

On timer end .....

Parameters
mepointer to the sunset timer

◆ dawnTimChg()

void dawnTimChg ( state_t *const me)

Dawn timer state change callback.

On timer end .....

Parameters
mepointer to the dawn timer

◆ sunriseTimChg()

void sunriseTimChg ( state_t *const me)

Sunrise timer state change callback.

On timer end turn off Hippogreiff (again) and mqttPlg02.
No more turning off battery unload due to replacing the one input miniJoule inverter by a two input Enversys. One input is for the PV panels and one for the battery discharge step up converter. Hence, solar power and battery discharging can be used simultaneously and do not have to be guarded against each other.

Parameters
mepointer to the sunrise timer

◆ sunsetTimChg()

void sunsetTimChg ( state_t *const me)

Sunset timer state change callback.

On timer end .....

Parameters
mepointer to the sunset timer

◆ duskTimChg()

void duskTimChg ( state_t *const me)

Dusk timer state change callback.

On timer end .....

Parameters
mepointer to the sunset timer

◆ genSunStateText()

void genSunStateText ( char * stateText,
state_t const *const me,
char const * stamp )

Generate the sun's status text.

This function makes the special log text for sun's times: set, rise etc..

Parameters
stateTexta character array supplied to hold the state text to be generated; minimal length 80.
mepointer to own state; never null
stamp(time) stamp to be prepended (max. length 23); default " - "

◆ switchSolPow()

void switchSolPow ( state_t *const me)

Solar power producer transition.

At the moment just switch the relays and set a flag.
Note 1: trigger with pSolar
Note 2: Used for state_t solarPowerHyst only.
state_t solarPowerHyst = newFloatHyst("solPowerProd", switchSolPow, ...

Parameters
mepointer to the give away hysteresis

◆ solPowStateText()

void solPowStateText ( char * stateText,
state_t const *const me,
char const * stamp )

Generate solar power status text.

This function generates the log text for the solar power on/off discriminator.

Parameters
stateTexta character array supplied to hold the state text to be generated; minimal length 80.
mepointer to own state; never null
stamp(time) stamp to be prepended (max. length 23); default " - "

◆ switchWouldGivAway()

void switchWouldGivAway ( state_t *const me)

Would give away transition.

At the moment just switch the relays and set a flag. Note: trigger wouldGiveAwayHyst with pGiveAway

Parameters
mepointer to the give away hysteresis

◆ switchWouldGiv250W()

void switchWouldGiv250W ( state_t *const me)

Would give 250W or more away, the transition.

At the moment just switch the relays and set a flag. Note: trigger with pGiveAway

Parameters
mepointer to the give away hysteresis

◆ switchConsGiv()

void switchConsGiv ( state_t *const me)

Power consumer / producer (give away) transition.

Triggered with pHome, at transitions relay and plug are switched for signalling via the switchConsGiv() SFC to have minimal on and off times.

At transitions to OFF, i.e. producer role imminent, battery ballast loading will be started (if not yet ON).

Parameters
mepointer to the give away hysteresis

◆ setConsGiv()

void setConsGiv ( state_t *const me)

Power consumer / producer (give away) SFC transition.

At the moment just switch the relays and set a flag. Note: trigger with pHome (hyst)

Parameters
mepointer to consumeGiveSFC

◆ surplStateText()

void surplStateText ( char * stateText,
state_t const *const me,
char const * stamp )

Generate surplus power status text.

This function generates the log text for the surplus power status machine.

Parameters
stateTexta character array supplied to hold the state text to be generated; minimal length 80.
mepointer to own state; never null
stamp(time) stamp to be prepended (max. length 23); default " - "

◆ mqttInit()

int mqttInit ( )

Initialise as MQTT client.

On success only: subscribe, loop and publish.

Returns
0: success the common mosq is set and usable; else: errno
See also
mqttClean

◆ mqttClean()

void mqttClean ( )

End as MQTT client.

Stop and cleanup.

See also
mqttInit

◆ mqttPlg01Set()

void mqttPlg01Set ( uint8_t const on)

Switch the plug Plug01.

This function publishes the switch command via MQTT to the relay device Plug01, usually a Sonoff S20 with Tasmota.

Parameters
onswitch on when true, else off

◆ mqttPlg02Set()

void mqttPlg02Set ( uint8_t const on)

Switch the plug PLG2.

See mqttPlg01Set

◆ mqttPlg03Set()

void mqttPlg03Set ( uint8_t const on)

Switch the plug PLG3.

See mqttPlg01Set

◆ mqttPlg04Set()

void mqttPlg04Set ( uint8_t const on)

Switch the plug PLG4.

See mqttPlg01Set

Variable Documentation

◆ sensors

The 1-wire sensors used.

See also NUM1W_SENSORS.

◆ hippoSwitchMode

int hippoSwitchMode

Hippogreiff on/off times.

time: dusk | dawn | set | rise
switch: on | off | on | off
bit: 3 | 2 | 1 | 0
value: 8 | 4 | 2 | 1

Bit 1,0, ( 3): switch at sunset resp. sunrise (winter)
Bit 3,2 (12): switch at dusk resp. dawn (summer)
See also HIPPO_COMMANDS.

◆ phPckSwIndex

volatile uint8_t phPckSwIndex

Actual index (0..200%) determining power.

This is the control variable for the electric heater elements in the hot water tank. Until June 2023 there was one such element of PCK100PERC_POWER W and this variable had a range of 0..100%. Since July 2023 there are two heater elements of equal power. The range of this control variable was extended to 0..200%. The power distribution between the two heater elements is done by software; see setPckSwPerc(uint8_t const perc) and PCK_POWER_IND_MAX

◆ batVoltValid

uint8_t batVoltValid

The measured battery voltage is valid.

When not 0 the last MQTT battery voltage measurement respectively message is not older than 2.4s and hence considered the actual valid value.
6..240 = uBat and SOC by Bluetooth; 1..5 = uBat by ADU

◆ batKeepInh

state_t batKeepInh

Inhibit battery keep alive loading.

This timer will be started after battery loading and unloading for a specific time BATkeepInhContLoad, BATkeepInhUnload or BATkeepInhByCmd. This timer is initially OFF and will be stopped in advance by battery keep command via HMI/GUI.
It will be started after battery unload, after battery ballast load and by battery off command via GUI.
When running out it will start battery keep alive with BAT_KEEP_PWM by startBatteryKeep.

Note: The feature seems/is unnecessarily complicated due to its lead acid battery past

◆ batUnloadAllowed

int batUnloadAllowed

Battery unload allowed.

Bit 0 (1): allow after sunset
Bit 1 (2): allow before sunrise
Bit 3 (4): allow when Pimp > 400W, i.e. allow also at daylight.
Bit 4 (8): default (usually 2 in winter and 3 in summer)
Start value: 8 = default
Note: Must be a standard integer (no uint_8 e.g.) for use in getopt_long.

See also BAT_UNL_SUMM BAT_UNL_WINT BAT_UNL_P400

◆ batLoadAllowed

int batLoadAllowed

Battery loading allowed.

Bit 0 (1): allow ballast loading
Bit 1 (2): allow automatic / controlled loading
start value: 3 = all allowed
Note: Must be a standard integer (no uint_8 e.g.) for use in getopt_long.

See also
batUnloadAllowed
BAT_LOAD_FORBID

◆ hundredsV

uint16_t hundredsV

The battery voltage in 0.01V units.

This is just an integer value consistent to the last valid battery voltage measurement valFilVal.batVolt. Contrary to valFilVal.batVolt which is set to -0.9 to indicate invalidity after 2.4s without new (MQTT) measurements, this integer value will be kept "forever".
It is preset with 1289 (12.89 V) to avoid "battery low" status before the first valid MQTT measurement / message.
Receiving a good MQTT message from the battery voltmeter will set valFilVal.batVolt, batVoltValid and this value.
Use

formFixed16(&textStart, hundredsV, 2)
uint16_t hundredsV
The battery voltage in 0.01V units.
Definition sweetHome2.c:311
char * formFixed16(char *target, uint8_t targetLen, uint16_t value, uint8_t dotPos)
Format 16 bit unsigned fixed point, right aligned.
Definition weUtil.c:252

to format as "12.89" without trailing zero.

See also
formFixed16 valFilVal batVoltValid tenPromSoC

◆ tenPromSoC

uint16_t tenPromSoC

The battery state of charge or SOC in 0.01% units.

This the state of charge of (one of the) ECOworthy batteries in units of 0.01% or 10 per mille as published by Bluetooth. A value of 2468 would mean a SoC of 24.68% and for a 100Ah battery also a charge of 24.68Wh.

If no Bluetooth data of (at least) one of the three batteries connected in parallel are available the SoC will be looked up by SoC(U) table.

Use

formFixed16(&textStart, tenPromSoC, 2)
uint16_t tenPromSoC
The battery state of charge or SOC in 0.01% units.
Definition sweetHome2.c:313

to format as "24.68" without trailing zero.

See also
formFixed16 valFilVal batVoltValid

◆ batModPWM

volatile int batModPWM

The actual battery load module's PWM input.

The range of the Pi's pwm output control register 0 for 0 % or permanent off to 255 for 100% respectively permanent on. The eight bit register, hence, is to be fed with an unsigned 8 bit value which was for many years the type of this variable.
A new loader module since August 2025 uses the full range 0..255. This variable was made a standard int to simplify underflow and overflow detection.
Note: Keeping this variable's value in the range 0 .. +255 is essential!

◆ nologBatCap

volatile uint nologBatCap

Control logging inhibit charging battery due to capacity limit.

1: log next time when it occurs and (always) decrement 0: or high value log no more this day. n: inhibit the next 2*n seconds while continually trying

◆ batLoadPowValid

uint8_t batLoadPowValid

Battery charging power is valid.

Currently (2018..22026) the electric water tank heater and battery charging share a power meter. It will yield charging power (0..270 W) as ..batLoadPower if and only if water heating (0..4 kW) is off. The criterion is the contactor to the water heaters is off or all electronic relays (SSRs) to the resistor strads are off.

◆ batLoadPower

float batLoadPower

Battery charging power when valid.

See batLoadPowValid.

◆ sunriseTimer

state_t sunriseTimer

Sunrise timer.

This timer will run out every day at (approximated) sunrise. For the "every day" behaviour, its state change function will — after all due actions — restart this timer for the next 24h to hit (very approximately) the next sunrise. This acceptable guess will be adjusted at day change or at program start.

◆ sunsetTimer

state_t sunsetTimer

Sunset timer.

This timer will run out every day at (approximated) sunset. See also sunriseTimer

◆ befRiseTimer

state_t befRiseTimer

Before sunrise timer.

This timer will run out every day at about 180 min before (approximated) sunrise. The offset must be sufficient time to unload the battery before sunrise.
See also: sunriseTimer BEFORE_RISE

◆ dawnTimer

state_t dawnTimer

Dawn timer.

This timer will run out every day at (approximated) dawn, meaning the beginning of civil twilight. See also sunriseTimer and duskTimer

◆ duskTimer

state_t duskTimer

Dusk timer.

This timer will run out every day at (approximated) dusk, meaning the end of civil twilight. About this time street lamps and position lights may be lit. See also sunriseTimer

◆ solarPowerHyst

state_t solarPowerHyst

Solar power producer hysteresis.

The limits of the power of the biggest (or all) PV panels to recognise the availability / generation of solar power.
Current limits 7.9W (off), 40.0 W (on); since 03.07.2025
Former values 4.8, 12.02

◆ wouldGiveAwayHyst

state_t wouldGiveAwayHyst

Would give away hysteresis.

thresholds (04.03.18): -/+ 7W

◆ wouldGive250WHyst

state_t wouldGive250WHyst

Would give away 250W hysteresis.

thresholds (04.03.18): -250 / -178W

◆ consumeGiveHyst

state_t consumeGiveHyst

Give away hysteresis.

thresholds: PDEL_SGGIVE, PDEL_SGCONS

◆ consumeGiveSFC

state_t consumeGiveSFC

Give away state machine / SFC.

Status ON means consumer: OK.
Status OFF means very low power consumption: Inhibit power delivery.

◆ mqttHost

char mqttHost[68]

MQTT broker address or name.

It is either the hostname or the IP address as text. like e.g. 192.168.178.86 or mqttpi.

See also
mqttPort topicSubs

◆ mqttPort

int mqttPort

MQTT broker port.

It is usually the standard port 1883.

See also
mqttHost topicSubs

◆ topicSubs

char const topicSubs[20]

The MQTT topic to subscribe to.

The array's lenght is 20, fitting SUBTOP_I.

See also
mqttHost mqttPort SUBTOP_I

◆ subTopBatU

char const subTopBatU[10]

Relative topic to subscribe Ubat (bat/volt).

Hardware setup: (old) ESP with ADU. The EcoWorthy Bluetooth (BT) value subTopEco3 gets precedence when available.

See also
subTopEco3 subTopGrow

◆ subTopGrow

char const subTopGrow[14]

Relative topic for Growatt readings.

See also
subTopEco3 subTopBatU

◆ subTopEco3

char const subTopEco3[14]

Relative topic for topic for EcoWorthy BT readings.

Hardware setup 2026: M5Stamp S3; software platformIO

See also
subTopGrow subTopBatU

◆ messCmdOnPlg

char messCmdOnPlg[4]

Message to turn a S20 plug on.

See also
messCmdOffPlg messSttOnPlg messSttOffPlg subTopStPlg01

◆ messCmdOffPlg

char messCmdOffPlg[4]

Message to turn a S20 plug off.

See also
messCmdOmPlg messSttOnPlg messSttOffPlg subTopStPlg01 message to turn a S20 plug off

◆ subTopStPlg01

char subTopStPlg01[14]

State sub topic of S20 plug Number 01 to 09.

It's preset as plug01/POWER for 01, but the digit at index [5] will be set before each use accordingly.

See also
messSttOnPlg messSttOffPlg

◆ messSttOnPlg

char messSttOnPlg[6]

State message: a S20 plug is now on.

See also
messSttOffPlg subTopStPlg01

◆ messSttOffPlg

char messSttOffPlg[6]

State message: a S20 plug is now off.

See also
messSttOnPlg subTopStPlg01

◆ clientId

char clientId[38]

MQTT client ID.

default value: sweetHomeControl; length: 15; max. length: 36
May be changed before mqttInit().

◆ mosq

struct mosquitto* mosq

MQTT interface state.

Defined in <mosquitto.h> without description. MQTT interface (state)