Create a File With Appended Temperature Data in Descending Order

Using a C7 hub app to create a file and append temperature measurements taken each 15 minutes to an existing file in the hub's file manager. This has been setup so the text file can be accessed by clicking on a Window's desktop shortcut which then displays the entire file contents in ascending order in FireFox.

It would appear there is no built in hub function to add new temperature entries in descending order that is also truncated at 96 entries which opens and display in FireFox.

Shortened sample desired output.

temp_example

i.e. the listing is the newest temperature on top with the oldest temperature falling off the bottom limited to a total of 96 data points.

Would it be correct to assume that the desired actions are not yet available in Hubitat?

However, did find a way to use Window's PowerShell to accomplish the goal. However, it would nice if this function was available directly from the hub.

The file functions exist to this but you’d have to write app to use them. Could also look at using RM to store the data.

That is good to know. It may be time to look into the 'how to' part of creating an app.

Appreciate the information.

Here is the script for PowerShell. It run on both Windows 11/10 and PowerShell versions 5.0 and 7.4.

##### Variables - Use to change path and/or file names as needed plus number of sorted lines displayed. #####

# Variable - URL, path and file name to Hubitat appended temperature file on C7 Hub
# Alter between the double quotes to fit your specific needs.

$url = "http://192.168.1.155/local/outside_temp_log.txt"

##########

# Variable - path and file name to store file downloaded from Hubitat.
# Alter between the double quotes to fit your specific needs.

$dest = "C:\Users\Bob\Temp\org_temp.txt"

###########

# Variable - path and file name for sorted_temp file.
# Alter between the double quotes to fit your specific needs.

$dest1 = "C:\Users\Bob\Temp\sorted_temp.txt" 

##########

# Variable - determines the number of lines displayed for sorted temperatures listing.
# If displaying temperatures taken 4 times per hour then entering the number 96 will display 24 hours of temperature readings.
# Alter only the number to fit your display needs. 

$temp_listing = 96

##########

# Save to a PowerShell file with the extension of .ps1 after making changes to variables or script.

####################

# Copies the appended Hubitat log file to C:\Users\Bob\Temp\org_temp.txt on Windows computer.
Invoke-WebRequest -Uri $url -OutFile $dest

# Sets variable to sorted_temp.txt file location on Windows computer.
$dest1 = "C:\Users\Bob\Temp\sorted_temp.txt"

# Sorts top 96 entries newest to oldest and places in C:\Users\Bob\Temp\org_temp.txt ($dest) on Windows computer.
$sorted = Get-Content -Path $dest | Sort-Object -Descending | select -first $temp_listing
$sorted | Out-File $dest1

##########

# Select Notepad, Firefox or MS Edge to display output by adding or removing the # from start.

# Starts Notepad and displays contents of sorted_C:\Users\Bob\Temp\sorted_temp.txt ($dest1).
#start "C:\WINDOWS\system32\notepad.exe" @($dest1)

# Starts FireFox browser and displays contents of sorted_C:\Users\Bob\Temp\sorted_temp.txt ($dest1).
Start "C:\Program Files\Mozilla Firefox\firefox.exe" @($dest1)

# Starts MS Edge browser and displays contents of sorted_C:\Users\Bob\Temp\sorted_temp.txt ($dest1).
#Start "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" @($dest1)

##########

# Deletes temp file C:\Users\Bob\Temp\org_temp.txt ($dest).
Remove-Item -Path $dest

Exit