Announcement

Collapse
No announcement yet.

Plugs that show outdoor air quality conditions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • tommyd75
    replied
    I'm trying to get this to work but I keep getting this error "Running script /usr/local/HomeSeer/scripts/pollen.vb :Exception has been thrown by the target of an invocation.Invalid JSON string"

    I'm using this on a RaspberryPi3b with HS3, I've added the Polen.json file to the /user/local/HomeSeer/html/json folder.

    I have also added the three image files to the html/images/Pollen folder.
    I have also created 4 devices called Today's Pollen Level, Allergen 1,Allergen 2, Allergen 3.

    This is what my script looks like.........


    Imports System.Web.Script.Serialization

    Sub Main(ByVal Parms As Object)

    Dim devID as integer
    Dim allergenName as String
    Dim allergenType as String
    Dim allergenTypeValue as Integer
    Dim html as String
    Dim pollenRating As String
    Dim pollenIndex As Decimal


    ' Create a WebRequest to the remote site, specifying Referer and UserAgent
    Dim getRequest As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://www.pollen.com/forecast/current/pollen/60634")
    getRequest.Referer="https://www.pollen.com/forecast/current/pollen/60634"
    getRequest.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
    Dim getResponse As System.Net.HttpWebResponse = getRequest.GetResponse()

    If getResponse.StatusCode = System.Net.HttpStatusCode.OK Then
    ' Parse the contents from the response to a stream object
    Dim stream As System.IO.Stream = getResponse.GetResponseStream()

    ' Create a reader for the stream object
    Dim reader As New System.IO.StreamReader(stream)

    ' Read from the stream object using the reader, put the contents in a string
    Dim contents As String = reader.ReadToEnd()

    ' Save JSON string into a JSON file
    My.Computer.FileSystem.WriteAllText(hs.GetAppPath & "\html\json\Pollen.json", contents, False)

    ' Convert JSON string to object
    Dim jsonData As Object = New JavaScriptSerializer().Deserialize(Of Object)(contents)

    ' Get Pollen Index value
    pollenIndex = CDec(jsonData("Location")("periods")("1")("Index"))

    hs.SetDeviceValuebyRef (281, pollenIndex, True)
    hs.SetDeviceString(281, pollenIndex & " out of 12", True)
    hs.SetDeviceLastChange(281, now)



    For i As Integer = 0 To 2
    If i <= UBound(jsonData("Location")("periods")("1")("Triggers")) Then
    allergenName = jsonData("Location")("periods")("1")("Triggers")(Cstr(i))("N ame")
    allergenType = jsonData("Location")("periods")("1")("Triggers")(Cstr(i))("P lantType")
    allergenTypeValue = 0
    Select Case allergenType
    Case "Tree"
    allergenTypeValue = 1
    Case "Grass"
    allergenTypeValue = 2
    Case "Ragweed"
    allergenTypeValue = 3
    End Select
    If i = 0 Then
    devID = 281
    Elseif i = 1 Then
    devID = 283
    Else
    devID = 284
    End If
    html = "<img src=""/images/Pollen/" & allergenType & ".png"" height=""32""> " & allergenName
    hs.SetDeviceString(devID, html, True)
    hs.SetDeviceLastChange(devID, now)
    Else
    hs.SetDeviceString(284, "None", True)
    hs.SetDeviceLastChange(284, now)

    End If
    Next

    End If

    End Sub

    Leave a comment:


  • Dweber85rc
    replied
    Originally posted by prsmith777 View Post

    Great ! I use the virtual devices to announce a morning pollen report. I only announce the flu data if its high or very high. Works well.

    I am allergic to pretty much all types of pollen. Now that I have it working the goal is to create events to be able to turn off my air exchanger so I'm not sucking that junk inside and turn on my furnace fan to circulate air in my home through the whole home electronic air cleaner filtration system attached to my furnace.

    Leave a comment:


  • prsmith777
    replied
    That is strange. Perhaps try shutting down Homeseer and then editing the file and see if that helps.

    Leave a comment:


  • ewkearns
    replied
    Originally posted by prsmith777 View Post

    That all looks correct except you have a space in "Ext ensions" should read "Extensions"
    Actually, I don't.. or I don't think I do. When I copy and paste, it looks fine, when I hit [return] the space appears. I have removed the entire line and retyped, expecting some kind of odd character to be overwritten, one that doesn't show up in any editor I have used.... this is odd.

    ScriptingReferences=System.Web;System.Web.dll;System.Web.Ext ensions;System.Web.Extensions.dll (and it still shows up).

    Test (Copy and Past from 4 year old config)
    ScriptingReferences=System.Web;System.web.dll

    Test 2 (Typed addition to Cut & Paste)
    ScriptingReferences=System.Web;System.Web.dll;System.Web.Ext ensions;System.Web.Extensions.dll

    Test 3 (Typed from scratch)
    ScriptingReferences=System.Web;System.Web.dll;System.Web.Ext ensions;System.Web.Extensions.dll


    ...... and it added the [space] when I hit post...

    Additional attempt:
    ScriptingReferences=xxxSystem.Web;System.Web.dll ;System.Web.Extensions;System.Web.Extensions.dll

    Leave a comment:


  • prsmith777
    replied
    Originally posted by Dweber85rc View Post
    I have this working-thanks!
    Great ! I use the virtual devices to announce a morning pollen report. I only announce the flu data if its high or very high. Works well.

    Leave a comment:


  • Dweber85rc
    replied
    I have this working-thanks!

    Leave a comment:


  • prsmith777
    replied
    Originally posted by ewkearns View Post

    I did this, but no joy. I'm a little confused by the delimiter(s) and instructions. Should the delimiters be a comma, a semicolon, or both?

    [Settings]
    ScriptingReferences=System.Web;System.Web.dll,System.Web.Ext ensions;System.Web.Extensions.dll

    I am making changes to the file HS3/Config/settings.ini, is that the right one?
    That all looks correct except you have a space in "Ext ensions" should read "Extensions"

    Leave a comment:


  • ewkearns
    replied
    Originally posted by prsmith777 View Post
    Try adding ",System.Web.Extensions;System.Web.Extensions.dll" to the end of ScriptingReferences
    I did this, but no joy. I'm a little confused by the delimiter(s) and instructions. Should the delimiters be a comma, a semicolon, or both?

    [Settings]
    ScriptingReferences=System.Web;System.Web.dll;System.Web.Ext ensions;System.Web.Extensions.dll


    I am making changes to the file HS3/Config/settings.ini, is that the right one?

    Leave a comment:


  • prsmith777
    replied
    One other thing I noticed today. There is an allergen called Grasses that doesn't seem to populate with an image. It is either new or I missed it in my initial setup. Solution is to copy the Weed.png image and rename it Grass.png and put it in the same folder

    Leave a comment:


  • prsmith777
    replied
    Try adding ",System.Web.Extensions;System.Web.Extensions.dll" to the end of ScriptingReferences

    Leave a comment:


  • ewkearns
    replied
    Any thoughts?

    I do have ",System.Web;System.Web.dll" and I have added the stipulated directories, files, and images, yet I'm having similar issues, but my errors are:
    May-26 10:34:23 AM Error Compiling script J:\Program Files (x86)\HomeSeer HS3\scripts\pollen.vb: Type 'JavaScriptSerializer' is not defined.
    May-26 10:34:23 AM Error Compiling script J:\Program Files (x86)\HomeSeer HS3\scripts\pollen.vb: Namespace or type specified in the Imports 'System.Web.Script.Serialization' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
    May-26 10:34:23 AM Error Compiling script J:\Program Files (x86)\HomeSeer HS3\scripts\pollen.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

    Leave a comment:


  • prsmith777
    replied
    Originally posted by Dweber85rc View Post
    Never mind, I see the scripts don't actually create the virtual devices-can you post some screenshots of how you setup your virtual devices? I'm a little fuzzy on the values to configure those with.

    I also get this error just trying to run it-I've not run much for scripts in HS3 yet so I'm pretty new to this.
    Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\pollen.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
    You might have to add a new Scripting References in your settings.ini folder for it to work. add the following to the end of the "ScriptingReferences" : ",System.Web;System.Web.dll"

    The scripts read the data from flu.com and pollen.com and write data into files in homeseer. You will have to create these files first as blank files so that the script can write to them.

    Create a folder in the html folder called "json". Then create files in the json folder called Pollen.json and Flu.json.

    For all the devices you created you will have to change the device references throughout the scripts to match your new ones. You can see which device references I have on the screen caps of my devices to figure out how to change for your devices.

    You will also have to create a new folder in homeseer images folder called "Pollen" and then add these three icons in that folder: Name them Tree.png, Ragweed.png, and Weed.png



    Click image for larger version

Name:	Tree.png
Views:	81
Size:	3.6 KB
ID:	1307320
    Click image for larger version

Name:	Ragweed.png
Views:	58
Size:	3.1 KB
ID:	1307323
    Click image for larger version

Name:	Weed.png
Views:	59
Size:	3.4 KB
ID:	1307324

    Finally you will have to change the zipcode to whatever yours is and replace mine which is in the script as 80908.
    Attached Files

    Leave a comment:


  • jon00
    replied
    Originally posted by sparkman View Post
    There used to be some scripts to pollen info from pollen.com website. Not sure if they are still around and supported. I think Jon00 had one too, but not sure if it was just for the UK. I pull air quality from https://waqi.info with a script, but it does not supply pollen data.
    jono posted a method to parse pollen info using my datascraper script: https://forums.homeseer.com/forum/3r...51#post1304751

    Leave a comment:


  • Dweber85rc
    replied
    Never mind, I see the scripts don't actually create the virtual devices-can you post some screenshots of how you setup your virtual devices? I'm a little fuzzy on the values to configure those with.

    I also get this error just trying to run it-I've not run much for scripts in HS3 yet so I'm pretty new to this.
    Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\pollen.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

    Leave a comment:


  • Dweber85rc
    replied
    Originally posted by prsmith777 View Post
    I have scripts that pull data from pollen.com and flu.com and populate virtual devices

    Click image for larger version Name:	pollen.png Views:	0 Size:	67.4 KB ID:	1306438
    pollen.txt

    flu.txt

    change .txt to .vb
    That is good, I'll give this a try. Does the script create the virtual devices or do those need to be created separately?

    Leave a comment:

Working...
X