![]() |
rasProject_01 / weSweetHome
R. 102 2025-10-31
process control / RasPi software by weinert-automation
|
Common types, values and functions for a smart home project. More...
Data Structures | |
| struct | cmdLookUp_t |
| Structure for a defined remote command. More... | |
| struct | dayStrtVal_t |
| Day start values. More... | |
| struct | meterVal_t |
| One smart meter's readings. More... | |
| struct | phPckSwSet_t |
| Simple Structure for phase packet switch setting. More... | |
| struct | valFilVal_t |
| Smart meters' and other process values. More... | |
| struct | valsSharMem_t |
| Structure for shared memory. More... | |
Macros | |
| #define | Amsk |
| would give away | |
| #define | ANZmodSLAVES |
| Number of smart Modbus meters. More... | |
| #define | AUTO_PPSWI_COMMAND |
| auto control (ON=manual) | |
| #define | BALL_CARLOAD_COMMAND |
| car load as PV surplus ballast | |
| #define | bat2unload(x) |
| The battery load/undoad line (30A fuse) is connected to the unload step up converter and, hence, not to the PWM controlled charger. More... | |
| #define | BAT_COMMANDS |
| all battery commands mask | |
| #define | BATLOAD_COMMANDS |
| battery loading commands mask | |
| #define | BATUNL_COMMANDS |
| battery unloading commands mask | |
| #define | Bmsk |
| Controlled load battery (as ballast) | |
| #define | C250W_COMMANDS |
| give 250 W command mask | |
| #define | CARLOAD_COMMANDS |
| car load command mask | |
| #define | CHSBmsk |
| CHS mode ballast (1: on at 0.. max power at surplus) | |
| #define | CHScarC |
| CHS loading station: car connected to EVSE. | |
| #define | CHScPow |
| CHS loading station: power line connected to car. | |
| #define | CHSiLhi |
| CHS current limit at hi border. | |
| #define | CHSiLiM |
| CHS current limit at one border mask. | |
| #define | CHSiLlo |
| CHS current limit at lo border (usually 6A fixed) | |
| #define | CHSMmsk |
| CHS mode manual (1: on at max power) | |
| #define | CHSphas |
| CHS number of phases: 1..6; 0, 7 not used; 3 default. | |
| #define | CHSphHi |
| CHS number of phases at hi limit (1..6) | |
| #define | CHSphLo |
| CHS number of phases at lo limit (usually 1 fixed) | |
| #define | CHSphMs |
| CHS number of phases at limit mask. | |
| #define | cmdBits_t |
| Type for command bits. More... | |
| #define | DEC_CARLOAD_COMMAND |
| car load decrease max. current | |
| #define | DECLIM_PPSWI_COMMAND |
| reduce PPSWI limit (by 300W) | |
| #define | DECR_PPSWI_COMMAND |
| decrement (-1) PPSWI power | |
| #define | EFNY |
| Start position of date in evtFilNam. | |
| #define | getNoPhas() |
| Get number of phases. More... | |
| #define | GIVE250_COMMANDS |
| commands concerning Plg01 & Rel5 | |
| #define | Gmsk |
| Give away: Alarm / add ballast / etc. | |
| #define | HIPPO_COMMANDS |
| Mask for all Hippogreiff commands. More... | |
| #define | HWPUMP_COMMANDS |
| comfort pump command mask | |
| #define | INC_CARLOAD_COMMAND |
| car load increase max. current | |
| #define | INC_PPSWI_COMMAND |
| increment (+1) PPSWI power | |
| #define | INCLIM_PPSWI_COMMAND |
| increase PPSWI limit (by 200W) | |
| #define | Kmsk |
| Keep battery (minimal load voltage) | |
| #define | Lmsk |
| Load battery (normal program) | |
| #define | LOWER_BATLOAD_COMMAND |
| lower battery loading power | |
| #define | LOWER_PPSWI_COMMAND |
| lower PPSWI power | |
| #define | OFF_C250W_COMMAND |
| off control give 250 W | |
| #define | OFF_CARLOAD_COMMAND |
| E-car load off. | |
| #define | OFF_HIPPO_COMMAND |
| off Hippogreiff | |
| #define | OFF_PLG1_COMMAND |
| off Plug01 give 250 W | |
| #define | OFF_PLG2_COMMAND |
| off Plug02 | |
| #define | OFF_PLG3_COMMAND |
| off Plug03 | |
| #define | OFF_PLG4_COMMAND |
| off Plug04 | |
| #define | OFF_PPSWI_COMMAND |
| off PPSWI (Power packet switching) | |
| #define | ON_C250W_COMMAND |
| on control give 250 W | |
| #define | ON_CARLOAD_COMMAND |
| E-car load on. | |
| #define | ON_HIPPO_COMMAND |
| on Hippogreiff | |
| #define | ON_PLG1_COMMAND |
| on Plug01 give 250 W | |
| #define | ON_PLG2_COMMAND |
| on Plug02 | |
| #define | ON_PLG3_COMMAND |
| on Plug03 | |
| #define | ON_PLG4_COMMAND |
| on Plug04 | |
| #define | ONMAN_PPSWI_COMMAND |
| on and manual PPSWI PPSWI | |
| #define | P2sPmsk |
| PPS element 2 power * 50% (0:0% .. 2:100%) | |
| #define | PCK100PERC_POWER |
| Phase packet switching device. More... | |
| #define | PCK1PERC_POWER |
| phase packet switch 1% power / W | |
| #define | PCK50PRC_POWER |
| phase packet switch 50% power / W | |
| #define | PHDEC_CARLD_COMMAND |
| assume E-cars using 1 phase less | |
| #define | PHINC_CARLD_COMMAND |
| assume E-cars using 1 phase more | |
| #define | PLG1_COMMANDS |
| Plug01 command mask. | |
| #define | PLG2_COMMANDS |
| Plug02 command mask. | |
| #define | PLG3_COMMANDS |
| Plug03 command mask. | |
| #define | PLG4_COMMANDS |
| Plug04 command mask. | |
| #define | PPSMmsk |
| PPS mode manual (0: automatic, default) | |
| #define | PPSUmsk |
| PPS power at limit PCK_POWER_LIM_MAX. | |
| #define | PPSWI_COMMANDS |
| Power packet switching commands. | |
| #define | PPsXmsk |
| PPS max at limit (1: at 0.0 or PCK_POWER_LIM_MAX) | |
| #define | PUMP_STRT_POWR |
| Pump start heating power; see PUMP_STRT_TEMP. | |
| #define | PUMP_STRT_TEMP |
| Water (tank) temperature to start comfort pump when heating. More... | |
| #define | RFNY |
| Start position of date in retFilNam. | |
| #define | RISE_BATLOAD_COMMAND |
| rise battery loading power | |
| #define | RISE_PPSWI_COMMAND |
| rise PPSWI power | |
| #define | SAFE_TEMP_WAT |
| Upper limit of safe water (tank) temperature. More... | |
| #define | SHARED_MEM_DATA_SIZE |
| Size of defined master slave communication data in shared memory. More... | |
| #define | SHARED_MEM_FILL_SIZE |
| Size of extra fill array to have a standard shared memory size. | |
| #define | Smsk |
| Solar power is generated. | |
| #define | START_BATKEEP_COMMAND |
| start battery keep alive (with load) | |
| #define | START_BATKPLD_COMMAND |
| start battery keep or load | |
| #define | START_BATLOAD_COMMAND |
| start battery loading | |
| #define | START_BATUNL_COMMAND |
| start battery unloading | |
| #define | START_HWPUMP_COMMAND |
| start hot water comfort pump | |
| #define | STD_CARLOAD_COMMAND |
| set 3 phases and 16A (11kW) | |
| #define | STOP_BAT_COMMAND |
| stop battery unloading & loading | |
| #define | STOP_HWPUMP_COMMAND |
| stop hot water comfort pump | |
| #define | U_ENDRANGE |
| Upper end of battery operating range LiFePo. | |
| #define | U_ENDRANGE_SOC |
| SOC value assigned to U_ENDRANGE. | |
| #define | Umsk |
| Unload battery commanded. | |
| #define | UNUSED_COMMANDS |
| 4 unused command bits (June 2023) | |
| #define | Wmsk |
| Would give away 250W or more. | |
Functions | |
| int | batSOCbyU (float uBat) |
| Battery capacity or state of charge (SOC) in % by voltage. More... | |
| void | chgFilNames (void) |
| Set the current date in event & retain file paths. More... | |
Variables | |
| cmdLookUp_t | cmdLookUp [] |
| The common command look up table. More... | |
| char | dayFilNam [] |
| Path of the table to log a set of values for every day. More... | |
| char | evtFilNam [] |
| Path of the daily event file. More... | |
| volatile float | fLine |
| Last valid power line frequency. More... | |
| volatile int | invHasUnloadPow |
| The miniJoule inverter has battery unload power. More... | |
| float const | phPckSwPow [101] |
| First (or only) phase packet switching device power look up. | |
| phPckSwSet_t const | phPckSwSets [101] |
| The packet switch control values. More... | |
| char | retFilNam [] |
| Path of the daily retain file. More... | |
| smdX30modbus_t | smdX30modbus [2] |
| Descriptive and state array for smart meters on Modbus. More... | |
| volatile int | tempTankWater |
| Last value of tank water temperature. More... | |
| volatile uint8_t | tempWaterBadCnt |
| Tank water temperature bad read count. More... | |
| float const | uBatBySOC [113] |
| Battery voltage by capacity or state of charge (SOC) in %. More... | |
| valFilVal_t | valFilVal |
| All process values relevant for log files and HMI. | |
Common types, values and functions for a smart home project.
Revision history
In the smart home's PV under control, we assume one smart meter for the whole house's (public) electricity supply and one for solar generators and battery storage. The (two, cf. ANZmodSLAVES) meters are Modbus controlled.
Additionally we have home and PV related process control.
The process IO related definitions are mostly in include/sweetHome2.h
This include file collects some configuration and naming common to
a) the process control program (hometersControl)
b) a console HMI program (hometersConsol) and the
c) server side program(s) (meteRead, CGI) for the web interfaces
All those programs, running on the system for process control and I/O, are written in C. The client side programming for the web HMI is in Javascript.
The server side programs communicate via shared memory and a set of three (ANZ_SEMAS) semaphores.
| #define ANZmodSLAVES |
Number of smart Modbus meters.
Usually two.
| #define cmdBits_t |
Type for command bits.
Commands to the process control program from outside are transferred via shared memory as one bit set for every command to be executed. The bit position (0..31, as of May 2018) defines a concrete command.
"From outside" usually means from a web interface (html page with Javascript) and AJAX to a C written GCI program communicating via shared memory with the process control program. In this schema the CGI program sets bits for commands to be executed and the process control program clears the bit(s) in question on commands executed (or rejected).
Remark: On contradictory commands, ONyxz and OFFxyz, one will be executed and both will be cleared. In cases like this OFF... usually gets priority.
Remark 2: When exceeding 32 distinct commands we may switch to a uint64_t as was done from 16_t to 32_t in May 2018.
| #define HIPPO_COMMANDS |
Mask for all Hippogreiff commands.
Hippogreiff stands for a relay controlled 12V supply from storage battery. It should be ON at night, or more precisely either between sunset and sunrise or from dusk to dawn.
One consumer on this rail is a green LED beam to a little Hippogreiff sculpture. Hence the name.
The Hippogreiff is mythical beast with similarities to Harry Potter's Hippogreif, as long as looked at from the front. Seen from side one realises him being another species.
| #define PCK100PERC_POWER |
Phase packet switching device.
Since Rev. 157 (07-2018) we have one single phase heating device with then 950 W power, raised 03.2020 to 1267W and 02.2023 to 1845. It is actuated by a zero crossing electronic switch (SSR) at pin PH_P_SSR1 controlling the amount of power in 1% (PCK1PERC_POWER) steps.
For robustness and safety this electronic relay sits behind a 10A relay.
Since march 2023 we have two heater elements of 2kW each:
heater element 1 phase packet switch SSR1 PH_P_SSR1) 0..100%
heater element 1 phase packet switch SSR1 PH_P_SSR1) 0, 50, 100%
While the first one is controlled in 101 steps as before, the second one got three states: off, half and full power. This effectively gives a range of 0 to about 4kW in 201 steps. In the present configuration any PV surplus can be handled as in-house-consumption (Eigenverbrauch).
| #define SAFE_TEMP_WAT |
Upper limit of safe water (tank) temperature.
The integer value for safe water (tank) temperature sensor reading is +65950 m°C respectively 66 °C. Above this value all (electric) heating must stop.
| #define PUMP_STRT_TEMP |
Water (tank) temperature to start comfort pump when heating.
The integer value for pump start water (tank) temperature sensor reading is +63950 m°C respectively 64 °C (since 19.06.2025; was 62 °C). Above this value electric heating with >= 1.9kW (surplus) power shall start the (comfort) circulation pump for 3 minutes.
This is done in the hope to disturb the temperature layers in the tank and, hence, reduce hot water outlet temperature.
| #define getNoPhas | ( | ) |
Get number of phases.
| #define bat2unload | ( | x | ) |
The battery load/undoad line (30A fuse) is connected to the unload step up converter and, hence, not to the PWM controlled charger.
Since 30.05.2025 this replaced the miniJoule input switching relays state.
N.b.: The Enversys two input inverter may now deliver power from PV panel
| #define SHARED_MEM_DATA_SIZE |
Size of defined master slave communication data in shared memory.
This macro calculates the size in bytes of the shared memory area, see valsSharMem_t. The size of the shared memory SHARED_MEMORY_SIZE should be chosen as a multiple of 256 (512) bytes. The extra bytes are usable as an array uint8_t fill[] of size SHARED_MEM_FILL_SIZE.
| void chgFilNames | ( | void | ) |
| int batSOCbyU | ( | float | uBat | ) |
Battery capacity or state of charge (SOC) in % by voltage.
This function yields the SOC (capacity) in % as integer 0..100 for a LiFePo4 12V battery. Values 101..111 cover the upper band of the operating range, where 110 (14.5V) is the max. charging voltage.
A value of -1 says Ubat is < 10.00V the 0% value meaning really empty and outside the battery's operating range 10.0V (soc = 0) to 14.5V (soc = 110). A value of 111 says Ubat may be 14.6V which is the upper end of the allowed operating range. 112 says above 14.6V and hence outside allowed operation.
The values 101 to 110 may very well occur during charging and some time afterwards.
The index 0..100 is the SOC in % for the the idle state. That is no charging or discharging current worth mentioning, say less than 2A.
The values for 0, 10, 20 ... 90, 100, 109, 110 and 111 are from the EcoWorthy manual. The gaps were filled by linear interpolation.
The accuracy of the SOC values and the voltage measurement is about 10 mV and probably below. Hence two decimal places for U values as in the EcoWorthy manual are adequate. Nevertheless we partly use three decimal places for interpolated U values, to avoid equal values in adjacent entries in table uBatBySOC. So, this look up function batSOCbyU may yield any value in the range -1 .. 111 by binary search.
| uBat | battery voltage / V |
|
extern |
Path of the table to log a set of values for every day.
This is the text file in csv format where a set of day start values is recorded for every day shortly after midnight.
It will be used "endlessly". To set an end respectively close that diary just rename the file. A new "dayFile" will then be created an used hence on.
|
extern |
Path of the daily event file.
The current date in the format 2025-09-30 has to be set at position EFNY by chgFilNames().
The event file outLog is a text file used for one day for events and currently (see useOutLog4errLog) for errors, also.
|
extern |
Path of the daily retain file.
The current date in the format 2025-10-20 has to be set at position RFNY by chgFilNames().
The retain file is currently a short binary file for just one day kept in the file name. It contains start values for shortly after midnight for this day, only. It will be read in the case the program would be re-start at that day instead of running on 24-7.
The values stored are (example):
|
extern |
Battery voltage by capacity or state of charge (SOC) in %.
This table is the Ubat(SOC) function of the LiFePo4 12V battery. The index 0..100 is the SOC in % for the the idle state. That is no charging or discharging current worth mentioning, say less than 2A.
The values for 0, 10, 20 ... 90, 100 are from the EcoWorthy manual. The gaps were filled by linear interpolation. The values for [101..110] goto the limit of the charging voltage 14.6V. The value [111] is the upper end of the battery's operating range 10..14V. See also batSOCbyU.
|
extern |
Descriptive and state array for smart meters on Modbus.
The number of meters is ANZmodSLAVES.
|
extern |
The common command look up table.
It must end with an entry {"", 0}.
The current (CGI) program uses linear search for the command mnemonic. Hence, and cause of structure, alphabetic sorting is of no avail.
|
extern |
The packet switch control values.
The array holds the number of on and off phases (i.e. 20 ms periods at 50 Hz line frequency) for each percentage of full power. The array length is 101; the index [0..100] is, hence, directly the percentage wanted.
To avoid too visible flicker, for no set (phPckSwSets[i].onPhases, phPckSwSets[i].offPhases) the smaller of the two values would be greater than 4 (80 ms); in most cases it is 1 or 2 (40 ms).
|
extern |
Last valid power line frequency.
The measurement is taken from the more precise home three phase meter if communicative via Modbus. Otherwise the other meter's value is taken if available. Due to slow Modbus communication the values may be older than two seconds worst case.
This low sampling rate won't comply with VDE-AR-N 4105 cut off rules requiring a 0.1s reaction outside 47.5..51.5Hz. Nevertheless the current experimental set-up is a working proof-of-concept implementation (with very low power) — and a faster frequency measurement could easily be implemented.
Last valid power line frequency.
|
extern |
Last value of tank water temperature.
This value will be the last good .tempTankTop (see valFilVal_t) or the last good .tempPipe. If neither is good for 251 measurements BAD_TEMP_READ (an incredibly high value) will be set.
This last tank water temperature will be checked against a safety limit to allow electric heating as ballast.
The value is in units of 1/1000 grdC.
|
extern |
Tank water temperature bad read count.
This last tank water temperature will be checked against a safety limit to allow electric heating as ballast.
In case of too many bad reads the value must be fixed at 253
|
extern |
The miniJoule inverter has battery unload power.
Or at least may still have due to step up converter capacitors.