Email yourself the result of `chia farm summary` every N seconds (Windows)

Set this up today and figured I’d share. Create a PS script somewhere. I chose C:/users/wwwroth/Crypto/chia_farm_summary.ps1.

for(;;) {
    $EmailFrom = "YOUR_EMAIL@gmail.com"
    $EmailTo = "YOUR_EMAIL@gmail.com"
    $Subject = "Chia Farm Summary"
    $Body = C:\users\YOUR_USER\AppData\Local\chia-blockchain\app-*\resources\app.asar.unpacked\daemon/chia.exe farm summary
    $SMTPServer = "smtp.gmail.com"
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
    $SMTPClient.EnableSsl = $true
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("YOUR_EMAIL@gmail.com", "YOUR_PASSWORD");
    $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
 
    Start-Sleep 3600
}

Note: If you use 2FA (you better be.), you’ll have to create a Gmail application password.

Then kick it off with…

powershell -File C:/users/wwwroth/Crypto/chia_farm_summary.ps1 -WindowStyle Hidden

Every hour you’ll get an email showing your farm’s summary :slight_smile:

If any PS users want to optimize/recommend better ways of doing this, please do. I’ve been a software engineer on Linux for my entire career. This is the first project I’m using Windows on (and not running a UNIX shell) to be honest.

2 Likes

Later on Id like to stick the output as JSON in a NoSQL db and write some front-end build to display stats over time and project the future. Maybe tie in chiacalculator.com to estimate earnings automatically.

If anyone wants to collaborate on this let me know. I’ll get the repo set up. :grinning_face_with_smiling_eyes:

You should definetly have a look at time series databases like prometheus or influx db to do those stats. They are made for exactly this and are much easier to handle than a nosql db for this

2 Likes

like @speedmann said, GitHub - retzkek/chiamon: mtail, prometheus, and grafana config and dashboard for monitoring chia farming

1 Like

This is perfect. Cheers!

I like it! But I prefer sending notifications to discord. I just rewrote your posted code for that. Disclaimer: Not tested at all, since no chia.exe on my work computer. Might break due to unexpected format for ConvertTo-JSON:

for(;;) {
    $DiscordWebHookURL = "URL"
    $Body = C:\users\YOUR_USER\AppData\Local\chia-blockchain\app-*\resources\app.asar.unpacked\daemon/chia.exe farm summary
    $payload = [PSCustomObject]@{
    content = $body
    }
 
    Invoke-RestMethod -Uri $DiscordWebHookURL -Method Post -Body ($payload | ConvertTo-Json)
    Start-Sleep 3600
}
1 Like