Menu

Evaluate Condition based on file

airmax-b3
2009-09-13
2012-12-14
  • airmax-b3

    airmax-b3 - 2009-09-13

    I'd like to use the information in a file to evaluate if a condition is true or not. Is this possible with linknx?

    Background: My SolarLog 500 System writes its current power (which is linearly dependent to solar radiation) in a file on a webserver every 10  minutes. I'd like to use this value, to decide weather to close the blinds or not.

     
  • uidas

    uidas - 2009-09-14

    You can create a script that monitor the file and write the current power to linknx through XML interface.

    The script I use with Asus WL500GPv1 (OpenWRT Kamikaze 7.09)

        #!/bin/sh
        objectid=init
        objectvalue=1
        XMLresponse=$(printf "<write><object id='"$objectid"'  value='"on"'/></write>\n\x4"  | /usr/bin/nc -c 127.0.0.1 1028 )
        while ; do
            sleep 1
            XMLresponse=$(printf "<write><object id='"$objectid"' value='"$objectvalue"'/></write>\n\x4"  | /usr/bin/nc -c 127.0.0.1 1028 )
        done

        # uncomment echos for debug
        # request status. success or error
        #XMLrespstatus=$(echo $XMLresponse | /bin/sed "s/<write status='\(*\)'.*./\1/"  | /usr/bin/head -n 1)

        # Error description
        #if ; then
        #       XMLrespstring=$(echo $XMLresponse | /bin/sed "s/<write status='error'>\(.*\)<\/write>/\1/"  | head -n 1)
        #else
        #        XMLrespstring=''
        #fi

        #echo response: $XMLresponse
        #echo status: $XMLrespstatus
        #echo string: $XMLrespstring

    In Suse Linux Enterprise Server I use  netcat  127.0.0.1 1028 (without -c)

     
  • jef2000

    jef2000 - 2009-09-28

    Hi,

    To set an object value based on file content, you can use a LUA script  like this:

           

            <rule id="solar-power">
                    <condition type="timer" trigger="true">
                        <every>10m</every>
                    </condition>
                    <actionlist>
                        <action type="script"><![CDATA[
        file = io.open("solarpower.txt", "r");
        power = file:read("*n");
        - print ("Power is ::" .. power .. "::\n") ;
        file:close();
        if (power > 1500) then
            set("blinds", 1);
        end
        if (power < 500) then
            set("blinds", 0);
        end
        ]]>
                        </action>
                    </actionlist>
                </rule>

    Regards,

    Jean-François

     
  • jef2000

    jef2000 - 2009-09-29

    Hi,

    Since the previous message was severely mutilated by Sourceforge editor, I'll try again.

    To set an object value based on file content, you can use a LUA script like this:

            <rule id="solar-power">
                <condition type="timer" trigger="true">
                    <every>10m</every>
                </condition>
                <actionlist>
                    <action type="script"><![CDATA[
                    file = io.open("solarpower.txt", "r");
                    power = file:read("*n");
                    - print ("Power is ::" .. power .. "::\n") ;
                    file:close();
                    if (power > 1500) then
                        set("blinds", 1);
                    end
                    if (power < 500) then
                        set("blinds", 0);
                    end
                    ]]>
                    </action>
                </actionlist>
            </rule>

    Regards,

    Jean-François

     
  • jef2000

    jef2000 - 2009-09-29

    The preview text looks good, but once submitted the text is wrong.

    You need to replace < by < , > by > and  " by " to get the original text. Thanks Sourceforge.

     
  • airmax-b3

    airmax-b3 - 2009-09-29

    Thank you - the is code shown correctly in the e-mail notification that I received.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.