본문 바로가기
IoT

SZMDLX IR Hub (하트모양 IR 허브) 타스모타 커펌기

by ㅋㅋ잠자 2020. 7. 5.
반응형

안녕하세요? 



https://blog.djjproject.com/648 - 투야 탭투런으로 자동화


로컬로 써보기 위해 하기 하트모양 IR 허브를 타스모타로 커펌을 하였습니다.


이어서, ESPHOME 바이너리를 생성해서 업데이트를 해보려고 했는데요..

(실은 ESPHOME 바이너리로 바로 직배송 해셔도 됩니다.)


타스모타 IR 기능 펌으로도 충분해서 여기에 남기로 하였습니다.


ESPHOME IR Library 가 상당히 괜찮게 구성이 되어 있었습니다.


그럼 시작합니다.





1. tuya-convert 실행


투야 컨버트를 해야겠다고 마음 먹은것이 에어컨 IR 자동화가 너무 귀찮아서 그렇고, 클라우드를 통하다 보니 조금 반응이 늦어지는 현상 때문에 하게 되었습니다.



물론 이 투야 컨버트도 다른 장비 없이 비링크 GTMINI 에서 바로 실행하였습니다.


와이파이가 있기 때문이죠.


일단 투야 컨버트 소스를 복구합니다.


root@aml:/opt# mkdir tuya-convert

root@aml:/opt# cd tuya-convert/

root@aml:/opt/tuya-convert# git clone https://github.com/ct-Open-Source/tuya-convert .

Cloning into '.'...

remote: Enumerating objects: 59, done.

remote: Counting objects: 100% (59/59), done.

remote: Compressing objects: 100% (46/46), done.

remote: Total 1333 (delta 28), reused 30 (delta 13), pack-reused 1274

Receiving objects: 100% (1333/1333), 3.54 MiB | 2.60 MiB/s, done.

Resolving deltas: 100% (827/827), done.

root@aml:/opt/tuya-convert# ls

config.txt  docker  Dockerfile  files  install_prereq.sh  LICENSE  README.md  scripts  start_flash.sh


의존성 패키지들을 설치합니다.


root@aml:/opt/tuya-convert# ./install_prereq.sh


다음으로 start_flash.sh 를 실행합니다. 


이때 와이파이 이름이 wlan0 여야 합니다. 이름이 특이하시면 udev 설정을 바꾸시거나 하여 이름을 맞춰주시길 바랍니다.


root@aml:/opt/tuya-convert# ./start_flash.sh 

tuya-convert v2.4.4

======================================================

TUYA-CONVERT


https://github.com/ct-Open-Source/tuya-convert

TUYA-CONVERT was developed by Michael Steigerwald from the IT security company VTRUST (https://www.vtrust.de/) in collaboration with the techjournalists Merlin Schumacher, Pina Merkert, Andrijan Moecker and Jan Mahn at c't Magazine. (https://www.ct.de/)



======================================================

PLEASE READ THIS CAREFULLY!

======================================================

TUYA-CONVERT creates a fake update server environment for ESP8266/85 based tuya devices. It enables you to backup your devices firmware and upload an alternative one (e.g. ESPEasy, Tasmota, Espurna) without the need to open the device and solder a serial connection (OTA, Over-the-air).

Please make sure that you understand the consequences of flashing an alternative firmware, since you might lose functionality!


Flashing an alternative firmware can cause unexpected device behavior and/or render the device unusable. Be aware that you do use this software at YOUR OWN RISK! Please acknowledge that VTRUST and c't Magazine (or Heise Medien GmbH & Co. KG) CAN NOT be held accountable for ANY DAMAGE or LOSS OF FUNCTIONALITY by typing yes + Enter


웹서버 포트 및 mqtt 서버를 죽여야 된다고 합니다.


root@aml:/opt/tuya-convert# ./start_flash.sh 

tuya-convert v2.4.4

Checking for network interface wlan0... Found.

Checking UDP port 53... Available.

Checking UDP port 67... Available.

Checking TCP port 80... Occupied by apache2 with PID 5178.

Port 80 is needed to answer HTTP requests

Do you wish to terminate apache2? [y/N] y

Attempting to stop apache2.service


Checking TCP port 443... Available.

Checking UDP port 6666... Available.

Checking UDP port 6667... Available.

Checking TCP port 1883... Occupied by mosquitto with PID 1963.

Port 1883 is needed to run MQTT

Do you wish to terminate mosquitto? [y/N] 

Aborting due to occupied port

======================================================

Cleaning up...

No screen session found.

No screen session found.

No screen session found.

No screen session found.

Closing AP

Exiting...


root@aml:/opt/tuya-convert# ./start_flash.sh 

tuya-convert v2.4.4

Checking for network interface wlan0... Found.

Checking UDP port 53... Available.

Checking UDP port 67... Available.

Checking TCP port 80... Available.

Checking TCP port 443... Available.

Checking UDP port 6666... Available.

Checking UDP port 6667... Available.

Checking TCP port 1883... Occupied by mosquitto with PID 1963.

Port 1883 is needed to run MQTT

Do you wish to terminate mosquitto? [y/N] y

Attempting to stop mosquitto.service

Checking TCP port 8886... Available.

======================================================

  Starting AP in a screen...

  Starting web server in a screen

  Starting Mosquitto in a screen

  Starting PSK frontend in a screen

  Starting Tuya Discovery in a screen


======================================================


IMPORTANT

1. Connect any other device (a smartphone or something) to the WIFI vtrust-flash

   This step is IMPORTANT otherwise the smartconfig may not work!

2. Put your IoT device in autoconfig/smartconfig/pairing mode (LED will blink fast). This is usually done by pressing and holding the primary button of the device

   Make sure nothing else is plugged into your IoT device while attempting to flash.

3. Press ENTER to continue


중간에 보면 장치를 페어링모드로 만들고

휴대폰 같은 장치고 vtrust-flash 에 연결하라고 합니다. 저는 연결하지 않고 했는데도 플래슁이 잘 되었습니다.



중간에 오리지널 펌웨어 백업에 실패했다고 나옵니다.


하.. 이걸 잘 봤어야 했는데... 제가 되레 겁을 먹고 본래 투야 펌웨어로 돌리려다 벽돌이 되었습니다. ㅎㅎㅎ


..................

SmartConfig complete.

Auto retry in 1s. .....................................

IoT-device is online with ip 10.42.42.42

Fetching firmware backup

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0 1024k    0  2920    0     0     32      0  9:06:08  0:01:30  9:04:38     0

curl: Saved to filename 'firmware-59b492.bin'

curl: (28) Operation timed out after 90000 milliseconds with 2920 out of 1048576 bytes received

Could not fetch a complete backup

Do you want to continue anyway? [y/N] y


======================================================

Getting Info from IoT-device

VTRUST-FLASH 1.5

(c) VTRUST GMBH https://www.vtrust.de/35c3/

READ FLASH: http://10.42.42.42/backup

ChipID: 59b492

MAC: BC:DD:C2:59:B4:92

BootVersion: 7

BootMode: normal

FlashMode: 1M QIO @ 40MHz

FlashChipId: 1540c8

FlashChipRealSize: 2048K

Active Userspace: user2 0x81000

======================================================

Ready to flash third party firmware!


For your convenience, the following firmware images are already included in this repository:

  Tasmota v8.1.0.2 (wifiman)

  ESPurna 1.13.5 (base)


You can also provide your own image by placing it in the /files directory

Please ensure the firmware fits the device and includes the bootloader

MAXIMUM SIZE IS 512KB


Available options:

  0) return to stock

  1) flash espurna.bin

  2) flash tasmota.bin

  q) quit; do nothing

Please select 0-2: 2

Are you sure you want to flash tasmota.bin? This is the point of no return [y/N] y

Attempting to flash tasmota.bin, this may take a few seconds...

Flashed http://10.42.42.1/files/tasmota.bin successfully in 16003ms, rebooting...

Look for a tasmota-xxxx SSID to which you can connect and configure

Be sure to configure your device for proper function!


HAVE FUN!

======================================================

Do you want to flash another device? [y/N] n

======================================================

Cleaning up...

Closing AP

Exiting...


플래슁이 되고 나면 와이파이에 tasmota-??? 가 올라옵니다.


연결하시고 192.168.4.1 로 이동하시면 


와이파이 정보를 입력하실 수 있습니다. AP1 에 기입하시고 저장하시면, 리부팅이 됩니다.




