Add integration for Hisense devices using ConnectLife

Looks like I had a bug with setTemperature try again with the latest version on github.

Should look like this when it runs now:

/poc.py", line 131, in
device = appliance(ApplianceResponse.json()[0])
IndexError: list index out of range

Is there an option to see all the output the script gets?

Also a question on the swagger.

  1. Back on the main page, click on “GET /api/v1/appliance”, then “try it out”, then “execute”

After this point - shall i see the linked appliances in the response there?

You could add this after line 140 to see what the response is:

print('\n\n' + str(ApplianceResponse.json()) + '\n\n')

If you don’t have 2 devices maybe you don’t need the index? So replace 143 with this?

device = appliance(ApplianceResponse.json())

You should see this on the swagger page. The red box is what you copy into the script.

The problem was with the region i used for registration. After switching it.

<Response [200]>
Traceback (most recent call last):
  File "/home/pi/poc.py", line 136, in <module>
    device.setTemperature('35', True)
TypeError: 'str' object is not callable

Code sent

device.setSystemMode('Heat', True)
device.setTemperature('35', True)
device.setFanSpeed('Medium', True)

Where I live - Cooling is done behind the door at this time of year :slight_smile:

1 Like

So this means that an api is freely available? Hopefully someone will get the integration going. Should have learned programming myself but… Too late

Technically it’s not available since you can’t generate your own client_id and client_secret, but it works if you just use theirs.

Did anyone actually managed to implement any ConnectLife device in HomeAssistant?

I received this email this morning.
They are still working.

Since the original request has been denied by the mfgr several times, and since there is no current core integration for this that can be modified, this appears to be more of a third party integration question. It will therefore be moved to that topic category.

Anyone contacted Hisense team lately?

p.s. Ok I did. Prompt reply.
So all i can say do not buy HiSense appliances or AC if you plan to run them with HA

2 Likes

I see that you haven’t abandoned the project! Everything works but one question. Any plans to add an option of On/Off?

I get this answer

Got the python script running and could try and make a package for HA but the token changes which is annoying. Also tried just running a rest command from my configuration.yaml file but no luck.

It there a way to get the access token using HA? In this case it is possibile to use a restful switch:

switch:
  - platform: rest
    name: Climatizzatore Ufficio 1
    resource: "https://api.connectlife.io/api/v1/appliance"
    state_resource: "https://api.connectlife.io/api/v1/appliance/MYDEVICE"
    body_on: '[{"id": "MYDEVICE","properties": {"Power": "1" }}]'
    body_off: '[{"id": "MYDEVICE","properties": {"Power": "0"}}]'
    is_on_template:  '{{ value_json[0].properties.Power == "1" }}'
    method: POST
    headers:
      Content-Type: application/json
      accept: application/json
      Authorization: "Bearer MYTOKEN"
    verify_ssl: false

And also to set the temperature and so on…

But it is necessary to find a way for receive the access token. Because it has a 24 h validity and so must be restored

1 Like

Hola, soy usuario novato completamente, mi solución paso por alexa que si que tiene comunicación directa con connect life, añadí unos boolean que mandan un mensaje a alexa cuando quiero encender o apagarlos, este mensaje puede ser configurado con temperatura también, después expones los boolean a alexa y los pones a funcionar de manera paralela.

1 Like

I tried and it’s working, so the ideal at the moment is this:

Connect “connectlife” to alexa or google home

Create some input boolean where you want to turn on the AC, and expose them to alexa

Create a routine on Alexa to turn on the “thermostat”, to the selected temperature that you want, and which area that you want

Then, make some automation where you trigger those boolean

In this way you can control the split via home assistant

The only problem i see is that you cannot select the mode in the smart home routine, so you cant select heating, cooling, or other modes…

I hope this is usefull

1 Like

guys any luck with this project?
i want to be able to get sensor data from the ac.
:frowning:

hi…i’ve implemented this solution, but now i’ve a problem, how can i know if an a/c is on or off is someone will turn it on or off by connectlife or by a local remote?
I cannot use a power consumpion (ive trial split) and i cannot use a contact open sensor physically on the a/c.

I found an “half” solution and I want to share.

What works:
. On/off conditioner
. Set temperature
. Set mode
. Get status of conditioner (on off)
. Regenerate token

To do:
. Generate a token from scratch

Requirement:
. Have an access token and refresh token from Swagger (see below)

Procedure:

  1. Install node-red-contrib-oauth2 (node) - Node-RED and install the sample flow
  2. Follow AEH-W4G2 · Issue #160 · deiger/AirCon · GitHub to get access token and refresh token from Swagger UI
  3. Fill the sample flow of nodered with data obtained from 2. (compile only the REFRESH SECTION)
  4. Let nodered refresh token every 12 hours (very important)
  5. In nodered flow, add an mqtt topic ( /connectlife/token) in order HA to get token from nodered

Use the entities on HA:

input_number:
  clima_ufficio_1_temp:
    name: Temperatura Clima Ufficio 1
    min: 17
    max: 28
    step: 1
    mode: box


input_select:
  clima_ufficio_1_mode:
    name: Modalità Clima Ufficio 1
    options:
      - Caldo
      - Freddo
      - Ventilazione
      - Deumidificatore



