Scripting

Description

Queries re using the xap-plugboard component to script xAP action events.

Forums

 

Hi guys, I have some scripting questions...

Following the examples, I have created a script to shutdown a PC running an ap to support shut down:

-- Registers ShutdownPC service
function init()
  register_target("dbzoo.livebox.ShutdownPC", "shutdown")
end

-- Sends http request to remote PC
function shutdown()
os.execute("curl http://172.16.10.30:8000/?action=System.Shutdown")
  xap_send("xap-header\
{\
target=dbzoo.livebox.Twitter\
class=xAPBSC.cmd\
}\
output.state.1\
{\
id=*\
text='PC Shutdown!'\
}\
")
end

I have also set up a google cal event to activate this script:

This is the xAP header in the google cal entry:

xAP-header
{
target=dbzoo.livebox.ShutdownPC
source=GoogleCalendar
class=unknown
}

Now as you know I'm trying to integrate the xAP Flash app into my home automation and I'd like to be able to activate this script from my Joggler.

Now I notice when the google cal event fires, I get this xAP message:

The following message caused an error during its processing.
The xAP message value is malformed. The block name contains one or more invalid characters
The message was received from 172.16.10.100:3078

------------
xAP-header
{
v=12
hop=1
uid=FF00DA00
class=unknown
source=dbzoo.livebox.GoogleCal
target=dbzoo.livebox.ShutdownPC
}
}

------------
The error that was generated is as follows:
The xAP message value is malformed
The block name contains one or more invalid characters

Source: xFx
The xAP message value is malformed
The block name contains one or more invalid characters
KCS.xAP.Framework.xAPException: The xAP message value is malformed
The block name contains one or more invalid characters
   at KCS.xAP.Framework.Message.xAPPairValue.ValidateValue()
   at KCS.xAP.Framework.Message.xAPMultiComponentValue..ctor(String value, Char seperator_char)
   at KCS.xAP.Framework.Message.xAPMessageBlock..ctor(String keyword)
   at KCS.xAP.Framework.Message.xAPMessageReader.ReadMessageBlockKeyword(xAPMessage message, String line)
   at KCS.xAP.Framework.Message.xAPMessageReader.ReadMessage()

But the script seems to fire.

My code for the xAPFlash config file stipulates that I need to include a little more in the header, so looks like this:

        <button NAME="Turn PC OFF">
            <gridX>2</gridX>
            <gridY>3</gridY>
            <posY>-10</posY>
            <posX>+10</posX>
            <visible>true</visible>
            <style>button60_off_.png</style>
            <textPrefix>PC_Off</textPrefix>
            <label>
                <fontsize>11</fontsize>
                <offset>-8</offset>
                <text>Shutdown PC</text>
            </label>
            <xAP>
                <schema>xAPBSC</schema>
                <uid>*</uid>
                <source>dbzoo.livebox.shutdownPC</source>
            </xAP>
            <mode>toggle</mode>
            <xapon>    
                xap-header
                {
                v=13
                hop=1
                uid=FF.0738:00
                source=UKUSA.Joggler.Controller
                target=dbzoo.livebox.shutdownPC
                class=unknown
                }
                output.state
                {
                }
            </xapon>
            <xapoff>    
            </xapoff>
        </button>

 

However this doesn't activate the script, so I was wondering if we could setup xAP on HAH for it to include plugboard scripts as xAP endpoints that follow the xAP schema?

Also I was also trying to figure out how to activate WOL entries via xAP, is this even possible?  I assume it is through some command entry but have spent some hours trying to suss it and have come up short.

Hoping you can nudge me in the right direction..

Cheers

Gary

Forums

Has anyone experienced any problems just posting an informational tweet, rather than a command tweet? 

I've written a Plugboard script to alert me when energy usage goes over a certain threshold, currently set low for testing.  However, more often than not, the tweet will never show up, after a bit of trouble shooting, I think the xap-twitter process may be deleting it as soon as it's sent it.  I've been through the Wiki a couple of times, and it does say that tweets will be deleted once actioned, but there is also an example of how to send a "Hello World" tweet.

Here is an example of the xAP messages that get generated when my script runs, and the script itself.  Perhaps a Forum area could be setup to share scripts in the future.

xAP-header
{
v=12
hop=1
uid=FF00D800
class=xAPBSC.cmd
source=dbzoo.livebox.Plugboard
target=dbzoo.livebox.Twitter
}
output.state.1
{
id=*
text=Energy usage is 891 kW
}


xap-header
{
v=12
hop=1
uid=FF00D900
class=alias
source=dbzoo.livebox.Twitter
}
command
{
text=Energy usage is 891 kW
}

 

 

And the Lua script

-- Tweet when CurrentCost reports more than 2kW

