Advertisement
scrand

Sonoff POW - Dryer notification

Nov 26th, 2017
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cls
  2.  
  3. #Settings
  4. $senzor = "" # For example http://192.168.1.1/api/power?apikey=53B8B55BEE6A4775" #Need to know POW's IP and API key
  5.  
  6. #Email Settings
  7. $SMTPUsername = "" #for example somebody@seznam.cz
  8. $SMTPServer = "" #for example smtp.seznam.cz
  9. $SecureStringPassword =  Read-Host "password for email account please" -AsSecureString
  10. $EmailCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $SMTPUsername,$SecureStringPassword
  11. $email1 = "" #emaill address or special email address with your phonenumber which you received from your operator I can set it in My T-Mobile App in Czech Republic
  12. $counter = 5 #Higer value when script is started because of fake notification it will be changed to 0 after dryer will be started.
  13. while (1){
  14.     #Vypis poweru
  15.     $power = Invoke-WebRequest -uri $senzor
  16.     $actualtime = Get-Date -Format "yyyy-MM-dd HH:mm"
  17.     write-host $actualtime $power.Content "W - counter: " $counter
  18.  
  19.     if([INT]$power.Content -lt 5){ #When power is less then 5W (standby value) it add 1 to counter
  20.         $counter = $counter + 1
  21.     }
  22.     else{
  23.         $counter = 0
  24.     }
  25.  
  26.     if($counter -eq 3){ # If it is for three times less then 5W it goes to send e-mail notification
  27.       write-host("I: E-mail has been sent") -ForegroundColor Yellow
  28.       Send-MailMessage -From $SMTPUsername -To $email1 -Subject "Drying finished" -SmtpServer $SMTPServer -Credential $EmailCredential  
  29.     }
  30.    
  31.     Start-Sleep -Seconds 30 #Wait 30s
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement