Commit d26887ad authored by Vassilis Panos's avatar Vassilis Panos
Browse files

New broadlink service

parent a972bf70
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -12,8 +12,7 @@ _Please note that the device_code field only accepts positive numbers. The .json
**name** (Optional): The name of the device<br />
**unique_id** (Optional): An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception.<br />
**device_code** (Required): .... (Accepts only positive numbers)<br />
**controller_send_service** (Required): The service that will be used to send the commands. Only `broadlink_send_packet` (Broadlink controller) and `mqtt.publish` is currently supported.<br />
**controller_command_topic** (Optional): MQTT topic on which to send commands when *controller_send_service* is mqtt.publish<br />
**controller_data** (Required): The data required for the controller to function. Enter the IP address of the Broadlink device (must be an already configured device) or the MQTT topic on which to send commands.<br />
**temperature_sensor** (Optional): *entity_id* for a temperature sensor<br />
**humidity_sensor** (Optional): *entity_id* for a humidity sensor<br />
**power_sensor** (Optional): *entity_id* for a sensor that monitors whether your device is actually On or Off. This may be a power monitor sensor. (Accepts only on/off states)<br />
@@ -32,7 +31,7 @@ climate:
    name: Office AC
    unique_id: office_ac
    device_code: 1000
    controller_send_service: switch.broadlink_send_packet_192_168_10_10
    controller_data: 192.168.10.10
    temperature_sensor: sensor.temperature
    humidity_sensor: sensor.humidity
    power_sensor: binary_sensor.ac_power
@@ -49,8 +48,7 @@ climate:
    name: Office AC
    unique_id: office_ac
    device_code: 2000
    controller_send_service: mqtt.publish
    controller_command_topic: home-assistant/office-ac/command
    controller_data: home-assistant/office-ac/command
    temperature_sensor: sensor.temperature
    humidity_sensor: sensor.humidity
    power_sensor: binary_sensor.ac_power
+3 −5
Original line number Diff line number Diff line
@@ -9,8 +9,7 @@ Find your device's brand code [here](FAN.md#available-codes-for-fan-devices) and
**name** (Optional): The name of the device<br />
**unique_id** (Optional): An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception.<br />
**device_code** (Required): ...... (Accepts only positive numbers)<br />
**controller_send_service** (Required): The service that will be used to send the commands. Only `broadlink_send_packet` (Broadlink controller) and `mqtt.publish` is currently supported.<br />
**controller_command_topic** (Optional): MQTT topic on which to send commands when *controller_send_service* is mqtt.publish<br />
**controller_data** (Required): The data required for the controller to function. Enter the IP address of the Broadlink device or the MQTT topic on which to send commands.<br />
**power_sensor** (Optional): *entity_id* for a sensor that monitors whether your device is actually On or Off. This may be a power monitor sensor. (Accepts only on/off states)<br />

## Example (using broadlink controller):
@@ -27,7 +26,7 @@ fan:
    name: Bedroom fan
    unique_id: bedroom_fan
    device_code: 1000
    controller_send_service: switch.broadlink_send_packet_192_168_10_10
    controller_data: 192.168.10.10
    power_sensor: binary_sensor.fan_power
```
Make sure the broadlink switch is already installed. Go to the Home Assistant UI/dev service, find the broadlink send_packet service and copy the name of it.
@@ -42,8 +41,7 @@ fan:
    name: Bedroom fan
    unique_id: bedroom_fan
    device_code: 2000
    controller_send_service: mqtt.publish
    controller_command_topic: home-assistant/bedroom-fan/command
    controller_data: home-assistant/bedroom-fan/command
    power_sensor: binary_sensor.fan_power
```

+3 −5
Original line number Diff line number Diff line
@@ -9,8 +9,7 @@ Find your device's brand code [here](MEDIA_PLAYER.md#available-codes-for-tv-devi
**name** (Optional): The name of the device<br />
**unique_id** (Optional): An ID that uniquely identifies this device. If two devices have the same unique ID, Home Assistant will raise an exception.<br />
**device_code** (Required): ...... (Accepts only positive numbers)<br />
**controller_send_service** (Required): The service that will be used to send the commands. Only `broadlink_send_packet` (Broadlink controller) and `mqtt.publish` is currently supported.<br />
**controller_command_topic** (Optional): MQTT topic on which to send commands when *controller_send_service* is mqtt.publish<br />
**controller_data** (Required): The data required for the controller to function. Enter the IP address of the Broadlink device or the MQTT topic on which to send commands.<br />
**power_sensor** (Optional): *entity_id* for a sensor that monitors whether your device is actually On or Off. This may be a power monitor sensor. (Accepts only on/off states)<br />

