Trigger php function on status change


I’m working on a home automation system right now and for that I would need to trigger a php function to run. Is there a way to do this from rules or something?

I hope you understand my question


Do you need to directly call PHP or do you want to trigger a PHP-based web application?

If you need to call PHP directly, take a look at the exec actions or binding. If you need to trigger a PHP web app, take a look at the HTTP actions or binding.

I have installed php on my raspberry and built a homepage for my controller, a tablet. The thing is that I want to be able to send SMS, i have a sim card connected to my router and created a php script to send and receive messages. I also want to be able to log things in php, ex if a motionsensor is triggerd or battery is low on a device or something like that. I want to be able to log everything and then work from the current state to do some stuff from php.I hope you understand what I mean, my english is not so good.

So, for example, a motionsensor is triggered, I want to run a php function to log this to mysql database, and then send sms to myself with a picture from my cameramodule.

I have all php pages in /var/www/html, how do I run a specific function in a specific file in that location from php. I read about exec and it seems to be a quite good way but I still can’t understand how to do it.

I can’t answer your other questions except to point you to the Exec binding wiki page and executeCommandLine actions. You basically just send it the command like to call your PHP the same way you would do from the command line. If you use the executeCommandLine(cmd, timeout) action in a rule, it will return what the command prints out which is helpful for debugging.

But I can say that there is a MySQL persistence engine which saves all your Item’s states in MySQL so you shouldn’t need to write a separate PHP script to do that.

To do something like your example you would:

rule "Motion sensor"
    Item MyMotionSensor received command
    val results = executeCommandLine("call to php", 5000)
    logInfo("Results", results)

Where “call to php” is the command line string you would type on the command line to execute your php script.

Thank you so much @rlkoshak for your help and kicking me in the right direction :slight_smile: