I have two questions

Ask and answer questions related to any type of OSA scripting.
Message
Author
Maximo
Posts: 199
Joined: Thu Dec 15, 2011 8:53 am
Location: UK

I have two questions

#1 Post by Maximo » Wed Sep 24, 2014 8:26 am

Thanks for your help. What I'm after is a few ideas and approach's.

Question 1, I have a number of Raspberry PI's around the house all running XBMC. I would like to monitor the temperature of them, I've therefore added a new field to the properties of the XBMC object type. My script is ready and working on the raspberry pi and just need a method of updating the field in the object type.

My first thought was to create a SQL script and directly insert the data, but wasn't sure if that would cause me issues elsewhere.

Question 2, I have a number of CCTV camera's around the house and have them connected to a piece of software named "iSpy". There is a function within the configuration that allows me to get alerts when motion is detected. So I though that would be useful in a number of ways. One of them being to switch on outside lights in the required area. What I've setup is an object type with two states. ON (Recording) and OFF (Not Recording) in the hope that I can use the rest api to update the state. But I'm not sure that I fully understand how to create the correct URL.

This is what I think it should be;

http://localhost:8732/api/object/GarageCamera/ON

But this isn't working for, so I'm after a little help with this one.

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: I have two questions

#2 Post by Automate » Wed Sep 24, 2014 10:17 am

Maximo wrote:Thanks for your help. What I'm after is a few ideas and approach's.

Question 1, I have a number of Raspberry PI's around the house all running XBMC. I would like to monitor the temperature of them, I've therefore added a new field to the properties of the XBMC object type. My script is ready and working on the raspberry pi and just need a method of updating the field in the object type.

My first thought was to create a SQL script and directly insert the data, but wasn't sure if that would cause me issues elsewhere.
In general it is best to use the the REST service but SQL will work also. If you use SQL it is best to use stored procedures rather than writing directly to the tables. osae_sp_object_property_set will set a property.
Maximo wrote: Question 2, I have a number of CCTV camera's around the house and have them connected to a piece of software named "iSpy". There is a function within the configuration that allows me to get alerts when motion is detected. So I though that would be useful in a number of ways. One of them being to switch on outside lights in the required area. What I've setup is an object type with two states. ON (Recording) and OFF (Not Recording) in the hope that I can use the rest api to update the state. But I'm not sure that I fully understand how to create the correct URL.

This is what I think it should be;

http://localhost:8732/api/object/GarageCamera/ON

But this isn't working for, so I'm after a little help with this one.
In looking at the REST plugin wiki there is a way to set a Property but not a State. You can read the current State but not set it directly.

Another way would be to create a named script that sets the State and then trigger the named script from the REST service.

Vaughn
Site Admin
Posts: 1432
Joined: Thu May 13, 2010 2:17 pm

Re: I have two questions

#3 Post by Vaughn » Wed Sep 24, 2014 11:44 am

I have not looked at the REST options, you say it is missing the ability to set a state, but it can run methods, right? If so, most objects should have state setting methods...

Vaughn

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: I have two questions

#4 Post by Automate » Wed Sep 24, 2014 1:12 pm

Sounds like he created his own object so there is no plugin to handle the methods. He could create methods with the same names as the States of the object and then make sure the object type is Owned By the system object. Then the method will change the State without the need for a plugin.

Maximo
Posts: 199
Joined: Thu Dec 15, 2011 8:53 am
Location: UK

Re: I have two questions

#5 Post by Maximo » Wed Sep 24, 2014 2:39 pm

Thanks for the replies.

So this is the REST Post I need to use but just can't get it to work at all.

http://localhost:8732/api/object/Garage ... m2={param2}

The object has the following;

State: Not Recording / Recording
Method: OFF / ON
Event: Not Recording / Recording

So how do I use this post?

Maximo
Posts: 199
Joined: Thu Dec 15, 2011 8:53 am
Location: UK

Re: I have two questions

#6 Post by Maximo » Wed Sep 24, 2014 2:49 pm

I have tried every option I can think of and always get; Method not allowed. Please see the service help page for constructing valid requests to the service.

Andre
Posts: 26
Joined: Tue Jul 08, 2014 6:29 am

Re: I have two questions

#7 Post by Andre » Wed Sep 24, 2014 11:08 pm

Hi Maximo,

For Q1:
Try in a Powershell script: (I haven't found much that I couldn't do in Powershell :D Thank you Mat!)

Code: Select all

set-osa -name "XBMCLounge" -property "Temp" -value "22"
For Q2:
I am not familiar with iSpy but could you try and change the state of an object from the OSA Powershell plugin?

Perhaps you can set the iSpy to execute a PS script file on detection? (If using a script file, you may have to include the PS OSA type and module path and allow script file execution)
..using a clever bit of PowerShell "magic" you can call the API directly without a powershell cmdlet, and since I made all the API methods static the call is nice and short see below:

[OSAE.OSAEObjectStateManager]::ObjectStateSet("test", "ON", "Your Source")
See Datahead and Mat's original thread on changing states via PS plugin here:
http://www.opensourceautomation.com/php ... tate#p7069


On a totally aside note, based on your questions, you may also want to take a look into this (If you haven't already):
It takes static images from the Security Camera and overlays them in XBMC in a PIP corner in realtime.

http://thedigitallifestyle.com/w/index. ... ay-add-on/

It has given me many hours of enjoyment setting it up on my XBMC (PI, PC and Android all work). I am triggering via the XBMC JSON interface, from OSA's Powershell. You just need to get the motion detection event into OSA from iSpy, or find a way to do it directly. :)

@Vaughn, I think you will also get a kick out of this.

Maximo
Posts: 199
Joined: Thu Dec 15, 2011 8:53 am
Location: UK

Re: I have two questions

#8 Post by Maximo » Wed Sep 24, 2014 11:56 pm

Thanks for the replies so far. I think I'm slowly getting there.

@Andre, I'm running XBMC on the Raspberry PI so there is no PowerShell only Bash. So ideally I need a way of updating using the Rest API

Also I should have added that OSA is running on a separate server to the one running iSpy, so how do I connect over the network?

Locally on the OSA server I have this script;

Add-Type -Path "C:\Program Files\OSA\OSAE.API.dll"
Import-Module -Name "C:\Program Files\OSA\Plugins\PowerShell\OSAE.PowerShellProcessor.dll"
Invoke-Osa -name "GarageCamera" -Method "On"

How do I get this to run on my Ispy server?

Once again thanks for your help.

Andre
Posts: 26
Joined: Tue Jul 08, 2014 6:29 am

Re: I have two questions

#9 Post by Andre » Thu Sep 25, 2014 1:00 am

Hmm, I see your problem.... :?

Short of writing an OSA plugin for iSpy, or an iSpy plugin for OSA, the REST would be the most direct method I can think of.

I haven't looked at/played with the REST plugin for OSA, but have you tried passing empty parameters in the string?
Something like

Code: Select all

http://localhost:8732/api/object/GarageCamera/ON?param1=''

The calling of a named script, that Automate mentioned, sounds like a possibility too. You could then call your PS script.

Code: Select all

http://localhost:8732/api/namedscript/{MATCH}
If you still have issues and if they are both Windows machines, you could try something more exotic like this:

http://stackoverflow.com/questions/3188 ... on-another

I'll try and have a play with the REST interface this weekend if you still can't come right.

A

Maximo
Posts: 199
Joined: Thu Dec 15, 2011 8:53 am
Location: UK

Re: I have two questions

#10 Post by Maximo » Thu Sep 25, 2014 2:19 am

I have just tried to run a named script; http://localhost:8732/api/namedscript/Test

:( Sadly I still get the screen that states that the Method is Not allowed. Any chance of a step by step guide?

Post Reply