Access Keys:
Skip to content (Access Key - 0)
 

More Rules Help...

Phillip Lavender

On Apr 28, 2012 11:32

Hi,

It's been a while since I used OR, but now the Rules engine is in place I think I can finally achieve what I wanted only I´m not sure how. I´ve read the exmaples and the forum posts and still really have no idea where to start.

Here's the situation. (pre-rules)

I have an Amp (Onkyo) that provides an ASCII reponse to a Command queston. I wanted to create a volume slider so I created a Sensor (VolumeSensor) from a VolumeStatus TCP/IP command: !MVLQSTN
Next I created a Slider (VolumeSlider) with the VolumeSensor from above and a new command VolumeWriter using command !1MVL$

Unknown macro: {param}

First issue the status response from the sensor is in the form of an ASCII string e.g. !MVLxx. (OK so I overcame this partially with the regexp branch to only return the int val of the reponse.) However that lead to a bigger problem, that I think only rules can resolve, so never went any further. If I add another sensor say PowerSensor from the command !PWRQSTN since both sensors are linked to the same IP/PORT the reponse goes to both, which causes some strange undesired behaviour, so here's what I need now (post-rules)and not sure about the best way to go about it.

I need to be able to take a command !MVLQSTN and covert it´s reponse !MVLxx to and integer to update a Slider (VolumeSensor) but the rules should only update the sensor if the reponse starts with !MVL. Then I´m free to create other rules of a simlar nature that only update say if the reponse to their specific question i.e. a PowerSwitch where the sensor command is !PWRQSTN and the reponse is !PWR00 or !PWR01.

In rules how do I take the value of the response to the sensor command,say VolumeSensor (!MVLxx), parse it, check the first part,(if eq !MVL) then convert the remainder to an integer (int) and 'publish' that value as the sensor output so that the Slider updates.

I'm really lost here an going round in circles.

Help much appreciated.

Phill

 
Labels:
Participants: Phillip Lavender , Marcus Redeker
  1. May 04, 2012

    Marcus Redeker says:

    Maybe you can take this rule as a hint: package org.openremote.controller.mo...

    Maybe you can take this rule as a hint:

    package org.openremote.controller.model.event
    global org.openremote.controller.statuscache.CommandFacade execute;
    global org.openremote.controller.statuscache.SwitchFacade switches;
    global org.openremote.controller.statuscache.LevelFacade levels;
    
    import java.lang.Float;
    
    rule "test 1"
    when
    CustomState(source == "Temp1Sensor", val : value, eval(Float.valueOf(val) > 24.000) && eval(Float.valueOf(val) < 26))
    then
    System.out.println("between 24 and 26");
    end
    

    You should be able to take the source name and put that into a variable. After that perform an eval(xxx.startsWith("!MVL").
    There is a very extensive documentation available on the Drools website and our testsuite also has a lot examples already.

Adaptavist Theme Builder Powered by Atlassian Confluence