rasProject_01 / weSweetHome
R. 240
process control / RasPi software by weinert-automation
|
Common values for an experimental smart home (lab) project. More...
Functions | |
void | batKeepInhTimChg (state_t *const me) |
Inhibit battery keep alive loading timer state change function. More... | |
void | befRiseTimChg (state_t *const me) |
Before sunrise timer state change callback. More... | |
void | dawnTimChg (state_t *const me) |
Dawn timer state change callback. More... | |
void | duskTimChg (state_t *const me) |
Dusk timer state change callback. More... | |
void | genSunStateText (char *stateText, state_t const *const me, char const *stamp) |
Generate the sun's status text. More... | |
void | logBatteryState () |
Log battery state on outLog as line with time stamp. More... | |
void | mqttClean () |
End as MQTT client. | |
int | mqttInit () |
Initialise as MQTT client. More... | |
void | mqttPlg01Set (uint8_t const on) |
Switch the plug Plug01. More... | |
void | mqttPlg02Set (uint8_t const on) |
Switch the plug PLG2. More... | |
void | mqttPlg03Set (uint8_t const on) |
Switch the plug PLG3. More... | |
void | mqttPlg04Set (uint8_t const on) |
Switch the plug PLG4. More... | |
uint8_t | pckSwPec (float power) |
Set and get package switch percentage by power. More... | |
void | reduceBatLoadPWM (uint8_t const pwmRed) |
Reduce battery loader module PWM. More... | |
void | setBatLoadPWM (uint8_t pwm) |
Set battery loader module PWM. More... | |
void | setConsGiv (state_t *const me) |
Power consumer / producer (give away) SFC transition. More... | |
uint8_t | setPckSwPerc (uint8_t perc) |
Set package switch percentage. More... | |
float | setPhPckLimit (float powerLimit) |
Set and get package switch power limit. More... | |
void | solPowStateText (char *stateText, state_t const *const me, char const *stamp) |
Generate solar power status text. More... | |
void | sunriseTimChg (state_t *const me) |
Sunrise timer state change callback. More... | |
void | sunsetTimChg (state_t *const me) |
Sunset timer state change callback. More... | |
void | surplStateText (char *stateText, state_t const *const me, char const *stamp) |
Generate surplus power status text. More... | |
void | switchBatToStepUp (uint8_t const on) |
Switch battery to step up converter. More... | |
void | switchConsGiv (state_t *const me) |
Power consumer / producer (give away) transition. More... | |
void | switchHotWpump (uint8_t const on) |
Hot water comfort pump turn on/off. More... | |
void | switchInvToBatUnl (uint8_t const on) |
Switch inverter to battery unload. More... | |
void | switchSolPow (state_t *const me) |
Solar power producer transition. More... | |
void | switchWouldGiv250W (state_t *const me) |
Would give 250W or more away, the transition. More... | |
void | switchWouldGivAway (state_t *const me) |
Would give away transition. More... | |
Variables | |
state_t | batKeepInh |
Inhibit battery keep alive loading. More... | |
int | batUnloadAllowed |
Battery unload allowed. More... | |
uint8_t | batVoltValid |
The measured battery voltage is valid. More... | |
state_t | befRiseTimer |
Before sunrise timer. More... | |
char | clientId [38] |
MQTT client ID. More... | |
state_t | consumeGiveHyst |
Give away hysteresis. More... | |
state_t | consumeGiveSFC |
Give away state machine / SFC. More... | |
state_t | dawnTimer |
Dawn timer. More... | |
state_t | duskTimer |
Dusk timer. More... | |
uint8_t | heaterAllowed |
phase packet load enabled (always) | |
int | hippoSwitchMode |
Hippogreiff on/off times. More... | |
uint16_t | hundredsV |
The battery voltage in 0.01V units. More... | |
char | mqttHost [68] |
The MQTT broker URL or name. More... | |
int | mqttPort |
MQTT port 1883. | |
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. More... | |
volatile uint8_t | phPpow2 |
heater 2 power * 50% (0:0% .. 2:100%) | |
oneWireDevice_t | sensors [NUM1W_SENSORS] |
The 1-wire sensors used. | |
state_t | solarPowerHyst |
Solar power producer hysteresis. | |
char | subTopStPlg01 [14] |
State sub topic of S20 plug Number 01 to 09. More... | |
state_t | sunriseTimer |
Sunrise timer. More... | |
state_t | sunsetTimer |
Sunset timer. More... | |
state_t | wouldGive250WHyst |
Would give away 250W hysteresis. More... | |
state_t | wouldGiveAwayHyst |
Would give away hysteresis. More... | |
Common values for an experimental smart home (lab) project.
Revision history
This file is the addendum to sweetHome.c and sweetHome.h containing process IO related issues, not necessary for pure HMI or logging related programs.
void switchHotWpump | ( | uint8_t const | on | ) |
Hot water comfort pump turn on/off.
It turns the hot water comfort circulation pump on respectively off.
on | != 0 : on; else, ==0 : off |
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.
powerLimit | PPS power limit in W |
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.
power | in W |
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.
perc | 0..200; values above PCK_POWER_IND_MAX will have no effect and return the current setting un-altered |
void logBatteryState | ( | ) |
Log battery state on outLog as line with time stamp.
Logs the battery voltage and ... .
void switchInvToBatUnl | ( | uint8_t | on | ) |
Switch inverter to battery unload.
When the parameter is !=0 respectively ON, this function switches the (small) inverter from panel to the battery unload step up converter and turns the extra Ferraris energy meter off by REL2. Note: Said Ferraris is now unused (but still mounted).
When the parameter is off it does the other way round.
on | true: switch inverter to step up converter (battery unload); 0, false: switch inverter to panel. |
void switchBatToStepUp | ( | uint8_t | on | ) |
Switch battery to step up converter.
When the parameter is !=0 respectively ON, this function switches the battery to the step up converter.
When the parameter is off, this function switches the battery to the (max. 20 A) battery loader / keep alive module .
on | true: switch battery to step up converter; 0, false: switch battery to load modul. |
void batKeepInhTimChg | ( | state_t *const | me | ) |
Inhibit battery keep alive loading timer state change function.
It turns the battery keep alive loading on when ending.
me | pointer to the inhibit battery keep alive loading timer |
void setBatLoadPWM | ( | uint8_t | 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.
pwm | the pwm ratio 0: 0%; 255: 100% |
void reduceBatLoadPWM | ( | uint8_t const | pwmRed | ) |
Reduce battery loader module PWM.
This function reduces the battery load module power PWM signal and hence its output voltage by the parameter value. The reduction is limited to BAT_NOLD_PWM.
pwmRed | the reduction of the pwm ratio |
void befRiseTimChg | ( | state_t *const | me | ) |
Before sunrise timer state change callback.
On timer end .....
me | pointer to the sunset timer |
void dawnTimChg | ( | state_t *const | me | ) |
Dawn timer state change callback.
On timer end .....
me | pointer to the dawn timer |
void sunriseTimChg | ( | state_t *const | me | ) |
Sunrise timer state change callback.
On timer end .....
me | pointer to the sunrise timer |
void sunsetTimChg | ( | state_t *const | me | ) |
Sunset timer state change callback.
On timer end .....
me | pointer to the sunset timer |
void duskTimChg | ( | state_t *const | me | ) |
Dusk timer state change callback.
On timer end .....
me | pointer to the sunset timer |
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..
stateText | a character array supplied to hold the state text to be generated; minimal length 80. |
me | pointer to own state; never null |
stamp | (time) stamp to be prepended (max. length 23); default " - " |
void switchSolPow | ( | state_t *const | me | ) |
Solar power producer transition.
At the moment just switch the relays and set a flag. Note: trigger with pSolar
me | pointer to the give away hysteresis |
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.
stateText | a character array supplied to hold the state text to be generated; minimal length 80. |
me | pointer to own state; never null |
stamp | (time) stamp to be prepended (max. length 23); default " - " |
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).
me | pointer to the give away hysteresis |
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)
me | pointer to consumeGiveSFC |
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.
stateText | a character array supplied to hold the state text to be generated; minimal length 80. |
me | pointer to own state; never null |
stamp | (time) stamp to be prepended (max. length 23); default " - " |
void switchWouldGivAway | ( | state_t *const | me | ) |
Would give away transition.
At the moment just switch the relays and set a flag. Note: trigger with pGiveAway
me | pointer to the give away hysteresis |
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
me | pointer to the give away hysteresis |
int mqttInit | ( | ) |
Initialise as MQTT client.
On success only: subscribe, loop and publish.
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.
on | switch on when true, else off |
void mqttPlg02Set | ( | uint8_t const | on | ) |
Switch the plug PLG2.
See mqttPlg01Set
void mqttPlg03Set | ( | uint8_t const | on | ) |
Switch the plug PLG3.
See mqttPlg01Set
void mqttPlg04Set | ( | uint8_t const | on | ) |
Switch the plug PLG4.
See mqttPlg01Set
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
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.
int batUnloadAllowed |
Battery unload allowed.
Bit 0 (1): allow after sunset
Bit 1 (2): allow before sunrise
start value: 8 set default value (usually 2 in winter and 3 in summer) Note: Made int en lieu de uint_8 for use in getopt_long.
int hippoSwitchMode |
Hippogreiff on/off times.
Bit 0,1 ( 3): switch at sunset resp. sunrise (winter)
Bit 2,3 (12): switch at dusk resp. dawn (summer)
start value: 12 (/ref Hippogreiff summer)
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 value will be kept (forever).
It is preset with 1289 (12.89 V) lest have battery low 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) to format as "12.89" without trailing zero.
state_t batKeepInh |
Inhibit battery keep alive loading.
While running disallow battery keep alive with BAT_KEEP_PWM. This timer is initially OFF and will be stopped in advance by low battery voltage stress and battery keep command via HMI/GUI.
It will be started after battery unload, after battery ballast load and by battery off command via GUI.
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.
state_t sunsetTimer |
Sunset timer.
This timer will run out every day at (approximated) sunset. See also sunriseTimer
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
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
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
state_t consumeGiveHyst |
Give away hysteresis.
thresholds: PDEL_SGGIVE, PDEL_SGCONS
state_t consumeGiveSFC |
Give away state machine / SFC.
Status ON means consumer: OK.
Status OFF means very low power consumption: Inhibit power delivery.
state_t wouldGiveAwayHyst |
Would give away hysteresis.
thresholds (04.03.18): -/+ 7W
state_t wouldGive250WHyst |
Would give away 250W hysteresis.
thresholds (04.03.18): -250 / -178W
char mqttHost[68] |
The MQTT broker URL or name.
May be set by option –mqttHost meterPi or –mqttBroker 192.168.178.87
default: localhost MQTTBroker (currently localhost !)
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.
char clientId[38] |
MQTT client ID.
default value: sweetHomeControl; length: 15; max. length: 36
May be changed before mqttInit().
MQTT client ID.