function init()
  register_source('dbzoo.livebox.CurrentCost:ch1.0', "dosource")
  watts_high_threshold = 600
  current_watts = 0
end

function tweet(msg)
   xap_send(string.format("xap-header\
{\
target=dbzoo.livebox.Twitter\
class=xAPBSC.cmd\
}\
output.state.1\
{\
id=*\
text=%s\
}", msg))
end

function dosource()
  if xAPMsg.class == "xAPBSC.event" then
        current_watts = xapmsg_getvalue("input.state","level")
        print (string.format("Current Watts = %s", current_watts))
        if tonumber(current_watts) > watts_high_threshold then
          tweet(string.format("Energy usage is %s kW", current_watts))
        end
  end
end

 

Any ideas or experience on this problem or using Twitter would be greatly appreciated.

 

Thanks

 

Karl

Forums

Hi, I was wondering why we're sending v12 xap messages?

I was thinking the new state "toggle" might be a more reliable/effective way to control/monitor RF modules.  Might be a good reason to upgrade.

 

Is it just a timing thing? 

All of my other devices are v13, will this have some negative impact on controlling them?  I guess things like level etc aren't available to control.

 

No biggie, just thinking out loud.  Is it an easy upgrade?, I may "avago".

Hope the moves the going well Brett, will we be seeing higher or lower temps on Pachube?

Cheers

Gary

Forums

Hi,

Thought this might be useful.  Here's my script to shutdown a remote Windows based PC.

Firstly you'll need to install a small app call Airytech SwitchOff on the remote machine.

You can get that here: http://www.airytec.com/en/switch-off/ &nbsp; Turn on the remote access feature in that app.

This opens http on port 8000

here's my script for the plugboard:


-- Script to shutdown remote windows PC
-- requires Airytech SwitchOff to be running on remote system
-- http://www.airytec.com/en/switch-off/

-- Registers ShutdownPC service
function init()
  register_target("dbzoo.livebox.ShutdownPC", "shutdown")
end

-- Sends http request to remote PC
function shutdown()
  os.execute("curl http://remoteip:8000/?action=System.Shutdown")
end

Here's my header for GoogleCal:

xap-header
{
target=dbzoo.livebox.ShutdownPC
class=unkown
source=Google
}

Nice thing about this is that it shutdowns all the open apps 'nicely' and then shutdowns the PC.

You can of course just use the app itself to schedule a shutdown....but that's not the point!

Now to figure out how to turn it back on again...myabe I'll just have to use the 'On' button!

Forums

Hi Brett, Derek

I'm still upto my forhead wrinkles in LUA scripts.  I've noticed in your examples a function called recent_cache.

There's no mention of this function in the Implementation list, this maybe becuase it is not a C function?

It would still be usefull to have it doc'd...it seems to work similarly to xapcache_find?

 

Cheers

Gary

Forums

I've been frying my brains trying to get started on the Lua scripts to bring some intelligence to my HAH.

I just don't seem to be able to get anything going.

  • I have enabled the plugboard in the xap-livebox.ini.
  • I have added scipt(s) to the /etc/plugboard folder.
  • I am assuming that if I run the script it should have some effect.
  • I have tested the RF socket from the WebGui.

My first script is a somewhat confused attempt to turn on an RF socket if the temp get's above 33c.

-- Script to turn fan 1 on via RF when temp hits 33
-- Rev 0.1
--
function init()
  register_source('dbzoo.livebox.Controller:1wire.1', "gettemp")
--  register_source('dbzoo.livebox.Controller:rf.2', "getstate")
end

-- This is the xap header for turning RF on function cmd(action)
  xap_send(string.format("xap-header\
{\
target=dbzoo.livebox.Controller:rf.2\
class=xAPBSC.cmd\
}\
output.state.1\
{\
id=*\
state=%s\
}", action))
end

-- Get state of RF.2
-- function getstate()
--    state = xapmsg_getvalue("output.state", "state")
-- end

-- Get valid info from sensor
function gettemp()
  if xAPMsg.class == "xAPBSC.event" then
    if xapmsg_getvalue("input.state", "text") > 33 then
--       state == "off" then
         cmd("on")
    end
  end
end

I know there maybe be a couple of fumbles in this script but at the moment I just want to see the RF switch activate.

I run the script by typing 'lua temp_high.lua' from the console.  I'm expecting the RF switch to activate when the temp is above 33(which it is)? Nothing happens!  Grr!

Please provide clip round ear, condescending tut and a handy answer to put me out of my misery!

Thanks

Gary

Forums

Hi,

 

I have just flashed my recently acquired livebox with the HAH firmware - great instructions guys.

 

I see that you have a download on your site for usr.tar.bz2 which includes the gcc compiler also as well as Python runtime. Is it just a case of extracting the files into the /opt directory?

 

How do you run a python script?

 

Thanks,

John