그리고 공유기에 아래처럼 올라오는 지 확인하고 다시 연결을 해봅니다.




이 이후 ESPHOME 으로 하시려면 esptool 을 pip 로 설치하시고 yaml 파일을 통해 바이너리를 생성하시어 펌웨어 업그레이드를 다시 해주시면 됩니다만, 일단 이 과정은 진행하지 않았습니다.


처음 보는 플랫폼이라 그렇고.. 제가 당시에 12시 30분에 설치를 해서.. 잠을 못잘것 같아서 본래 펌웨어로 돌리려고 했습니다.





2. ESPHOME 만들려다.. 원복과정에서 벽돌


결국에 겁이 나서 투야 백업 펌웨어로 돌리려고 했는데.. 왠걸.. 상기 중간 로그에 백업 에러가 났다는 걸 모르고 업데이트를 돌려 버렸습니다.


파일 용량이 3KB 로 되어 있었네요.. 못해도 400KB 가 넘어야 하는데..


하... 어쩔 수 없이 ESP8266 을 플래슁 하는 방법을 찾아야 했고.. 제가 이사를 하면서 장비를 모두 고향집으로 내리면서.. 인두기 와이어 등등을 찾았습니다.


시리얼 모듈도 없어서 라즈베리 GPIO 를 UART 로 설정해서 아래처럼 납땜하게 되었네요.



일단, Heart IR Hub 는 tywe3s 칩을 가지고 있고 ESP8266EX 칩을 가지고 있습니다.


핀 결선은 아래와 같습니다.



라즈베리파이의 GPIO UART 는 아래와 같습니다.



일단 사용을 하시려면, GPIO UART Console 을 OFF 하시고 UART 를 설정해주시면 됩니다. raspi-config 에서 가능합니다.


투야 칩셋 기준으로 3.3V / RX / TX 를 교차 연결해 주시고, GND 는 연결하지 않으셔도 됩니다. 플래슁 할때 손으로 붙여서 진행하는게 플래슁 툴에서 감지가 잘 되더라구요.


상기 투야 칩셋에서 GPIO0 와 윗 철판 두께 사이에 선을 가져다 대면, GND 와 GPIO0 에도 GND 가 걸리기 때문에 순간 감지가 잘 됩니다.



플래쉬 툴을 실행시키고 칩 철판과 GPIO0에 GND 를 가져다 대시길 바랍니다. 중간에 흔들리기라도 하면 MD5 체크썸 에러가 나니 잘 손대고 있어야 합니다.


그리고 애매한 5V 전력으로 라즈베리파이에 전력을 공급하면, 3.3V 전원이 순간 흔들리기 때문에 빵빵한 어댑터를 사용해 주시길 바랍니다.




타오투 참기름 받침대.. 오늘도 납과 열로 고생하네요..



집에 굴러다니는 와이어가 없어서, 랜선을 짤라서 납땜했는데... 이 선 자체가 납이 잘 달라붙는 재질이 아니여서 붙여놓는데 애를 많이 먹었네요 ㅠㅠ 


테프론 선이 있었다면 쉽게 했을 터인데 .... 그래서 토요일 일요일 넘어가는 밤을 꼴딱 샛습니다.


그 다음, 저는 하기의 글을 보고 web 으로 에어컨을 컨트롤 하려고 tasmota-ir 펌웨어를 설치했습니다. ESPHOME IR Library 가 들어가 있는 펌웨어 입니다.


https://cafe.naver.com/stsmarthome/21311 (이 자리를 빌려, 룰루해피님 감사합니다.)


타스모타 IR 펌웨어

https://github.com/arendst/Tasmota/releases


참고로 해당 기기는 512KB 가 넘어가도 플래슁이 잘 되기 때문에 gz 펌웨어를 안쓰셔도 됩니다.



그러고 라즈에 esptool 을 설치합니다. 타스모타이져도 있는데 Qt5 를 깔아야 해서 커맨드로만 진행하기 위해 esptool 을 설치했습니다.


pip3 install esptool 로 설치가 간단하게 됩니다.


