Implementing an Astro Sunrise/Sunset Function on Siemens LOGO! 8
Siemens LOGO! logic modules do not ship with a native Astro function block, yet lighting, irrigation, and shutter applications frequently require a digital sunrise/sunset switch that follows the annual solar cycle at a fixed installation site. This reference documents four field-proven approaches - almanac lookup, simplified astronomical formula, KNX/EIB timer integration, and photovoltaic sensor tracking - with worked LOGO! Soft Comfort FBD code, parameter tables, and verification steps sized for garden-lighting accuracy (≤ 20 minutes).
1. Problem Definition and Accuracy Targets
The user requirement is straightforward: a Boolean output on a LOGO! that goes HIGH at local sunrise and LOW at local sunset, automatically tracking the changing day length across a 12-month cycle at a single fixed geographic coordinate (latitude, longitude). No GPS is required; the site is static.
| Parameter | Target | Comment |
|---|---|---|
| On-time error vs. true sunrise | ≤ ±20 min | Civil twilight band; acceptable for garden lighting |
| On-time error vs. true sunset | ≤ ±20 min | Same; conserves program space over sub-minute accuracy |
| Day-length drift over 12 months | ≤ 5 min/month | Driven by the 365-day resolution of the lookup table |
| Daylight Saving Time handling | Automatic | LOGO! RTC supports DST via menu; configure once at commissioning |
| Latitude range | -65° to +65° | Beyond this, civil twilight is undefined; use polar day/night fallback |
| Power-fail retention | ≥ 480 h | LOGO! 0BA8 retains RTC for ~480 h on the super-cap; 0BA9 with battery CR2032 ~2 years |
2. Hardware Selection
All four approaches below run on the LOGO! 8 system family (0BA8, 0BA9, 0BA10). The specific part numbers most commonly used for Astro switching applications are listed below.
| Catalog No. | Model | Role | Notes |
|---|---|---|---|
| 6ED1052-1MD08-0BA1 | LOGO! 8 BM 12/24RCE | Logic + relay outputs | 4 DI/4 DO, AI0/AI1 analog; relay 8 A |
| 6ED1052-1FB08-0BA1 | LOGO! 8 BM 24CE | Solid-state 24 V | 4 DI/4 DO transistor; faster switching |
| 6ED1052-1HF08-0BA1 | LOGO! 8 BM 230RCE | Mains-powered site | 8 DI/4 DO relay; no AI on mains unit |
| 6ED1055-1MM00-0BA2 | LOGO! 8 DM 16 | I/O expansion | Adds 8 DI / 8 DO when more than 4 of each is required |
| 6ED1055-1MA00-0BA2 | LOGO! 8 AM2 | Analog input expansion | 0-10 V or 0/4-20 mA inputs for PV-cell approach |
| 6ED1057-4EA00-0BA1 | LOGO! 8 CM EIB/KNX | KNX integration | Used in Approach 3 for external Astro timer |
| 6ED1055-4MH00-0BA1 | LOGO! 8 TDE | Text display | Optional, shows sunrise/sunset and override status |
Refer to the LOGO! 8 System Manual (Siemens Support, 109741041) for the full device specification, in particular the maximum number of function blocks (0BA8: 400 blocks; 0BA9: 800; 0BA10: 800 with multi-page program support).
3. Approach 1 - Almanac Lookup Table (Simplest, Recommended for 20-min Accuracy)
The most reliable method on LOGO! is to pre-compute the year's sunrise and sunset times in a spreadsheet, then load the values as constants. Because the LOGO! has no trig instructions but has shift registers and analog comparators, a 365-step lookup is trivially implementable.
3.1 Compute the Almanac Offline
Use the NOAA Solar Calculator algorithm. For latitude φ (positive north), longitude λ (negative west), in the northern hemisphere at solar declination δ, the hour angle H of sunrise/sunset is:
cos(H) = -tan(φ) · tan(δ)
with solar declination approximated as:
δ = 23.45° · sin(360° · (284 + n) / 365)
where n is the day-of-year. Solar noon in local mean time (LMT) is then:
LST = 12:00 + EoT - 4·λ + DST_offset
with the Equation of Time (minutes):
EoT = 9.87·sin(2B) - 7.53·cos(B) - 1.5·sin(B), B = 360°·(n - 81) / 365
Sunrise = LST - H, Sunset = LST + H. Worked example for Berlin (52.52° N, 13.40° E) yields:
| Day of year | Date | Sunrise (CET) | Sunset (CET) | Day length |
|---|---|---|---|---|
| 1 | Jan 1 | 08:18 | 16:02 | 7 h 44 m |
| 80 | Mar 21 (equinox) | 06:09 | 18:21 | 12 h 12 m |
| 172 | Jun 21 (solstice) | 04:43 | 21:33 | 16 h 50 m |
| 266 | Sep 23 (equinox) | 06:52 | 19:01 | 12 h 09 m |
| 355 | Dec 21 (solstice) | 08:14 | 15:54 | 7 h 40 m |
3.2 LOGO! Soft Comfort Implementation
The implementation pattern uses the LOGO! 8 weekly timer and yearly timer blocks. Although a single yearly timer accepts a maximum of 16 date/time pairs, three yearly timers cover the 32 transitions of a typical year when combined with on/off-pulse variants. The minimal block diagram is:
- Set "Yearly Timer 1" with the 8 day-of-year entries bracketing the spring-summer half (Feb 10 → Jun 5 sunrise). One output Q1 = "Sun is up".
- Set "Yearly Timer 2" with the 8 entries for the summer-fall half (Jun 5 → Oct 28). This avoids midnight-crossing overlap with Timer 1.
- Set "Yearly Timer 3" for the off-season entries (Oct 28 → Feb 10) where the day length is < 9 h.
- OR-combine the three Q outputs into Q_SunUp.
- Optional: add an "Off-delay" block (parameter = 20 min) so the lights remain ON for a buffer after sunset.
// LOGO! FBD pseudocode
[Yearly Timer 1: Feb10_on..Jun05_off] --Q1--\
[Yearly Timer 2: Jun05_on..Oct28_off] --Q2---+--[OR]--- Q_SunUp --[Off-delay 20 min] --Q1_output
[Yearly Timer 3: Oct28_on..Feb10_off] --Q3--/
3.3 Day-of-Year Resolution
If sub-10-minute accuracy is required, replace the three Yearly Timers with a free-running Shift Register holding 365 sunrise minutes and 365 sunset minutes. Generate the index from the RTC via an arithmetic block:
day_of_year = (month_code[1..12] lookup) + day - 1
Use the LOGO! Analog Multiplexer block to select today's pair, then compare against the RTC time-of-day with two Analog Threshold Triggers (one rising for sunrise, one falling for sunset). This consumes ~25 function blocks, well within 0BA8's 400-block budget.
4. Approach 2 - Simplified Astronomical Formula (On-Device, No Table)
LOGO! 0BA8 supports integer addition, subtraction, multiplication, and division, but not trigonometric functions. A direct on-device formula is therefore not feasible. The only on-device option without trig is a polynomial fit of sunrise/sunset over a 12-month period:
sunrise_minutes_from_midnight ≈ a0 + a1·cos(2π·n/365) + b1·sin(2π·n/365) + a2·cos(4π·n/365) + b2·sin(4π·n/365)
Coefficients a0, a1, b1, a2, b2 are pre-computed in a spreadsheet for the site latitude and hard-coded as LOGO! analog constants. The LOGO! can then implement the sum using five Math Instruction blocks chained together. Accuracy is typically ±25 min over the year - usable for garden lighting, marginal for shutter control.
5. Approach 3 - External KNX/EIB Astro Timer
When a KNX installation already exists, the cleanest approach is to delegate the Astro calculation to a KNX actuator with a built-in Astro function. The Siemens LOGO! 8 CM EIB/KNX (6ED1057-4EA00-0BA1) integrates the LOGO! into the KNX bus. The Theben TR 648 top2 RC or Jung TRDA-2 KNX Astro timers publish a 1-bit sunrise/sunset object daily over KNX.
5.1 Topology
5.2 LOGO! Side Configuration
In LOGO! Soft Comfort, open the EIB/KNX editor and bind:
- Network input
NI 1← KNX group1/0/15(1-bit, sun below horizon) - Network input
NI 2← KNX group1/0/16(1-bit, sun above horizon)
The FBD reduces to a single OR block feeding the lighting relay. This is the most compact approach (~5 function blocks) and the most accurate (±1 min, since the KNX timer does the trig).
6. Approach 4 - Photovoltaic Sensor Tracking (Closed-Loop, No Almanac)
For installations that need a truly self-calibrating solution and where pointing accuracy matters more than civil-twilight accuracy (e.g. solar panel positioning, greenhouse louvre control), two photovoltaic cells can be wired in a differential configuration. The LOGO! reads the differential and drives a pair of motor outputs. The advantage: no almanac, no latitude data, automatically follows weather and actual cloud cover. The disadvantage: it tracks the brightest source, not necessarily the sun.
6.1 Sensor Circuit
| Component | Specification |
|---|---|
| PV cell | 5 V/100 mA mini-panel, 80×60 mm, Voc ≈ 4.8 V |
| Series resistor | 10 kΩ across each cell (load) |
| Differential amplifier | LM358, gain 1, single supply 12 V |
| Output to LOGO! AI0, AI1 | 0-10 V (0 V = dark, 10 V = full sun) |
| Cell mounting | Back-to-back on common heat-sink, normal vectors separated by 90° |
6.2 LOGO! Soft Comfort FBD
The corresponding LOGO! blocks:
- Two Analog Amplifier blocks scale AI0 and AI1 to 0-1000 (raw mV / 10).
- One Math Instruction block computes
Δ = AI0 - AI1. - Two Analog Threshold Triggers detect
Δ > +0.2 VandΔ < -0.2 V. - An RS-flip-flop holds the drive direction; an off-delay of 60 s prevents hunting.
- Q1 → motor contactor east, Q2 → motor contactor west.
7. Cross-Platform Comparison
| Approach | Function Blocks | Accuracy | External HW | Best use case |
|---|---|---|---|---|
| 1. Almanac lookup | ~25 | ± 5-10 min | None | Garden lighting, shutters, fixed sites |
| 2. Polynomial fit | ~15 | ± 25 min | None | Decorative lighting, low-budget sites |
| 3. KNX Astro timer | ~5 | ± 1 min | CM EIB/KNX + KNX timer | KNX installations, commercial sites |
| 4. PV sensor tracking | ~40 | Sub-degree | PV cells + amplifier | Solar panels, heliostats, moving loads |
| (Vendor X solar library) | ~300+ | ± 1 min | None | Not applicable on LOGO! |
8. Commissioning Procedure (Approach 1, Almanac)
8.1 Prerequisites
- LOGO! Soft Comfort V8.2 or newer (V9.0 for 0BA9/0BA10)
- Ethernet or micro-SD connection to the LOGO! 8 BM
- Site coordinates (decimal degrees, WGS84)
- Reference year (2025) NOAA sunrise/sunset CSV export for the site
8.2 Step-by-Step
- Set the LOGO! clock. On the LOGO! HMI, navigate to Settings → Date/Time, set the timezone, and enable DST auto-adjustment. This is the single most common commissioning mistake - an incorrectly set timezone will shift sunrise/sunset by exactly 1 hour.
- Open LOGO! Soft Comfort and create a new program. From the toolbar, drag three Yearly Timer blocks (Y1, Y2, Y3) and one Off-Delay block (T1) onto the worksheet.
-
Configure Y1 with the day-of-year on/off pairs for the spring-summer half. Use the table editor in LOGO! Soft Comfort: click the block, select Yearly Timer, and add rows. Format:
MM/DD hh:mmfor the ON,MM/DD hh:mmfor the OFF. - Configure Y2 and Y3 for the remaining months. Verify that the intervals are disjoint - if a single minute is covered by two timers, the OR will still produce the correct output, but the project becomes harder to audit.
-
Wire Y1, Y2, Y3 outputs to a 3-input OR gate, then to the Off-Delay T1 with parameter
Th = 00:20. T1 output drives Q1. - Compile with F5 and check the resource count. The Info dialog should show < 20 blocks used.
-
Download the program over Ethernet. The LOGO! 8 web server can also accept
.lscuploads - log in as admin, go to Toolbox → Upload. - Force the output via Online → Force Q1 = 1 for 5 s to confirm the wiring reaches the load.
8.3 Verification Tests
| Test | Method | Pass criteria |
|---|---|---|
| Time-of-day | Compare LOGO! clock with NTP reference | Δ < ± 30 s |
| Spring equinox | Force LOGO! RTC to 2025-03-21 06:00, monitor Q1 | Q1 = 0 before 06:09, Q1 = 1 by 06:10 |
| Autumn equinox | Force LOGO! RTC to 2025-09-23 19:00, monitor Q1 | Q1 = 1 before 19:00, Q1 = 0 by 19:02 |
| Year-end | Force LOGO! RTC to 2025-12-21 16:30, monitor Q1 | Q1 = 0 by 15:55 ± 5 min |
| DST transition | Watch Q1 around last Sunday of March / October | No glitch; transition at 02:00 → 03:00 / 03:00 → 02:00 |
| Power-fail retention | Cut supply for 5 h, restore, check Q1 vs. RTC | RTC retained; Q1 follows schedule within 1 min |
9. Memory and Cycle Time Considerations
LOGO! 0BA8 executes a fixed scan cycle; for the almanac approach the cycle time is unaffected because the Yearly Timer is event-driven. For the shift-register approach, an additional Analog Multiplexer adds ~2 ms per scan. On a 0BA8 with 25 function blocks, the typical cycle is 8-15 ms, well within the 50 ms budget for lighting control.
Memory footprint:
| Item | RAM bytes (0BA8) | Retained |
|---|---|---|
| Program (FBD) | 2 400 | Yes (flash) |
| Almanac table (365 × 4 B) | 1 460 | Yes (retain) |
| Remainder of project | ~ 1 200 | Volatile |
| Total | ~ 5 060 of 8 500 free |
10. Troubleshooting Matrix
| Symptom | Likely cause | Diagnostic | Fix |
|---|---|---|---|
| Lights ON at midnight | Three timers overlap and produce 24 h coverage | Open LOGO! Online → Watch Y1, Y2, Y3 simultaneously | Trim overlap; verify date pairs in Yearly Timer editor |
| Switching ± 1 h off | Timezone mis-set | Settings → Date/Time → Timezone | Set correct UTC offset; re-flash |
| No switching at all | RTC dead - super-cap drained | Power-cycle, observe clock drift | Leave powered 24 h; replace CR2032 on 0BA9 |
| Switching in summer OK, winter OFF | Winter timer Y3 missing sunrise entries | Open Y3, check ON/OFF rows | Add the 8 winter day-of-year transitions |
| Drift over the year | Polynomial approach (Approach 2) at high latitude | Compare logged Q1 transitions with USNO data | Switch to Approach 1 lookup |
| Tracker swings wildly on cloudy day | PV cell differential noisy | Scope AI0 - AI1 with LOGO! online trace | Add 60 s off-delay; cap minimum irradiance |
| KNX Astro object never updates | ETS group address not linked | ETS bus monitor on group 1/0/15 | Re-link in ETS, re-download to LOGO! CM |
11. Best-Practice Checklist
- Always pre-compute the almanac with a known-good spreadsheet (e.g. NOAA Solar Calculator, suncalc.js) and paste the result into LOGO! Soft Comfort - never trust an on-the-fly trig approximation on the LOGO!.
- Define a single "Astro_SunUp" flag and use it as an enable for downstream logic, not as a direct relay drive. This makes overrides (holiday, maintenance) easy to implement.
- Add a 20-min off-delay buffer to absorb sub-minute cloud cover at sunrise/sunset - this matches the original requirement of ±20 min accuracy for garden lighting.
- Configure DST in the LOGO! menu, not in the program. The RTC hardware handles the transition; user programs should treat clock time as opaque.
- Document the latitude, longitude, and time-zone on the inside of the cabinet door. A future commissioning engineer will need them to update the almanac next year.
- For a multi-year deployment, consider switching to a 0BA9 with a CR2032 battery - the super-cap on 0BA8 is rated for ~480 hours, and a long winter power outage will lose the clock.
12. Frequently Asked Questions
Does any version of LOGO! have a built-in Astro function block?
No. The LOGO! 0BA6, 0BA7, 0BA8, 0BA9 and 0BA10 firmware families all ship without a native Astro block. The integrated yearly/weekly timers can reproduce the Astro behaviour only if the sunrise/sunset times are pre-computed offline and entered as up to 16 ON/OFF pairs per timer (three timers are required to span a full year without overlap).
What is the minimum function block count for a usable Astro program on LOGO! 8?
Five blocks is achievable when a KNX Astro timer supplies the sunrise/sunset signals (Approach 3): three OR gates, one off-delay, one output. The almanac approach (Approach 1) needs about 25 blocks; the PV tracker (Approach 4) needs about 40. The 0BA8 firmware supports up to 400 blocks, so even the 40-block tracker fits with 90 % of the program space still free.
Can I do the trig calculation directly on the LOGO! with a custom function block?
No. LOGO! 8 only provides addition, subtraction, multiplication, division, and absolute-value math instructions. It does not provide sin, cos, tan, or atan2, and there is no UDF (User Defined Function) mechanism for adding new primitives. A on-device trig solution is therefore not possible without external hardware.
How accurate is the almanac approach for a German site at ~50° N?
For Berlin (52.52° N, 13.40° E) the worst-case 2025 deviation between the NOAA calculation and the LOGO! Yearly Timer with 8-day resolution is ± 11 minutes. For a 50.0° N site the worst-case deviation is ± 9 minutes, which is comfortably inside the 20-minute garden-lighting target. Equinox weeks (March 20-23 and September 22-25) drive the worst error because the day length changes by 3 minutes per day.
How do I handle Daylight Saving Time transitions in the Astro logic?
Do not handle DST in the application code. Configure DST in the LOGO! HMI under Settings → Date/Time, selecting "Auto DST". The internal RTC advances at 02:00 → 03:00 on the last Sunday of March and falls back at 03:00 → 02:00 on the last Sunday of October. The Yearly Timer blocks reference the clock directly, so they follow the transition automatically. Verify once at commissioning by forcing the RTC to 2025-03-30 01:55 and watching the transition.
Can the LOGO! Astro function be used for shutter control, or is it only suitable for lighting?
For lighting, ± 20 min is acceptable. For shutter control the typical industry requirement is ± 5 min, which requires the almanac approach (Approach 1) with a 5-day resolution - that is 73 ON/OFF pairs, exceeding the 16-pair limit of a single Yearly Timer. Split across five Yearly Timers (with disjoint intervals), this fits within 0BA8's 400-block limit. The KNX approach (Approach 3) is the more robust choice for shutter control.