mqtt:
  sensor:
  ### THESE SENSORS CONTAIN THE TOKEN FROM NODERED. IT MUST SPLIT IN 2 PARTS, BECAUSE HA DOES NOT HANDLE A STRING > 255 chrs
  - name: "Token Hisense A"
    state_topic: "connectlife/token"
    value_template: "{{value[:250]}}"

  - name: "Token Hisense B"
    state_topic: "connectlife/token"
    value_template: "{{value[250:]}}"


binary_sensor:
  - platform: rest
    resource: https://api.connectlife.io/api/v1/appliance/PUT-HERE-THE-ID-OF-YOUR-DEVICE
    method: GET
    name: Clima Ufficio 1 ISON
    device_class: light
    value_template: '{{ value_json[0].properties.Power == "1" }}'
    headers:
      Content-Type: application/json
      Authorization: 'Bearer {{states("sensor.token_hisense_a")+states("sensor.token_hisense_b")}}'
    verify_ssl: false    


    
switch:
  - platform: template
    switches:
      climatizzatore_ufficio_1:
        friendly_name: "Climatizzatore Ufficio 1"
        value_template: "{{ is_state('binary_sensor.clima_ufficio_1_ison', 'on') }}"
        turn_on:
         - service: shell_command.clima_ufficio_1_on
         - delay:
            seconds: 5
         - service: homeassistant.update_entity
           target:
            entity_id: binary_sensor.clima_ufficio_1_ison
        turn_off:
         - service: shell_command.clima_ufficio_1_off
         - delay:
            seconds: 5
         - service: homeassistant.update_entity
           target:
            entity_id: binary_sensor.clima_ufficio_1_ison



shell_command:
  clima_ufficio_1_on: 'curl -X POST "https://api.connectlife.io/api/v1/appliance" -H "accept: application/json" -H "Authorization: Bearer {{states("sensor.token_hisense_a")+states("sensor.token_hisense_b")}}" -H "Content-Type: application/json" -d "[{\"id\": \"PUT-HERE-THE-ID-OF-YOUR-DEVICE\",\"properties\": {\"Power\": \"1\"}}]"'
  clima_ufficio_1_off: 'curl -X POST "https://api.connectlife.io/api/v1/appliance" -H "accept: application/json" -H "Authorization: Bearer {{states("sensor.token_hisense_a")+states("sensor.token_hisense_b")}}" -H "Content-Type: application/json" -d "[{\"id\": \"PUT-HERE-THE-ID-OF-YOUR-DEVICE\",\"properties\": {\"Power\": \"0\"}}]"'
  clima_ufficio_1_settemp: 'curl -X POST "https://api.connectlife.io/api/v1/appliance" -H "accept: application/json" -H "Authorization: Bearer {{states("sensor.token_hisense_a")+states("sensor.token_hisense_b")}}" -H "Content-Type: application/json" -d "[{\"id\": \"PUT-HERE-THE-ID-OF-YOUR-DEVICE\",\"properties\": {\"SetTemperature\": \"{{states("input_number.clima_ufficio_1_temp")}}\"}}]"'
  clima_ufficio_1_setmode: 'curl -X POST "https://api.connectlife.io/api/v1/appliance" -H "accept: application/json" -H "Authorization: Bearer {{states("sensor.token_hisense_a")+states("sensor.token_hisense_b")}}" -H "Content-Type: application/json" -d "[{\"id\": \"PUT-HERE-THE-ID-OF-YOUR-DEVICE\",\"properties\": {\"Mode\": \"{{modalita}}\"}}]"'


automation:
- id: "clima_ufficio_1_settemp"         
  alias: Imposta temperatura clima ufficio 1
  trigger:
    platform: state
    entity_id: input_number.clima_ufficio_1_temp
  condition: []
  action:
   - service: shell_command.clima_ufficio_1_settemp


- id: "clima_ufficio_1_setmode"         
  alias: Imposta modalità clima ufficio 1
  trigger:
    platform: state
    entity_id: input_select.clima_ufficio_1_mode
  condition: []
  action:
  - if: "{{ states('input_select.clima_ufficio_1_mode') == 'Caldo' }}"
    then:
      - service: shell_command.clima_ufficio_1_setmode
        data:
          modalita: "1"
  - if: "{{ states('input_select.clima_ufficio_1_mode') == 'Freddo' }}"
    then:
      - service: shell_command.clima_ufficio_1_setmode
        data:
          modalita: "2"
  - if: "{{ states('input_select.clima_ufficio_1_mode') == 'Ventilazione' }}"
    then:
      - service: shell_command.clima_ufficio_1_setmode
        data:
          modalita: "0"   
  - if: "{{ states('input_select.clima_ufficio_1_mode') == 'Deumidificatore' }}"
    then:
      - service: shell_command.clima_ufficio_1_setmode
        data:
          modalita: "3" 
          
          

   

Sorry for the quick guide. In a second moment I try to be more detailed on the procedure.

If anyone knows how to use nodered flow to generate a new token from scratch, can do this guide complete.

2 Likes

Hello Paolo,
can you help me to set your solution? I’m newbie to nodered and i can’t figure how to proceed. If you want, write me a pm and i’ll give you my contact. Thanks!