Mac os script

Hi I don’t know if i’m at the right place so don’t be rude :stuck_out_tongue: I use remote body on my mac https://www.iospirit.com/products/remotebuddy/

For people wo don’t know the software it allow me to control any software in my mac with a big selection of remote.

so i made a shity python script that open or close my light (milight/limitlessled) so when I start a tv show on my mac i can control my light or when i play music i can put disco mode on my light etc…

Since Openhab is way better than my shity script and it remember of the state of my light (last input) i want to put Openhab in my remote buddy.

To do that I juste need a terminal shell command who gonna call the miligth method in Openhab

I’m pretty new to Openly but it must have a way to send command to openhab right ?

Thanks

You can POST an update/command to any ITEM by /rest API. This is the function I use in PHP on Linux to do it. I am not sure if php is standard for MacOS or it is part of a development suite, I have it mine. You can verify this by typing in the remninal php -v:

jj-mac:~ Jj$ php -v
PHP 5.5.27 (cli) (built: Jul 23 2015 00:21:59) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

Check where the php (by typing which php) is in the system and change the path to interpretter in the first row of the script accordingly. If OpenHab runs on a different machine you should change the the url to point to the right address.

Please let me know if it worked for you.

Here is the script to switch MyMilight item to OFF:

#!/bin/php
<?php
function sendCommand($item, $data) {
   $url = "http://localhost:8080/rest/items/" . $item;
   $options = array( 'http' => array(
                      'header'  => "Content-type: text/plain\r\n",
                      'method'  => 'POST',
                      'content' => $data));
   $context  = stream_context_create($options);
   $result = file_get_contents($url, false, $context);
   return $result;
}
sendCommand ("MyMilight", "OFF");
?>

And On script:

#!/bin/php
<?php
function sendCommand($item, $data) {
$url = "http://localhost:8080/rest/items/" . $item;
$options = array( 'http' => array(
                  'header'  => "Content-type: text/plain\r\n",
                  'method'  => 'POST',
                  'content' => $data));
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
sendCommand ("MyMilight", "ON");
?>

You can use curl and do it with a one-line command. For example,

curl --header 'Content-Type: text/plain' --request POST --data 'ON' 'http://192.168.100.21:8080/rest/items/MyLight'

Where you would substitute the hostname or IP address of your openHAB server for 192.168.100.21 and the name of your item for MyLight. See also:

https://github.com/openhab/openhab/wiki/Samples-REST#curl

I’ve used curl on my Mac for testing openHAB functionality locally and my RPi server. I don’t think it ships with Mac OS X, but you can install it using Mac Ports or Homebrew.

Wow ! thanks and just by curiosity, How do you change the color or dim the light

For dimmer: sendCommand (dimmer,80) to set dimmer to 80%
For RGB I set each colour sepatately, in the same way.

I don’t get how the color work… i look at my code and the command was like : sendCommand (“Light_Party”, “0,80,100”) but i don’t know what the value mean

Most likely these are values for RGB color components: 0% red, 80% green, 100% blue that will be somenting close to cyan color.

This is what i taught but … the last value (100) is for the brightness …

and this is green : sendCommand (“Light_Party”, “100,0,100”);

Finaly, What is the white command !?

EDIT: I just found on openhab documentation that the Color type item is control by HSB

ItemtypeDescription_______ Command Types
Color______Color information (RGB)_____OnOff, IncreaseDecrease, Percent, HSB
( https://github.com/openhab/openhab/wiki/Explanation-of-items )

So i found this site : RGB to HSV conversion | color conversion so i can find my color…
I just can’t figure out how to put it white