Linking a string and integer together to create a string for notifications

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

//

What error is being logged?

3 suggestions that might help:

  1. Use VSCode to debug your rules
  2. Use Code Fences when posting rules in the forum
  3. Add logInfo statements within your rule to help you debug

make sure also that you use the correct quotation marks in your rules file:

rule "Zone 1 Watering"

instead of:

rule “Zone 1 Watering”

Lots of minor things I see.

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.

Thanks for the tip.

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?

Have a look at Design Pattern: Cascading Timers for a way to deal with most of these edge cases.

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 don’t use the Weather binding.

Hey quick question.

Im getting random times in the log which is running the
when
started

rule

//rule "Reset Irrigation at OH Start"
//when
//    System started
//then

//	SprinklerSystemZone1.sendCommand(OFF)
//	SprinklerSystemZone2.sendCommand(OFF)
//	SprinklerSystemZone3.sendCommand(OFF)	
//	SprinklerSystemZone4.sendCommand(OFF)
//	Irrigation_Zone1.postUpdate("Inactive")
//	Irrigation_Zone2.postUpdate("Inactive")
//	Irrigation_Zone3.postUpdate("Inactive")
//	Irrigation_Zone4.postUpdate("Inactive")
//	Countdown_Zone1.postUpdate(0)
//	Countdown_Zone2.postUpdate(0)
//	Countdown_Zone3.postUpdate(0)
//	Countdown_Zone4.postUpdate(0)

//end

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?

You can you the restoreOnStartup persistence with the mapdb persistence
It will restore your items to the last saved state when the system starts up

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.

I don’t think this is correct.
When I modify an item file, only the items in that file exhibit the behaviour you describe above. Not all the items.

If that is the case it is a recent change.