Something else to consider here is your use cases keep in mind how they interact.
for example, suppose it is a sunny day and the wind is greater then high_wind_threshold.
Your wind high rule is going to close the shutter but your sunny day rule is going open it right back up.
Thank you for your consideration I believe this 2 rules can integrate as it is true that if it is sunny the shutters go down but it happens once any hour between 11 and 20 so 9 times in total.
The âaverage wind ruleâ runs continuously so it keep command the shutters to roll up if it is windy.
My goal is to put the two rules together and get the avg from Rich rule and put as condition on the âsunny ruleâ to not run if itâs windy. Need to find the best strategy to do that
Could be create an item that point on the avg calculated in the âwindy ruleâ?
Actually I am a bit concerned as I donât have a light sensor and I get solar exposition in lux from a template rule This script calculate the solar exposition using sun position and cloud cover without any physical sensor
At the moment I try to understand the behaviour of this as I donât know if It can be reliable.
That is one option another you may consider is using shared cache as outline here.
As for your solar calculation again testing and review behavior for accuracy over a period of time is really the best way to decide if that is sufficient versus getting an actual device that measures the solar amount.
Thanks justanoldman I thought to a shared cache but which is the difference from a private and a shared cache? I only understood that this can be used from other rules. Isnât?
And what the reminder blocks does in a rule?
![]()
I do not understand completely this block.
It add anytime 1 to index (num_samples times)but why is / num_samples?
Should it be reminderâŠx num_samples?
the wording is self-explanatory
Private means only the rule that created it can read the key.
Shared means any rule can read the values of the key.
The block you are showing is determining index which is related to the number of samples remaining in the list and increment it by 1.
You can think of the Index value as the âaddressâ of each sample in the list same way room numbers in a building tell you where they are in a hallway. So unless you want to put all your boxes in the same room and replace the boxes that was already there you have to change âincrementâ the room number âaddressâ to a different one then if you want to make sure you are using all the rooms and keep up with how many empty ones you still have left you subtract all the rooms you already used and that is your remainder and add the rooms as you use each (1). That is stored in private cache so the rule remembers where it was last time the rule executed. IE how many rooms do you have left after you go out and get another box what is the next room you want to put a box in.
Thanks.
Understood the sense.
In the block âreminder of âis used the / symbol that led me misunderstanding.
I would expected x symbol.
I ask this as I want to understand how to use it in the future.
Once a cache is shared I can recall it in other rules just with is name as variable?
Yes, you should be able to retrieve that value based on the key name.
So if I store avg variable in a shared cache can I ask to other rule to get this number and use in the rule itself?
yes that usage is all explained in the link I shared in previous post read the section Get stored value for examples and usage. also, good video link on Global Value Storage.
The documentation is very good and helpful for understanding all of this approach. Worth the time to fully review.
See Design Pattern: Separation of Behaviors, in particular the âStore Resultâ section of the âConcept 1: Itemâ section.
I use that template and it seems to work well enough. Of course itâs only going to be as good as the inputs into the rule in the first place. If the cloudiness reading from your weather binding only updates once per hour or isnât particularly accurate for your location then the rule isnât going to accurately reflect the current amount of sunlight.
When you use the private cache, the values stored are only available in the script that put the value into it. With the shared cache, any script, even a script from another rule, can access and modify the variable stored in the cache. The shared cache is a place to store values you want to share across scripts.
Note that to share a value between a script condition and script action in the same rule you still must use the shared cache. The private cache is private to the script, not the whole rule.
You donât have a remainder when you multiply though. You only have a remainder when you divide. Given the first operand is 7 and the second operand (the one after the divide symbol) is 3, the remainder would be 1. 7 / 3 = 2 remainder 1.
Yes but be careful in your variable names in that case so you donât accidentally overwrite a variable in another rule that is using the cache for something else.
Overall, the cache approach is a good one but I prefer the Item approach mainly because the state of an Item can be used outside of scripts. You can put the average windspeed on your sitemap or MainUI for visualization, chart the average over time, and use it in simple âItem Conditionsâ or triggers on your rule.
If you apply Separation of Behaviors, the cron rule will just calculate the windspeed average and update the Windspeed_Average Item. Then you could move the code that raises and lowers the blinds to another rule that triggers on changes to Windspeed_Average. In simple cases you donât even need to write code, you can add a condition and issue a command to another Item without even needing any Blockly code at all.
What might be confusing to OP is actually related to the difference in what is being preformed as explained here (yes once again a link to how javascript works)
quoted from above
In arithmetic, the division of two integers produces a quotient and a remainder.
In mathematics, the result of a modulo operation is the remainder of an arithmetic division.
So this
var operand1 = 7;
var operand2 = 3;
var result = 0;
var remainder = 0;
result = (operand1 / operand2);
remainder = (operand1 % operand2);
console.info('Operand1 value is '+ operand1 + ' divided by ' + ' Operand2 value is '+ operand2 + ' result is '+ result + ' But the Remainder is ' + remainder);
returns this
2024-05-07 11:36:09.320 [INFO ] [nhab.automation.script.ui.74bd233d95] - Operand1 value is 7 divided by Operand2 value is 3 result is 2.3333333333333335 But the Remainder is 1
Hi Rich Why do you prefer use this rule then the Astro binding channel of radiation weighted? It give a data straight away..
I understand now the reminder meaning. That was a linguistic issue . Understood it is the amount left over now
Iâll go on item direction for triggering the shutterâs rule and on cache approach for learning
Thank you for this link after the reading I understand quite well how to store results
The Astro channel soes not correct for cloudiness. You need input from a weather binding or the Synop binding for that.
Hi justanoldman
Thanks to this post I understand the linguistic issue.
I thought about reminderâ as something to be recall in mind.
Didnât know the English algebra meaning
I thought the channel of âdiffuse radiationâ was a weighed radiation after cloudiness correction.
Am I wrong so?
Diffuse radiation can increase with clouds (because reflection effects increase
sun_diffuse_rad = sun_diffuse_rad * (1 + 0.15 * cloudiness / 100)
It could be true this in effect
Because I use this to control some lights. I need to know how bright it is taking into account cloudiness.
Astro knows nothing about the current weather conditions. It only knows the sun position and what it can calculate from that. Diffuse radiation takes into account latitude and altitude to calculate how the sunlight is scattered by the atmosphere but it doesnât account for clouds, dust, smoke, and anything else that could change the radiation at any given time.
Indeed it can be affected by clouds, but since Astro knows nothing of the weather we need the rule.
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.