Help simplifing a long yet repetitious piston


#6

Yeah, the 1 min is just for testing.

And I can’t have it on change of Temp, as the temp changes in 0.1 increments quite frequently.


#7

The hour 24 you mentioned gave me an idea.

At the moment the variables are called

1600_1700 (which is the variable integer for anything between 4pm and 5pm)

Sorry, not sure how to do this, but if I just changed the variables to be:
16 (instead of 1600_1700), then…
17
18 etc,

Then could I run a Piston every so often, but use the result of $hour24 to dynamically construct one of my repeating paragraphs? That probably sounds more complicated than it is.

For example.

Every 15 mins
If temperature is less than ($hour24)
Then
Open rad valvs
Else
Close valve

this, if 1725, would be “17”, so somehow the ($hour24) part would be populated with the valie of the variable called 17

Does that makes sense?

If poss, would cut out a hell of a lot of code!


#8

You can create a new mini piston for that.

Every 1 hour
    Set @global to X
END EVERY

This way, your monstrosity can simply refer to the current temp stored in the global variable.


#9

haha @ monstrosity…you’re really not wrong there…

For reasons too boring to mention, I’d like to avoid relying on an hourly piston to determine something.

But I’m currently attempting to figure out how to get something to spit out the result “17” if it’s “1756”…I am currently playing with it and searching

…progress! Managed to figure out how to store 'contact03" value as “21” if the time is 2129 (anything 21xx-2159).

Now I just need to figure how to use the value of the variable with the name “21”…


#10

Selecting your temperature setting might be a good place for a switch statement? You can use the fall through setting if you have a lot of the same value. Would look something like this:

Switch $hour24
case 0:
case 1:
case 2:
case 23:
  set tempSetting=5
  break
case 3:
case 4:
case 17:
  set tempSetting=10
  break
end switch

I didn’t fill in all the hours or the right values but hope you get the idea. One your temp setting is selected then you only need one logic block.


#11

Would it help if you defined the target temperatures in an array/list and used $hour24 as the index into it?


#12

I get the gut feeling this is probably the route to look into, but quite happy to admit I don’t understand it. Could you please elaborate ?


#13

I’ll have a look into what switch statements are, not sure at the minute… googling now…


#14

Actually, @orangebucket 's suggestion is better.

define
  string tempLevels="5,5,10,18,5"         <-- fill in complete list of 24 values
  integer tempSetting
end define

set tempSetting=arrayItem($hour24,tempLevels)

#15

trying this now, but can’t seem to save…


#16

Lists are more cumbersome to work with. You are putting the value in the name definition. All you can put there is the variable name and then you would have to write code assigning values to each index. Better to just use string as I gave in the example above.


#17

Apologies, I am trying, but I’m not familiar.


#18

Use the set variable task with the expression box like this:

EDIT: And no apologies necessary. Happy to help. We just never know what level of user knowledge we are working with. Always ask if advice isn’t clear.


#19

righto, thanks, getting there = )

I have the correct number/value getting pulled out (assuming it takes “ten past midnight” as “00”, referring to the first number in the list/array and “ten past 1 in the morning” as “01”, referring to the 2nd number in the list/array".

So… all good.I think. But now it’s obviously easier to look at a vertical list to alter temps, which at the minute I’m using by having a list of variables, i.e…

image

so it would be better (?) if those variables could be used to populate the list/array instead of a long string. If that makes sense. May sound redundant, but it’s easier to work with… still plugging. Much appreciate the help thus far, I’m sure it’s pretty easy for you guys, I’m just getting stuck in a little = )

Obviously it’s easier to


#20

You can do lots of different things but no simple way to keep the labels and still simplify your code. When assigning the value using an expression box, spaces are not significant so you can do either of these options to make it easier to count where you are at when editing:

Either will create the same result in the string and provide the same response using arrayItem.

EDIT: Sorry, I forgot to add the " " around the full string when changing to an expression. The pictures above do not work as is.


#21

Thanks, I believe I have (predictably!) a rather messy way of getting it working the way I’m referring to. Sure you understand that having a vertical list is easier to edit for the usage I have in mind.

I’ll post it in a few =)


#22

I think I’m nearly there. This looks a bit awful as promised, but allows me to use my old UI-friendly (?) format…

running the piston now (my time here is 2319 currently) sets “whichhour” variable as “1”. Which is what I wanted.

Thanks all !


#23

Well, that took a few hours of trial and error, but thought you may like to see the result.

Original piston (518 lines, 75K, very cumbersome to edit) - can’t even do a green cap because it slows my machine trying to do it!) :

New piston (75 lines, 14K, speedy and beautiful to edit

Cheers !!


#24

Lookin’ good @Djh_wolf!

Please don’t forget to reduce the frequency. You can really ruin a unit by cycling that often.


#25

Yup, will do.

But what do you mean by “can ruin a unit”? I presumed it would just slow execution. But I don’t know a hell of a lot about it to be honest.