## Example (using broadlink controller):
@@ -27,7 +26,7 @@ media_player:
    name: Living room TV
    unique_id: living_room_tv
    device_code: 1000
    controller_send_service: switch.broadlink_send_packet_192_168_10_10
    controller_data: 192.168.10.10
    power_sensor: binary_sensor.tv_power
```
Make sure the broadlink switch is already installed. Go to the Home Assistant UI/dev service, find the broadlink send_packet service and copy the name of it.
@@ -42,8 +41,7 @@ media_player:
    name: Living room TV
    unique_id: living_room_tv
    device_code: 2000
    controller_send_service: mqtt.publish
    controller_command_topic: home-assistant/living-room-tv/command
    controller_data: home-assistant/living-room-tv/command
    power_sensor: binary_sensor.tv_power
```

+4 −8
Original line number Diff line number Diff line
@@ -26,8 +26,7 @@ DEFAULT_NAME = "SmartIR Climate"

CONF_UNIQUE_ID = 'unique_id'
CONF_DEVICE_CODE = 'device_code'
CONF_CONTROLLER_SEND_SERVICE = "controller_send_service"
CONF_CONTROLLER_COMMAND_TOPIC = "controller_command_topic"
CONF_CONTROLLER_DATA = "controller_data"
CONF_TEMPERATURE_SENSOR = 'temperature_sensor'
CONF_HUMIDITY_SENSOR = 'humidity_sensor'
CONF_POWER_SENSOR = 'power_sensor'
@@ -43,8 +42,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Optional(CONF_UNIQUE_ID): cv.string,
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
    vol.Required(CONF_DEVICE_CODE): cv.positive_int,
    vol.Required(CONF_CONTROLLER_SEND_SERVICE): cv.entity_id,
    vol.Optional(CONF_CONTROLLER_COMMAND_TOPIC): cv.string,
    vol.Required(CONF_CONTROLLER_DATA): cv.string,
    vol.Optional(CONF_TEMPERATURE_SENSOR): cv.entity_id,
    vol.Optional(CONF_HUMIDITY_SENSOR): cv.entity_id,
    vol.Optional(CONF_POWER_SENSOR): cv.entity_id
@@ -96,8 +94,7 @@ class SmartIRClimate(ClimateDevice, RestoreEntity):
        self._unique_id = config.get(CONF_UNIQUE_ID)
        self._name = config.get(CONF_NAME)
        self._device_code = config.get(CONF_DEVICE_CODE)
        self._controller_send_service = config.get(CONF_CONTROLLER_SEND_SERVICE)
        self._controller_command_topic = config.get(CONF_CONTROLLER_COMMAND_TOPIC)
        self._controller_data = config.get(CONF_CONTROLLER_DATA)
        self._temperature_sensor = config.get(CONF_TEMPERATURE_SENSOR)
        self._humidity_sensor = config.get(CONF_HUMIDITY_SENSOR)
        self._power_sensor = config.get(CONF_POWER_SENSOR)
@@ -132,8 +129,7 @@ class SmartIRClimate(ClimateDevice, RestoreEntity):
            self.hass,
            self._supported_controller, 
            self._commands_encoding,
            self._controller_send_service,
            self._controller_command_topic)
            self._controller_data)
            
    async def async_added_to_hass(self):
        """Run when entity about to be added."""
+6 −13
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ BROADLINK_COMMANDS_ENCODING = [
MQTT_COMMANDS_ENCODING = [ENC_RAW]

class Controller():
    def __init__(self, hass, controller, encoding, service, topic=None):
    def __init__(self, hass, controller, encoding, controller_data):
        if controller not in [
            BROADLINK_CONTROLLER, XIAOMI_CONTROLLER, MQTT_CONTROLLER]:
            raise Exception("The controller is not supported.")
@@ -40,16 +40,10 @@ class Controller():
                raise Exception("The encoding is not supported "
                                "by the mqtt controller.")

            if not topic:
                raise Exception("controller_command_topic must be "
                                "specified for mqtt controllers.")

        self.hass = hass
        self._service_domain = split_entity_id(service)[0]
        self._service_name = split_entity_id(service)[1]
        self._command_topic = topic
        self._controller = controller
        self._encoding = encoding
        self._controller_data = controller_data

    async def send(self, command):
        if self._controller == BROADLINK_CONTROLLER:
@@ -73,20 +67,19 @@ class Controller():
                                    "Pronto to Base64 encoding")

            service_data = {
                'host': self._controller_data,
                'packet': command
            }

            await self.hass.services.async_call(
                self._service_domain, self._service_name, 
                service_data) 
                'broadlink', 'send', service_data) 
                

        if self._controller == MQTT_CONTROLLER:
            service_data = {
                'topic': self._command_topic,
                'topic': self._controller_data,
                'payload': command
            }

            await self.hass.services.async_call(
                self._service_domain, self._service_name, 
                service_data)
 No newline at end of file
               'mqtt', 'publish', service_data)
 No newline at end of file
Loading