Skip to content
matsfunk edited this page Jan 6, 2022 · 2 revisions

Create a HeyOOCSI device:

To integrate OOCSI with HomeAssistant we need to create a heyOOCSI device:


Python

from oocsi import OOCSI
o = OOCSI('testHeyOOCSI', 'localhost')
prototypename = o.heyOOCSI()

Arduino / ESP

oocsi.connect("devicename", "server IP", "ssid", "password");
OOCSIDevice prototypename = oocsi.heyOOCSI("prototypename");

OOCSI Properties:

Add some extra information so everyone knows who they're talking with. such as creator information.


prototypename.addProperty(propertyName, propertyValue)

TBD. Will be finished after device page is integrated

OOCSI Location:

Add a location for later location based systems.


prototypename.addLocation(location_name, latitude, longitude)

Contains location data of the device, currently not implemented properly in home assistant. Requires Latitude and Longitude values as a float to create a detailed location.

OOCSI Entities:

Now the real deal, These lines will add the real functionality to your prototype, pick one you are interested in!


Sensor:

Create a sensor that sends data to home-assistant.


prototypename.addSensor(Name, OOCSI Channel, Type, Unit, Default value, icon)
Name description Value type allowed values
Name Device name. Required, String Any.
OOCSI Channel the OOCSI Channel we will use to communicate with the entity. Required, String An unique name per device.
Type What kind of sensor is it? Optional, String https://developers.home-assistant.io/docs/core/entity/sensor/#available-device-classes
Unit The unit of output. Required, String https://developers.home-assistant.io/docs/core/entity/sensor/#available-device-classes
Default value Value of sensor when idle. Optional, String Any.
Icon The icon displayed in HA. Optional, String https://materialdesignicons.com/ Copy the title of the icon page

Number input:

Create a number input in home-assistant.
prototypename.addNumber(Name, OOCSI Channel, Min-Max, Unit, Default value, icon)
Name description Tags allowed
Name Device name. Required, String Any.
OOCSI Channel The OOCSI Channel we will use to communicate with the entity. Required, String An unique name per device.
Min and Max value The minimum and maximum value the number input can take. Array, Float Any float, default 0 to 100
Unit The unit of input. String https://developers.home-assistant.io/docs/core/entity/sensor/#available-device-classes
Default value Value of sensor when starting. Float Any.
Mode The way of input. TBD.
Icon The icon displayed in HA. String https://materialdesignicons.com/ Copy the title of the icon page

Output:

{"value", <value>}

Binary sensor:

Create a binary sensor display in home-assistant.
prototypename.addBinarySensor(Name, OOCSI Channel, Sensortype, Default state, icon)
Name description Tags allowed
Name Device name. Required, String Any.
OOCSI Channel The OOCSI Channel we will use to communicate with the entity. Required, String An unique name per device.
Type The type of binary sensor. Optional, String https://developers.home-assistant.io/docs/core/entity/binary-sensor#available-device-classes
Default value Value of sensor when starting. Boolean, Required Value of sensor when starting.
Icon The icon displayed in HA. Optional, String https://materialdesignicons.com/ Copy the title of the icon page

Switch:

Create a digital switch in home-assistant.


prototypename.addSwitch(Name, Switchchannel, Switchtype, Default state, icon)
Name description Tags allowed
Name Device name. Required, String Any.
OOCSI Channel The OOCSI Channel we will use to communicate with the entity. Required, String An unique name per device.
Type The type of binary sensor. Optional, String https://developers.home-assistant.io/docs/core/entity/switch#available-device-classes
Default value Value of sensor when starting. Boolean, Required Value of sensor when starting.
Icon The icon displayed in HA. Optional, String https://materialdesignicons.com/ Copy the title of the icon page

Output:

{state,<True/False>}

Light:

Create a digital light remote in home-assistant.


prototypename.addLight(Name, OOCSI Channel, Ledtype, Spectrum, Default state, Default brightness, Miredminmax, icon)
Name description Tags allowed
Name Device name. Required, String Any.
OOCSI Channel The OOCSI Channel we will use to communicate with the entity. Required, String An unique name per device.
Led type what type of lamp are you using? Required, String RGB, RGBW, RGBWW, CCT, DIMMABLE, ONOFF
Spectrum what spectrum(s) do you want your light to display only needed when using rgb lights Optional, Required, String array CCT, WHITE, RGB
Default state State of lamp when starting. Boolean, Optional Value of light when starting. default = off
Default brightness brightness value of light when starting. Int The default brightness when switching on. Value from 0 to 255
Mired Min and Max, These are only required when using CCT only leds The maximum and minimum values of the colour temperature Int array, Optional Any integer your light supports, this is meant for colour accuracy
Icon The icon displayed in HA. Optional, String https://materialdesignicons.com/ Copy the title of the icon page

Output:

**"When using RGB/RGBW/RGBWW strips and a rgb spectrum"**
**"colourRGB":<R,G,B>, 
"colourRGBW":<R,G,B,W>, 
"colourRGBWW":<R,G,B,WarmWhite,ColdWhite>:
"When using RGB/RGBW strips and a cct spectrum":
"colorTempInRGB":<R,G,B>:
"When using white lights":
"brightnessWhite":<brightness white state>
"When using cct lights":
"colorTemp": <warm, cold>**
**"combined with state and brightness":**
{"brightness":<brightness>,"colourRGB()":<R,G,B>,state:<True/False>}

OOCSI sayHi:

After creating the prototype properties we need to submit everything.


prototypename.sayHi()

This command sends the device properties to home-asssistant and makes your device good to go!

Example:

from oocsi import OOCSI
import time
# oocsiConnection
o = OOCSI('testHeyOOCSI', 'localhost')
# create OOCSIDevice -----------------------------------------------------------------------------
# default name for device:
device = o.heyOOCSI()
# named device (for multiple digital oocsiDevices):
# device = o.heyOOCSI("my_first_device")
# create entities for the device:
# TODO document calls 
device.add_binary_sensor_brick("sensor_name", "sensor_channel", "sensor_type", "sensor_default")
# TODO document calls 
device.add_binary_sensor_brick("sensor_name2", "sensor_channel2", "sensor_type", "sensor_default")
# TODO document calls 
device.add_switch_brick("switchname", "sensor_channel", "switch", "false", "lightbulb")
# TODO add all remaining calls 
# TODO add example for property
# TODO add example for location
 
# don't forget to send the description off to the OOCSI server
device.sayHi()
# -----------------------------------------------------------------------------------------------
# run normal device-OOCSI communication 
while 1:
    message = {}
    message['state'] = True
    o.send('sensor_channel', message)
    time.sleep(2)
    message2 = {}
    message2['state'] = False
    o.send('sensor_channel', message2)
    time.sleep(2)
    # wait and continue