esptool 의 경우, 공식 가이드에서는 0x1000 주소에 펌웨어를 설치하는데요. 부트로더를 제외한 주소이기 때문에 ... 상기 tasmota-ir.bin 파일은 부트로더와 elf 등의 프로그램을 모두 포함하고 있습니다.


그래서 주소를 0x00 으로 주셔서 처음부터 플래슁하셔야 정상 동작합니다.


root@raspberrypi:/home/pi# esptool.py --port /dev/ttyAMA0 write_flash -fm dout 0x0 tasmota-ir.bin

esptool.py v2.8

Serial port /dev/ttyAMA0

Connecting........__

Detecting chip type... ESP8266

Chip is ESP8266EX

Features: WiFi

Crystal is 26MHz

MAC: bc:dd:c2:59:b4:92

Uploading stub...

Running stub...

Stub running...

Configuring flash size...

Auto-detected Flash size: 2MB

Flash params set to 0x0330

Compressed 580240 bytes to 395694...

Wrote 580240 bytes (395694 compressed) at 0x00000000 in 36.1 seconds (effective 128.5 kbit/s)...

Hash of data verified.


Leaving...

Hard resetting via RTS pin...


GPIO0 / GND 처리가 잘 안되면 해쉬 데이터 체킹이 실패합니다. 손으로 잘 붙이시길 바랍니다.


(오히려 납땜해서 붙여두면, 감지가 잘 안되기 때문에 플래슁 툴을 실행하고 갖다 대 주는게 성공확률이 높네요.)





3. tasmota-ir.bin


타스모타 IR 펌웨어를 설치하였으면, 디바이스 설정을 YTF-IR 로 설정합니다.


핀맵이 비슷한지 잘 되네요.


참고로 ESP8266 은 느리기 때문에 WEBUI 가 잘 안돌아갑니다. 인내를 가지고 설정해 주세요.


컨피겨레이션 --> 컨피겨 모듈 --> YTF-IR 로 설정하시면 됩니다.


콘솔에서 하기 명령으로 커맨드를 보내보면 에어컨이 반응을 합니다.


IRhvac {"Vendor":"SAMSUNG_AC", "Power":"On","Mode":"Cool","FanSpeed":"1","Temp":28} 



그러면, 저 부분을 curl 로 긇어주기만 하면 HA 에서 연동하기는 매우 편할 것 같습니다.


물론 MQTT 로 처음에 세팅을 시도했지만, MQTT Payload 에 HA 변수를 넣는게 계속 적으로 에러가 나서 포기하게 되었습니다.



추가적으로 이 제품이 버튼을 누르면 불빛이 들어오는데 이 부분은 아직 찾지 못했습니다.


generic 으로 설정한다면 하기 설정이 됩니다.






4. HomeAssistant Shell Command 추가


일단 기본적으로 스위치를 키면 28도 냉방으로 되도록 쉘 커맨드와 스위치를 설정했습니다.


스위치의 현 상태 파악은 도어 센서로 합니다.


shell_command:

  tasmota_aircon_on: 'curl -G "http://192.168.0.64/cm" --data-urlencode "cmnd=IRhvac {"Vendor":"SAMSUNG_AC", "Power":"On","Mode":"Cool","FanSpeed":"Auto","Temp":28}"'

  tasmota_aircon_off: 'curl -G "http://192.168.0.64/cm" --data-urlencode "cmnd=IRhvac {"Vendor":"SAMSUNG_AC", "Power":"Off"}"'


그리고 상기 기반으로 스위치를 만듭니다.


- platform: template

  switches:

    airconditioner:

      value_template: '{{ is_state(''binary_sensor.0x00158d0003e74169_contact'',''on'')

        }}'

      turn_on:

        service: shell_command.tasmota_aircon_on

      turn_off:

        service: shell_command.tasmota_aircon_off

      icon_template: "{% if is_state('binary_sensor.0x00158d0003e74169_contact', 'on') %}\n\

        \  mdi:air-conditioner-on\n{% else %}\n  mdi:air-conditioner\n{% endif %}"





5. IR 에어컨 써모스탯


한편, 이것을 generic thermostat 으로 만들 경우, 특정 온도가 되면 계속 꺼졌다 켜졌다 하기 때문에...


그냥 원형 빠를 돌리면 값이 반영되게만 설정했습니다. 이유는 정속형이 아닌 인버터형 에어컨이기 때문입니다.


