Can anybody help me.
I come from excel coding, so im still new to this. I have this code which detects whether my number is greater than 0, and if so, then it runs a timer function and then shuts off, otherwise if timer is 0, then it just runs without shutting off.
But I am trying to change the string that the sendnotification uses, to include the timer minutes.
this is some code i have tried.
Nothing i have tried so far works.
Any help?
//
rule “Zone 1 Watering”
when
Item SprinklerSystemZone1 changed to ON
then
var Number timeout = onHours1.state as DecimalType
var int lawnTime = (timeout).intValue
var String numberAsString = "Watering for " + String.valueOf(lawnTime)
postUpdate(Irrigation_StartTime1, new DateTimeType())
if (lawnTime > 0)
{
sendBroadcastNotification(numberAsString)
createTimer(now.plusMinutes(lawnTime)) [|
sendCommand(SprinklerSystemZone1, OFF)
]
}
else {
sendBroadcastNotification(“Watering Zone 1”)
}
end
you don’t need the parents around timeout. Just use timeout.intValue
you don’t need timeout at all really var lasnTime = onHours1.state as Number Don’t cast things down to primitives unless you have to. Later, if for some reason you do need it as a strong because the Rules engine can’t figure it hot to convert it on its own, just call lawnTime.toString
whether lawnTime is an int or a Number, you can just use "Watering for " + lawnTime
And a final but if advice: irrigation had the proposal to be expensive and can cause damage if you get your rules wrong it miss an edge case (e.g. what happens if oh goes down while irrigation is running?). I would not choose this as my first foray into learning rules. The risk of getting it won’t are too high and the code will become very complex as you try to handle all the edge and error cases.
I was able to get it to work using timeout.toString
the rules still need to be tidied up, as most things are copied. Ive only been working on this for about 3 days.
The irrigation setup is all done, and everything works as it should Im still in the testing phase right now. I do understand that damage can be caused, but so far, i have had the main pipe come loose as it was not designed to handle mains water, and flood the rear yard overnight. My irrigation setup is pretty good in a way that it wont do much damage if it does flood, as we have drainage that works well.
I love in the high desert with some of the most expressive water in the world. If I had the same problem and my back yard flooded over night, that would be at least a $200 mistake, assuming I didn’t get a fine on top of the water wasted. I’m very sensitive to this stuff as a result.
Now that you have it working, think about all the error cases. What happens if oh reboots while the system is on? (Hint, all your timers will go away). What happens if oh is off during the time that a zone is supposed to turn on or off? Is there any feedback to let you know whethera barber is open or closed?
Thanks heaps rikoshak, Im going to build in a watchdog to the arduino and have it reset. and on reset to turn off everything. I appreciate the feedback.
Any idea on my other question regarding weather setup in OH2, I have another topic posted.
I have commented it out for now, as its randomly setting all of these values while running. any idea what could cause this. Can there be issues when the files can not be set correctly. due to spelling mistake or something else. Would that cause something to restart.
One other thing i have, is when i make changes to the items or sitemaps file. sometimes it resets my onHours and my Garage Sensors to null.
is there a way we can set a default to a number, or a string?
When ever you save a .rules file all the System started Rules in that file will run.
When ever you save a .items file all of the Items, not just the ones in that file, get reset to NULL. If you after using persistence with restoteOnStartup, the items configured to be restored will be set to the most recent value saved in persistence.
Changes to the sitemap file will not change the states of any items nor will it cause any rules to run.