Is this possible? Store data from Asus Router ajax .asp page for Temperature data.
-
@toggledbits said in Is this possible? Store data from Asus Router ajax .asp page for Temperature data.:
You can push that string through the expression int() function
No idea what that means, but I will search. I also need to do some thing with that data like round it, as it says"66986" which should read as 66.99 degrees
-
OK I see what you mean my local expression is a string. But how to change it to int ?
When you create a local expression it gives you no option of the type it should be.
-
-
int(RouterCPUTemp) / 1000
-
-
You can wrap that in a
round()
if you only want one decimal (for example)...round( int( RouterCPUTemp ) / 1000, 1 )
-
cw-kidreplied to toggledbits on Jul 26, 2023, 8:44 PM last edited by cw-kid Jul 26, 2023, 4:46 PM
@toggledbits said in Is this possible? Store data from Asus Router ajax .asp page for Temperature data.:
round( int( RouterCPUTemp ) / 1000, 1 )
Even better, you have made my day! Thank you.
I have been worrying about my router getting too hot, now I will know if it does.
-
This post is deleted!
-
-
Maybe I should also add a timeout to the ssh commands ?
ssh -o ConnectTimeout=10 -i ~/.ssh/id_rsa admin@192.168.0.1 'cat /sys/class/thermal/thermal_zone0/temp'
-
Think I just found a bug? try naming a local expression as "2.4GTempRaw" without the quotes in a rule and see what happens. I am stuck and cannot delete the expression or exist the rule. Had to refresh the browser to recover. Should of known not to put a dot in the name LOL.
I might have just corrupted the rule now I cannot add an expression named "24GTempRaw"
Or maybe its the numbers it doesn't like.
OK that's better.
-
-
This is much more powerful than I imagined. Seems you can send any old linux command like "free" to see the memory usage. I haven't figured out how to extract and parse just a part of the returned data yet though, say just the "Used" memory value.
(string) " total used free shared buffers cached\nMem: 426020 303308 122712 3404 0 39212\n-/+ buffers/cache: 264096 161924\nSwap: 0 0 0\n"
"303308" is the used memory value, no idea how to extract just that part of the data to another local expression though as its not formatted like JSON data would be.
-
toggledbitsreplied to cw-kid on Jul 27, 2023, 12:40 AM last edited by toggledbits Jul 26, 2023, 8:42 PM
@cw-kid you're going to have to learn "regular expressions", which are patterns that can be matched in strings. It's another rabbit hole to go down, but here's a specific solution you might build on. Using your response string:
The
match()
function (refer to the docs) will match a pattern to a string. In this case, the pattern contains "regular expression groups", which are the parentheses and their contents. These groups contain\d+
patterns (you have to specify them as\\d+
as shown because of string escaping in the language)... the\d
pattern matches a single digit 0-9, and the modifier+
after it tells it to match one or more occurrences — so each\\d+
matches a number made of one or more consecutive digits. So this whole pattern basically finds the wordMem:
in the string, then from there finds the six numbers that follow. The3
in the last argument tellsmatch()
to return only the third matched item, which is the number 122712, the amount of free space (it's third in place in the string of numbers based on the header line above it).You can Google around to find regular expression tutorials.
-
Thanks I will take a look at the pattern matching.
I realised I need a Global Expression, for my second rule to trigger from. As I cannot use a local expression that is in one rule as a trigger in a different rule etc.
My second rule will be the one that triggers if the CPU Temp value is greater than 80 and it will notify me by repeated TTS announcements etc.So I created two new Global Expressions.
The first rule I setup that gets the CPU Temp via the ssh command, now also sends that raw response value to the Global variable as well, that is named "RouterCPUTempRaw" that works fine OK.
However my second Global variable called "RouterCPUTemp" that changes it to "int" doesn't seem to evaluate.
When should it evaluate ?
If I restart MSR then it evaluates then and updates correctly.
Maybe? its because to test it and force the value to be 81 I sent in this URL to MSR.
http://192.168.1.40:8111/api/v1/variable/RouterCPUTempRaw/set?value=81495
Thanks
EDIT: I guess as a work around I could delete the "RouterCPUTemp" global variable and just have my second rule trigger if the value in "RouterCPUTempRaw" global variable is greater than 80000
EDIT2: I just did that and that seems to work OK instead.
-
-
Local expressions are only evaluated when the parent rule is evaluated. The changing of the
rawResponse
local variable does not cause an evaluation of the other variables. These would need to be global. -
@toggledbits OK thanks I will change them to global variables and a see.
My comment before the last one, both of those expressions were global, yet one of them didn't seem to be evaluating and I wasn't sure why..
-
OK I changed all three expressions to be global ones instead.
I waited a while, but a similar thing as yet they have not been evaluated.
I then press Play on them but still nothing.
I then ran the action in the rule that pulls down the Free Memory data, but they still say (has not been evaluated)
Edit: I am on build, latest-23196-40ef07f4, just checked I am up to date it seems.
Restarting MSR also doesn't help. I don't understand why these global variables don't seem to be evaluating.
-
toggledbitswrote on Jul 28, 2023, 3:23 PM last edited by toggledbits Jul 28, 2023, 11:29 AM
Not showing enough work here. What sets
RouterMemoryRaw
? Need detailsEdit: also, did you hard refresh after restarting MSR?
26/77