Triggering an even or odd day valve: is it possible? Not based on the day number but rather on the date itself

Good evening;
I would like to know if I can base the triggering of a rule on odd or even days? For example, I have valves (bhyve) for watering the lawn or flowers but it is allowed according to the civic number in my town, even or odd. I search but I can't find.

For the pilot (Even Day Switch - check the day of the year and turn on a switch based on even/odd) even-odd it gives a bad reading, today June 28 it says it's a day odd. I believe it is because it is day 179 of the year.


Maybe I don't understand well but the easiest way would be to have trigger available in Hubitat.
Thanks a lot for your help!

You can use a Custom Attribute trigger in Rule Machine to do this, using that attribute.

I don't this that's the OP issue. Looks like a custom driver which is made to then use in rules. But the driver doesn't work as they want. So they need a fix for the driver or a way to directly do it in RM. The later is what is being asked but either would fix the problem.

How about a continual loop, repeating once every 48 hours?

A loop would eventually end up falling on an odd or even day? I don't believe it's reliable. If I water one day when it is prohibited, I expose myself to an infraction ticket!

Sorry I didn't read your post carefully enough. I assumed you were just trying to find a way to water alternate days. I wonder if RM has a way (in a conditional action) to get the day-of-month number, divide by 2 and see if it's a whole integer? If not, a custom app would do it. Then it just needs triggering once per day.

Actually I am going to see if I can write an app to do this. Set a boolean variable each day.

https://raw.githubusercontent.com/thebearmay/hubitat/main/evenDaySwitch.groovy is purposefully based on the day/week of the year as it's designed to provide a continual alternating sequence.

I prefer

if (dayOfMonth % 2 == 0)....

:sunglasses:

2 Likes

Unfortunately, it doesn't work for the reasons I explained above and my knowledge is quite basic . I created a virtual device with Date & Time Parser (jshimota). This gives me the day of the month (DayOfMonNum). I made a rule with REQUIRED EXPRESSION and even numbers (my civic number is even). Then I added another virtual device with the weather forecast. Another REQUIRED EXPRESSION to exclude days with the RAIN expression. I will try this.

That might be long-winded but it's easy to follow. Meanwhile I will continue work on my app, as it's all good practice :slight_smile:

I have got the app written - just testing it now over a midnight

1 Like

WoW! where can I get it?

If it correctly changes the variable just after midnight tonight I will post the code here. Basically you set up a boolean hub variable and tell the app which variable it is. On even number days the variable is true, odd days it's false, so you can use the variable as the condition or required expression.

Ok the status changed as intended, but I'd advise you at least for the first few days not to rely on it and just have it notify you whether the day is odd or even until you're sure it's getting it right.

definition (
    name: "Even Day of Month Checker",
    namespace: "simlogical",
    author: "Inge Jones",
    description: "Sets a boolean hub variable to True when the day of the month is an even number, and false when odd",
    category: "Date",
    iconUrl: "",
    iconX2Url: "",
    iconX3Url: "")


preferences {
	page(name: "mainPage", title: "Even Day of Month Checker", install: true, uninstall: true) {
		section("") 
        {
            //paragraph "Update 5"
            paragraph "Sets hub variable to indicate if the day is an even day of the month. Eg. 1st, 5th, 31st are odd, 6th and 30th are even"
            paragraph "First create a boolean hub variable.  Your variable will be True when the day is an even number and False when odd, and may then be used as condition in Rule Machine etc"
		}
        section("") {
            List vars = []
            getGlobalVarsByType("boolean").each{vars += it.key}
            input "indicator", "enum", title: "Choose a boolean variable", options: vars
		}
	}
}

def installed() {
    log.info "install ran"
    schedule("0 1 0 ? * *","checktheday")
    addInUseGlobalVar(indicator)
}

def uninstalled()
{
    log.info "uninstalled"
    removeAllInUseGlobalVar()
    unschedule("checktheday")
}

def updated() {
    unschedule("checktheday")   
    removeAllInUseGlobalVar()
    addInUseGlobalVar(indicator)  
    schedule("0 1 0 ? * *","checktheday")
    log.info "Updated"
}

def checktheday() {
    dateNow = new Date()
    dayNumber = dateNow[Calendar.DAY_OF_MONTH]
    if (dayNumber % 2 == 0) {
        log.info "checked the day " + dayNumber + " true"
        setGlobalVar("${indicator}", true)
    }
    else
    {
        log.info "checked the day " + dayNumber + " false"
        setGlobalVar("${indicator}", false)
    }
}



    type or paste code here

If you don't want the logging, comment out those lines. I can do some further work on it to make optional logging, but I wanted to get the basic script out to you asap

2 Likes

Hello;
I created the variable:

I created a Variable Connectors:
the name of de child is even_day_true:


we notice that today, July 1st (Canada Day!), the variable is set to FALSE since it is an odd day.

I will see if tomorrow the variable will change to TRUE.

Thank you very much, I appreciate it very much!

1 Like

You actually don't want the connector - the app wants direct access to the hub variable

Um, have you actually installed the app? I didn't think it should have let you choose the connector even. Can you show me a screenshot of the app's own page?

1 Like


Voici la page de l'application

Ah ok that's probably the actual variable there. You can remove the connector unless you need it for connecting to something other than rule machine, like a dashboard or something,

hello, after a few days everything works fine! Many thanks once again!

2 Likes

Great! Thank you for coming back to update me :slight_smile:

2 Likes