[SOLVED] Sitemap Selection Days List based on Month Entry

I have created an entry in my Sitemap to enter a date and time. There are four Number Selections: Month, Day, Hour, Minute.

Is there a way to make the Selection list for Day of the month to be dependent on the month selected? For example, If I choose June, the days that can be selected are 1-30, July: 1-31, February: (non-leap year) 1-28, February: (leap year) 1-29?


sitemap tmp label="TMP" {
    Setpoint item=year  minValue=1900 maxValue=2018
    Setpoint item=month minValue=1 maxValue=12
    Setpoint item=day   minValue=1 maxValue=28 visibility=[max_days<=28]
    Setpoint item=day   minValue=1 maxValue=29 visibility=[max_days==29]
    Setpoint item=day   minValue=1 maxValue=30 visibility=[max_days==30]
    Setpoint item=day   minValue=1 maxValue=31 visibility=[max_days==31]

and build a rule to set the item-state of max-days to 28,29,30 or 31 depending of selected year and month.

Setpoint item=day minValue=1 maxValue=29 visibility=[month==2]
Setpoint item=day minValue=1 maxValue=30 visibility=[month==4, month==6, month==9, month==11]
Setpoint item=day minValue=1 maxValue=31 visibility=[month==1, month==3, month==5, month==7, month==8, month==10, month==12]
1 Like

@hr3 Harry,

Thanks for this. Truly! I have taken your idea and converted it to my specifics where I’m using Selections rather than Setpoints. All pretty much working like a charm. I have each “type” of month working with limits to the Selection days of the month… except I’m trying to implement February with a check for leap year so I can set 28 or 29 days.

I’m trying to have the 'puter tell me the last day in February using something like this:

dtTimestamp = new DateTime(now.getYear,3, 1, 0, 0, 0, 0).millis - 1

(I know that syntax and data typing is all wrong… because it’s erroring out). I’ve read @rlkoshak Rich Koshak’s Time of Day Design Pattern and a ton of other posts regarding date and time manipulation… but I’m no less baffled.

Conceptually, I want to have the system generate a value for March 1 of the desired year (e.g., current) right at midnight and go back one millisecond to yesterday (i.e., last day of February). Then I’ll parse that DateTime value to grab the day of month element… and use that to set the Days of Month list visibility flag.

I’m probably overthinking this and there’s probably a much more straightforward way to get the last day of the month of February for a given year. As I said in a separate track, I’m not proud. I’ll take code donations… especially after spending three hours trying to make that simple concept work!



Use the methods of DateTime to your advantage.

val int lastDayOfFeb = new DateTime(now.getYear, 3, 1, 0, 0, 0, 0).minusMinutes(1).getDayOfMonth

So we create a new DateTime for the the current Year, March 1 at midnight, subtract a minute (it doesn’t matter how much we subtractso long as it’s no more than a day, then get the day of the month from that.

Determine leap day - check. @rlkoshak
List proper days in month - check. @hr3
Set event trigger based on entered date - check. @rlkoshak @5iver

OH Project complete. On to the next OH project!

Thank you all!


1 Like

Unfortunately, this does not work any more for OH3.
It throws the error

[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'home-79' failed: An error occurred during the script execution: null in home

Any ideas on what to change?

Okay, solved it by replacing the script by Ephemeris.

can you post how you adapted it to OH3?

To be honest, I found out that my Ephemeris solution did not work.
Now I simply always use 28 days for Feb - it is only used for solar inverter revenue calculation here.
Sorry to not be able to help further…