logInfo("AstroActions", "{} will be positioned at elevation {} - azimuth {}",sunEvent, elevation.toString,azimuth.toString)
```
+### getTotalRadiation(timeStamp)
+
+Retrieves the total radiation (QuantityType<Intensity>) of the sun at the requested instant.
+Thing method only applies to Sun thing type.
+
+```java
+ val totalRadiation = sunActions.getTotalRadiation(ZonedDateTime.now)
+ logInfo("AstroActions", "Currently, the total sun radiation is {}", totalRadiation.toString)
+```
+
## Tips
Do not worry if for example the "astro dawn" is undefined at your location.
import org.openhab.binding.astro.internal.AstroBindingConstants;
import org.openhab.binding.astro.internal.handler.AstroThingHandler;
import org.openhab.binding.astro.internal.handler.SunHandler;
+import org.openhab.binding.astro.internal.model.Radiation;
import org.openhab.binding.astro.internal.model.SunPhaseName;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.ActionOutput;
import org.openhab.core.automation.annotation.RuleAction;
+import org.openhab.core.library.dimension.Intensity;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.thing.binding.ThingActions;
import org.openhab.core.thing.binding.ThingActionsScope;
return null;
}
+ @RuleAction(label = "get the total sun radiation", description = "Get the total sun radiation for a given time.")
+ public @Nullable @ActionOutput(name = "getTotalRadiation", label = "Total Radiation", type = "org.openhab.core.library.types.QuantityType<org.openhab.core.library.dimension.Intensity>") QuantityType<Intensity> getTotalRadiation(
+ @ActionInput(name = "date", label = "Date", required = false, description = "Considered date") @Nullable ZonedDateTime date) {
+ logger.debug("Astro action 'getTotalRadiation' called");
+ AstroThingHandler theHandler = this.handler;
+ if (theHandler != null) {
+ if (theHandler instanceof SunHandler sunHandler) {
+ Radiation radiation = sunHandler.getRadiationAt(date != null ? date : ZonedDateTime.now());
+ return radiation.getTotal();
+ } else {
+ logger.info("Astro Action service ThingHandler is not a SunHandler!");
+ }
+ } else {
+ logger.info("Astro Action service ThingHandler is null!");
+ }
+ return null;
+ }
+
@RuleAction(label = "get the date time of a sun event", description = "Get the date time of a sun event.")
public @Nullable @ActionOutput(name = "getEventTime", type = "java.time.ZonedDateTime") ZonedDateTime getEventTime(
@ActionInput(name = "phaseName", label = "Phase", required = true, description = "Requested phase") String phaseName,
return ((AstroActions) actions).getAzimuth(date);
}
+ public static @Nullable QuantityType<Intensity> getTotalRadiation(ThingActions actions,
+ @Nullable ZonedDateTime date) {
+ return ((AstroActions) actions).getTotalRadiation(date);
+ }
+
public static @Nullable ZonedDateTime getEventTime(ThingActions actions, @Nullable String phaseName,
@Nullable ZonedDateTime date, @Nullable String moment) {
if (phaseName != null) {
import org.openhab.binding.astro.internal.calc.SunCalc;
import org.openhab.binding.astro.internal.job.DailyJobSun;
import org.openhab.binding.astro.internal.job.Job;
-import org.openhab.binding.astro.internal.model.Planet;
-import org.openhab.binding.astro.internal.model.Position;
-import org.openhab.binding.astro.internal.model.Range;
-import org.openhab.binding.astro.internal.model.Sun;
-import org.openhab.binding.astro.internal.model.SunPhaseName;
+import org.openhab.binding.astro.internal.model.*;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.scheduler.CronScheduler;
import org.openhab.core.thing.Thing;
thingConfig.useMeteorologicalSeason);
}
+ private Sun getPositionedSunAt(ZonedDateTime date) {
+ Sun localSun = getSunAt(date);
+ Double latitude = thingConfig.latitude;
+ Double longitude = thingConfig.longitude;
+ Double altitude = thingConfig.altitude;
+ sunCalc.setPositionalInfo(GregorianCalendar.from(date), latitude != null ? latitude : 0,
+ longitude != null ? longitude : 0, altitude != null ? altitude : 0, localSun);
+ return localSun;
+ }
+
public @Nullable ZonedDateTime getEventTime(SunPhaseName sunPhase, ZonedDateTime date, boolean begin) {
Range eventRange = getSunAt(date).getAllRanges().get(sunPhase);
if (eventRange != null) {
@Override
public @Nullable Position getPositionAt(ZonedDateTime date) {
- Sun localSun = getSunAt(date);
- Double latitude = thingConfig.latitude;
- Double longitude = thingConfig.longitude;
- Double altitude = thingConfig.altitude;
- sunCalc.setPositionalInfo(GregorianCalendar.from(date), latitude != null ? latitude : 0,
- longitude != null ? longitude : 0, altitude != null ? altitude : 0, localSun);
+ Sun localSun = getPositionedSunAt(date);
return localSun.getPosition();
}
+
+ public @Nullable Radiation getRadiationAt(ZonedDateTime date) {
+ Sun localSun = getPositionedSunAt(date);
+ return localSun.getRadiation();
+ }
}