Results 1 to 5 of 5

Thread: T.E.D. The energy detective / parsing XML documents

  1. #1
    Join Date
    Apr 2003

    Default T.E.D. The energy detective / parsing XML documents

    I have a Ted device on the way and would like to incorperate it's data into girder. Has there been any other attempts to acomplish this?

    The device hosts an XML document that should be very easily parsed. If there is nothing else out there I'm thinking that I will start/ build off of some of the weather scripts

  2. #2
    Join Date
    Jun 2005


    I don't know about the Ted device but I have used some of the Lua library methods that you'll find in the weather script examples to parse an XML document. I must say, it wasn't intuitive and I couldn't figure out how to grab stuff several layers deep. I later found it easier and would recommend directly parsing the data with the Lua string library methods described in my previous response to you. What you do is suck the whole XML document into a Lua variable and then go to town parsing it. Here's an example of the first step where the url is a XML document from the web:
    local url = ""
    local Page = socket.http.request(url)
    The next step is to parse the Lua string variable "Page". Good luck!

  3. #3
    Join Date
    Apr 2003


    am i correct that "Page" should be filled with the entire XML doc? i am likely just doin this wrong but this is what i am getting

    local http = require("socket.http")
    local url = ("")
    local Page = socket.http.request(url)
    print (url)
    print (Page)

  4. #4
    Join Date
    Apr 2003


    cancel that. it works great. i had the wrong network adapter selected in parallels and was not connected to the network.

  5. #5
    Join Date
    Apr 2003


    got things all figured out see script below. thanks to Todd Reed for his weather Script and Dsmes for getting me thinking

    function GetTED()
    TED = luacom.CreateObject("Msxml2.DOMDocument")
    TED.async = 0
    TED:load ("")
    if TED.parseError.errorCode ~=0 then
    print (TED.parseError.reason)
    -- Power Usage Now
    node = TED:selectSingleNode ("LiveData/Power/Total/PowerNow")
    TEDPowerNow = node.text
    TEDPowerNow = TEDPowerNow/1000
    -- Power Usage This Hour
    node = TED:selectSingleNode ("LiveData/Power/Total/PowerHour")
    TEDPowerHour = node.text
    TEDPowerHour = TEDPowerHour/1000
    -- Power Usage Today
    node = TED:selectSingleNode ("LiveData/Power/Total/PowerTDY")
    TEDPowerTDY = node.text
    TEDPowerTDY = TEDPowerTDY/1000
    -- Power Usage Month To Date
    node = TED:selectSingleNode ("LiveData/Power/Total/PowerMTD")
    TEDPowerMTD = node.text
    TEDPowerMTD = TEDPowerMTD/1000
    -- Power Projection for this month
    node = TED:selectSingleNode ("LiveData/Power/Total/PowerProj")
    TEDPowerProj = node.text
    TEDPowerProj = TEDPowerProj/100
    -- Cost Now
    node = TED:selectSingleNode ("LiveData/Cost/Total/CostNow")
    TEDCostNow = node.text
    TEDCostNow = TEDCostNow/100
    -- Cost Today
    node = TED:selectSingleNode ("LiveData/Cost/Total/CostTDY")
    TEDCostTDY= node.text
    TEDCostTDY = TEDCostTDY/100
    -- Cost Month to Date
    node = TED:selectSingleNode ("LiveData/Cost/Total/CostMTD")
    TEDCostMTD = node.text
    TEDCostMTD = TEDCostMTD/100
    -- Cost Projection (month)
    node = TED:selectSingleNode ("LiveData/Cost/Total/CostProj")
    TEDCostProj = node.text
    TEDCostProj = TEDCostProj/100
    -- Carbon Rate
    node = TED:selectSingleNode ("LiveData/Utility/CarbonRate")
    TEDCarbonRate = node.text
    TEDCarbonRate = TEDCarbonRate/100
    -- Current Carbon Emissions
    TEDCurrentCarbon = TEDPowerNow*TEDCarbonRate
    -- Carbon Emissions This Hour
    TEDHourCarbon = TEDPowerHour*TEDCarbonRate
    -- Carbon Emissions This Hour
    TEDTDYCarbon = TEDPowerTDY*TEDCarbonRate
    -- Carbon Emissions Month to Date
    TEDMTDCarbon = TEDPowerMTD*TEDCarbonRate
    -- Carbon Emissions Projected this month
    TEDProjCarbon = TEDPowerProj*TEDCarbonRate
    -- Current Rate
    node = TED:selectSingleNode ("LiveData/Utility/CurrentRate")
    TEDCurrentRate = node.text
    TEDCurrentRate = "."..TEDCurrentRate
    print ("Power usage now (kW): "..TEDPowerNow)
    print ("Carbon Emissions now (lbs): "..TEDCurrentCarbon)
    print ("Power usage this hour (kWh): "..TEDPowerHour)
    print ("Carbon Emissions this hour (lbs): "..TEDHourCarbon)
    print ("Power usage today (kWh): "..TEDPowerTDY)
    print ("Carbon Emissions today (lbs): "..TEDTDYCarbon)
    print ("Power usage month to date (kWh): "..TEDPowerMTD)
    print ("Carbon Emissions month to day (lbs): "..TEDMTDCarbon)
    print ("Power usage projected (kWh): "..TEDPowerProj)
    print ("Carbon Emissions projected for this month (lbs): "..TEDProjCarbon)
    print ("Cost by usage now : $"..TEDCostNow)
    print ("Cost by usage today: $"..TEDCostTDY)
    print ("Cost by usage this month: $"..TEDCostMTD)
    print ("Cost Projected for this month: $"..TEDCostProj)
    print ("Current carbon rate (lbs): "..TEDCarbonRate)
    print ("Current Rate: $"..TEDCurrentRate)
    print ('TED Get Data')
    TED = nil
    Power usage now (kW): 5.73
    Carbon Emissions now (lbs): 8.8815
    Power usage this hour (kWh): 8.081
    Carbon Emissions this hour (lbs): 12.52555
    Power usage today (kWh): 97.615
    Carbon Emissions today (lbs): 151.30325
    Power usage month to date (kWh): 2586.893
    Carbon Emissions month to day (lbs): 4009.68415
    Power usage projected (kWh): 30850.7
    Carbon Emissions projected for this month (lbs): 47818.585
    Cost by usage now : $0.86
    Cost by usage today: $14.6
    Cost by usage this month: $401.82
    Cost Projected for this month: $479
    Current carbon rate (lbs): 1.55
    Current Rate: $.14521
    Last edited by 28seven; December 17th, 2009 at 09:23 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts