[SOLVED] Item linked with file

I have a file (let’s say ‘powerstatus’) that has only 2 values 0 or 1.
(This is just a script on another server that echo 0 or 1 into that file.)

Is there a way that I create an item ‘from’ this file?
Or what’s a good way?

The end goal is to update an item with the power status of servers. That I can use in rules, sitemaps…
And linked with this, send out messages, reboot/shutdown machines…

Not directly, but you could use the executeCommandLine action

for example:

var String result = executeCommandLine("cat path/to/file/file.txt", 1000)
if (result == "0") {
} else if (result == "1") {
1 Like

Works great!!! Thanks!

Hereby the convert rule, and the rule that’s been triggered by it:

rule "check powerstatus of Hypervisor"
//Convert textvalue 0 or 1 towards OH item ON or OFF.
	Time cron "0 0/1 * * * ?"
	Thread::sleep(10000) // Give other server some time
	var String result = executeCommandLine("cat /diy/power_status",2000)
	if (result == "0") {
	else if (result == "1") {

rule "Action for Hypervisor on power failure"
//Trigger action if power is lost
	Item HypervisorPower changed from ON to OFF

ps The thread of 10 sec is because the other server is also trigger every minute. This way, I’m sure that the other server is finished with his check. Else I would lose a whole minute, and with my small UPS… :wink:

So why not trigger the rule using `10 0/1 * * * ?" ? This is functionally equivalent to what you are doing only you won’t be tying up a runtime thread waiting for those ten seconds.


I come from the linux world. In cron, no seconds, only minutes… :open_mouth:
So not used to think that way. :wink:

Thanks for the remark! I’ve updated it accordingly…

rule "check powerstatus of Audrey"                                                                                                                                                                                                                       
        Time cron "10 0/1 * * * ?"