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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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)
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
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
The preview text looks good, but once submitted the text is wrong.
You need to replace &lt; by < , &gt; by > and &quot; by " to get the original text. Thanks Sourceforge.
Thank you - the is code shown correctly in the e-mail notification that I received.