그리고 특히, 온도가 되었을 경우, 대기모드로 들어가면서 에어컨을 꺼버리기 때문에 스위치를 더미 스위치를 달아 주었습니다.


인풋 불린으로 연동한 더미 스위치 입니다.


- platform: template

  switches:

    air_thermo_temp_switch:

      value_template: "{{ is_state('binary_sensor.0x00158d0003e74169_contact','on') }}"

      turn_on:

        service: input_boolean.turn_on

        data:

          entity_id: input_boolean.air_state

      turn_off:

        service: input_boolean.turn_off

        data:

          entity_id: input_boolean.air_state


  - platform: generic_thermostat

    name: "Air_Conditioner"

    heater: switch.air_thermo_temp_switch

    target_sensor: sensor.0x00158d0003cd1d89_temperature

    ac_mode: True

    cold_tolerance: 0

    hot_tolerance: 1

    min_temp: 18

    max_temp: 30

    target_temp: 28

    initial_hvac_mode: "off"

    precision: 1

    away_temp: 30


그러면, 실제로는 에어컨을 켜거나 끌 때는, 제네릭 써모스탯의 밸류값으로 자동화에서 켜고 꺼주게 됩니다.


- id: '1592761882988'

  alias: thermo_aircon_turnon

  description: ''

  trigger:

  - entity_id: climate.air_conditioner

    platform: state

    to: cool

  condition: []

  action:

  - data: {}

    service: shell_command.tasmota_aircon_on

- id: 612c29343cf24eb0b304bbb56d40a816

  alias: thermo_aircon_turnoff

  description: ''

  trigger:

  - entity_id: climate.air_conditioner

    platform: state

    to: 'off'

  condition: []

  action:

  - data: {}

    service: shell_command.tasmota_aircon_off


실제로 제네릭써모스탯의 켜고 끄기는 작동이 되지 않는 것이지만, 자동화가 그것을 보고 껏다가 켰다가 해줍니다.


그 다음 온도조절을 반영하기 위해서 쉘 커맨드를 하나 만듭니다.


shell_command:

  tasmota_aircon_set: 'curl -G "http://192.168.0.64/cm" --data-urlencode "cmnd=IRhvac {"Vendor":"SAMSUNG_AC", "Power":"On","Mode":"Cool","FanSpeed":"Auto","Temp":{{temp}}}"'


쉘 커맨드를 실행할 때 온도 부분은 호출하는 곳에서 변수로 넣어둘 수 있도록 설정했습니다.


실제로는 MQTT 로 하려고 했으나 아무리 해봐도 payload 안에 변수를 집어넣을 수 없어서 어쩔 수 없이 이렇게 작업하게 되었습니다.


그럼 온도값 자동화는, 제네릭 써모스탯의 값을 받는 thermo_temperature_setted_value 인풋 넘버를 참조하여 하기 자동화로 구성됩니다.


이 자동화는 이전에 IR 을 씬으로 구축할 때 남아 있어서 약간 최적화가 덜 되었는데요. 그냥 제네릭 써모스탯의 상태가 바뀌면 써모스탯의 상태값을 가져와서 넣어줘도 될 것 같습니다.


- alias: thermo_aircon_temp_set

  description: ''

  trigger:

  - entity_id: sensor.thermo_temperature_setted_value

    platform: state

  condition:

  - condition: and

    conditions:

    - condition: state

      entity_id: binary_sensor.0x00158d0003e74169_contact

      state: 'on'

  action:

  - service: shell_command.tasmota_aircon_set

    data_template:

      temp: '{{ states("sensor.thermo_temperature_setted_value") }}'


그러면, 하기의 러브레이스로 간단한 에어컨 컨트롤이 가능합니다.



제네릭은 이게 한계인 것인지 에어컨 / 전원 버튼 밖에 생성이 되지 않는데요.. 음.. 제습이나 송풍을 추가하고 싶은데


어떻게 해야할지 모르겠습니다.




차후 MQTT 와 연동한다면, 에어컨 리모컨에서 이리저리 돌린 값을 IR 학습으로 리턴받아서 온도 값 설정이 가능할 것으로 보입니다만, 일단 여기서 마치겠습니다.


감사합니다.

반응형

댓글