How to get data back from a HTTP get

Hi guys, slowly moving all my devices off Vera.. but there are going to be some that aren't ready yet. All I want to do is issue command to my Vera (gets back reading form my Netatmo weather system)

http://192.168.0.99:3480/data_request?id=variableget&DeviceNum=1510&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature

and get back a value I can do something with.

I'v looked at Rule machine and Momentary Switch and can't see any reference on how you get data back. It's probable something really simple but I can't see it.

Anyone?

There are several ways and I use both. However, for simplicity, try the below method which contains your command and the initial parse thereof

private sendSyncCmd(command){
	def host = "http://192.168.0.99:3480"
	def command = "/data_request?id=variableget&DeviceNum=1510&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature"
	httpGet([uri: "${host}${command}",
			 contentType: "text/xml",
			 timeout: 5]) { resp ->
		def respData = resp.data.response
		log.debug respData
		//	Place your data extraction parsing here.
	}
}
1 Like

Note that this works in a driver. In rule machine I do not know. You can also try using the Maker API and just place your command therein. (I am not a Maker API user.)

You cannot do this in rule machine. You would have to write a driver to do this.

Thanks guys... it can't be that hard surely... I'm out of my comfort zone but will eventually get there.
I managed to install a driver - having little idea what I am doing

metadata {
definition (
name: "Mick2",
namespace: "Mick2",
author: "Novice" )
{
capability "Refresh"
}
}
private sendSyncCmd(commandx){
def host = "http://192.168.0.99:3480"
def command = "/data_request?id=variableget&DeviceNum=1510&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature"
httpGet([uri: "${host}${command}",
contentType: "text/xml",
timeout: 5])
{ resp ->
def respData = resp.data.response
log.debug respData
}
}
log says:

2019-09-04 15:31:26.850 errorgroovy.lang.MissingMethodException: No signature of method: user_driver_Mick2_Mick2_449.refresh() is applicable for argument types: () values: [] Possible solutions: every(), every(groovy.lang.Closure), grep() (refresh)

In Vera this is easy! Going to need some more clues. Maker API looks to be about external devices issuing gets to the HA.. I'm going the other way.. Maybe a walk will help...

Sorry but you're basically asking "How do I write a driver?" and that's not a quick or easy question to answer. My suggestion would be to find some other way to do it. Maybe using the maker API to send the data to HE rather than HE polling for it.

in this specific case, the capability Refresh requires a method refresh.
def refresh() ( sendSyncCommand() }

You also need to change:
private sendSyncCmd(commandx){
to
private sendSyncCmd(){

Look at some available drivers to see how a driver is formulated. Try this link (it is one of mine and more complex than you need, but you can get the flow).

https://raw.githubusercontent.com/DaveGut/bleBox-Hubitat/master/Drivers/switchBox.groovy

To import into the editor (easier to read), go to a new driver, press the Import button and paste the above code into the field. OR you can copy the code from the gitHub editor and paste it into a new window.

it works!

metadata {
definition (
name: "Mick2",
namespace: "Mick2",
author: "Novice" )
{
capability "Refresh"
}
}
def refresh() { ( sendSyncCmd() ) }

private sendSyncCmd(){
def host = "http://192.168.0.99:3480"
def command = "/data_request?id=variableget&DeviceNum=1510&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature"
httpGet([uri: "${host}${command}",
contentType: "text/html",
timeout: 5])
{ resp ->
def respData = resp.data
log.debug respData
}
}

2019-09-04 19:12:28.831 debug18.0

18 is the correct answer... thanks

Right.. now the issue is how to get this value so that I can do something with it in the rule machine.. Seems I can't just set it to a global value so how?

What's the quickest , simplest path here... nothing fancy needed here.. ?

If you are creating this as a driver, make a "sendEvent" that provides the name of the attribute and the value. You will need to put the value from the response into a specific field. From your sample that means it might look like:

sendEvent( name: "temperature", value: CurrentTemperature, unit: location.getTemperatureScale(), linkText: deviceName, descriptionText: "", isStateChange: true )

My NeptuneSystemsApex driver does a lot of this type of stuff, although I am able to check an XML page for the data.

Thanks for your help. I have it working now with values being updated in the UI. This means I can proceed with the final transit of my remaining devices, Eventually I'll tidy up this driver and make it more generic. It will be a useful training exercise for me. So much to learn..but it's fun...

I have one last thing to do so I can move off Vera. So in Vera I have a working curl command but for the life of me I can't get curl to do anything in this driver code. So some dumb questions:
Is curl actually available in a driver? Do I need to load some libraries into the driver code first?

It's as if curl is not available?

Curl isn’t available but I would assume your curl command is doing an HTTP get or post which can be done in a driver. Post your curl command and we can try to help.

Thanks... best part of day investigating.. found many references in forums using curl...never mind. i learnt a lot about curl!

Ok i'm actuallu posting data to PVOUT
https://pvoutput.org/help.html#api-postsystem

Their example is good enough...

curl -d "d=20100830" -d "g=15000" -H "X-Pvoutput-Apikey: Your-API-Key " -H "X-Pvoutput-SystemId: Your-System-Id " https://pvoutput.org/service/r2/addoutput.jsp

This is of course all hard coded.. in my final version it will be using variables.

Never got notified of your reply. Check out this thread for a similar question. You just need to invoke a httppost:

Ok finally coded my http...

here's a sample
https://pvoutput.org/service/r2/addstatus.jsp?&key=xxxxx&sid=yyyy&v7=%5-minute-PV-export_last%&v4=%5-minute-PV-total-last%&t=%PVtime%&d=%PVdate%&v5=%Outside-temp%

I had to code a driver so I could create a date yyyymmdd and a time of hh:mm just so that I could use it the post above. Surely that's a little over the top. Has someone an easier method? I'm learning all the time.

Anyway I have now sucessfully migrated everything from Vera.... thanks for the all the help from forum members... yipee