Announcement

Collapse
No announcement yet.

Help with get and store in HS a value from emoncms (returns json via api call)

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

    Help with get and store in HS a value from emoncms (returns json via api call)

    Hi, I am moving to HS from DomotiGa and am in the process of learning the system.

    I want to get the data from emoncms (an energy monitoring site) into HS. The value (Watts) is available via an api call...ie.
    http://emoncms.org/feed/timevalue.js...xxxxx&id=13325

    Which returns the pairs "{"time":1479520565,"value":"56"}".

    (There are other calls incl. just the value)...see here https://emoncms.org/site/api#feed

    I have some programming skills (and can google) but really do not know where to start. Can you please help me to get this running on my system?

    I am sure it's simple...but I do not know where to begin?

    I assume I'll need:
    1: Event that calls a script every x seconds.
    2: The script would then call the emon cms api for each of the energy monitored id's (ie id 13325 = overall power, id 13326 = Solar etc)
    3: Parse the data
    4: Update HA via For each id it would then call hs.SetDeviceString to update the HS virtual device.

    Is that about right?

    I found this old thread for HS 2 http://board.homeseer.com/showthread.php?t=162865 is it usable as a base?

    thanks!
    Last edited by davros; November 19, 2016, 10:38 PM.

    #2
    I would say it is fairly easy to get going the only slight issue with seeing the API for the 0.2 seconds I've browsed it is the authentication header in the HTTP call might mean it is better off using one of the .net facilities to do a HTTP GET rather than the ones HS exposes. I would suggest;

    1) Search the message board for 'JSON' and you should see a couple of JSON scripts, I posted one for a radiation meter that might be a starter for this purpose. The JSON structures will need to be amended for the structures in the API.

    2) Get the data, search around for a .net HTTP get method and some examples with authorisation headers, I might have one somewhere if you struggle.

    Combine the two and get the data and just put it in the HS log at the minute, once you have it in the log the rest should be easy - post back and can help.

    Comment


      #3
      How to load emoncms readings into Homeseer.

      Thanks mate. I very much appreciate your reply. You do alot of good here.

      < rant >
      Challenge with this (and with most last gen designed systems - and HS is very last gen. design) is that it's obvious to those who know...but impossible to know for those who are just starting. The old timers on forums all too often forget what it's like to be newbie. It's a natural thing. Spoon feeding, examples and links goes a long way to lessen the steepness of the learning curve. It's sometimes held out as a thing of pride - but it's just poor design thinking. Making complex simple and eliminating the curve is hard work and a skill in itself. I do not have the skill, but I use others in my work who do.

      The Homeseer brand would benefit imensely from a revamp and modernisation of the way it approaches new users. Tough love - the manual is on the shelf, go find it - is increasingly old school and not relevant in an age of intuative larning. That's very hard to achive - so ultimately is a commercial decision. Though in my view, the tolerance for steep learning curves is rapidly evaporating and this will negaively impact the potential market for HS.

      Anyway, back to the topic at hand.
      < /rant >


      My post was in moderation so I spent hours stumbling about and came up with the following...

      1. Made virtual devices - one for each power sensor (you can use the copy function in the unnamed action dropdown to duplcate devices) (see images below).
      2. Made an event and clicked on the advanced (dove/airoplane?) button to enter the below script. (See image below)
      Code:
      Sub Main(ByVal parm As String)
      
        Dim Response = hs.GetURLex("https://emoncms.org","/feed/fetch.json?apikey=2943811111111111152&ids=13325,13326,13506,13507,13508,13509,13510,13511,13512", "", "443", "TRUE", "FALSE", "")
        'hs.writelog("emoncms","Response " & Response)
      
        Response = Response.Replace(Chr(34), "")
        Dim ReturnedValues As String = Response.Substring(1, Response.Length - 2)
      
        Dim ReturnedValuesArray() As String = ReturnedValues.Split(",") 
        Dim CurrentValue As String 
        Dim ValuePosition As Integer 
        Dim StringToWorkWith As String
      
        'hs.writelog("emoncms","ReturnedValues " & ReturnedValues)
      
        hs.SetDeviceValueByName("House Power", Convert.ToInt32(ReturnedValuesArray(0)))
        hs.SetDeviceValueByName("Solar Power", Convert.ToInt32(ReturnedValuesArray(1)))
        hs.SetDeviceValueByName("Voltage", Convert.ToInt32(ReturnedValuesArray(2)))
        hs.SetDeviceValueByName("Laundry Power", Convert.ToInt32(ReturnedValuesArray(3)))
        hs.SetDeviceValueByName("Study Kitchen Lounge Power", Convert.ToInt32(ReturnedValuesArray(4)))
        hs.SetDeviceValueByName("Front HA Server Power", Convert.ToInt32(ReturnedValuesArray(5)))
        hs.SetDeviceValueByName("Upstairs Power", Convert.ToInt32(ReturnedValuesArray(6)))
        hs.SetDeviceValueByName("Dinner Lounge TV Power", Convert.ToInt32(ReturnedValuesArray(7)))
        hs.SetDeviceValueByName("Lights Power", Convert.ToInt32(ReturnedValuesArray(8)))
        
      End Sub
      Job done

      I used a different method, fetch, which enales multiple values to be queried in one call. It returns the values as an array. I strip off an quotes and remove the brackets "[]" on the array then load each value into an array using split on ",". Now, if I was smarter, I'd just load the array directly But I am not.

      Hope that helps someone and please feel free to improve.
      Attached Files
      Last edited by davros; November 19, 2016, 07:45 PM.

      Comment

      Working...
      X