SmartIR icon indicating copy to clipboard operation
SmartIR copied to clipboard

ESP8266 IR (for AC control) not sending commands

Open rodsolmi opened this issue 2 years ago • 23 comments

Home Assistant version

Home Assistant Core 2022.6.4 Home Assistant Supervisor 2022.05.3 Home Assistant OS 8.1

SmartIR version

1.17.6

SmartIR configuration

smartir:

climate:
  - platform: smartir
    name: AC_despacho
    unique_id: myespir
    device_code: 1385
    controller_data: myespir_send_raw_command
    temperature_sensor: sensor.temperature
    humidity_sensor: sensor.humidity
    power_sensor: binary_sensor.ac_power

**On the ESP_HOME side of it:**

esphome:
  name: myespir
  platform: ESP8266
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "5XIXlxJhluG2wIIaB6vmZwet4ZEMXSo7Wd8b4WYj/3Y="
  services:
    - service: send_raw_command
      variables:
        command: int[]
      then:
        - remote_transmitter.transmit_raw:
            code: !lambda 'return command;'
  
remote_transmitter:
  pin: GPIO14
  carrier_duty_percent: 50%

ota:
  password: "9d0874ab74118ff49ccf150330bad424"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Myespir Fallback Hotspot"
    password: "y76BVR3x3wq3"


Describe the bug

I have purchased some ESP-01M (ESp8266) chipsets with built-in IR transmitter/receiver to control some ACs at home using HomeAssistant.

In the chipset you can read the IOs:

IO4: IR_TX IO14: IR_RX

And lucky for me, i found the exact controller for my current remote R11HG/E which corresponds to the id 1385. So far everything looked perfect.

I installed SmartIR using HACS (everything seems fine), and the chipset itself was integrated ("succesfully") via TTL directly on the raspberry that holds the HA. It connects to Wi-Fi and has a fixed IP. No issues so far.

Then I added the configuration.yaml part of it, keeping it as similar as the example, to avoid typos etc. I restarted HA, added the card for a thermostat, and it identified the entity without any issue.

I don't know what I'm missing, but the IR simply doesn't send anything, the connection with HA seems correct, but when I operate the thermostat the log shows no response, and obviously the AC won't respond either.

Debug log

This is the log read by ESP OTA, it just sits there doing nothing, even if I change continously the temperature/modes, etc...

INFO Reading configuration /config/esphome/pruebair.yaml... INFO Starting log output from myespir.local using esphome API INFO Successfully connected to myespir.local [13:34:10][I][app:102]: ESPHome version 2022.5.1 compiled on Jun 10 2022, 13:08:38 [13:34:10][C][wifi:491]: WiFi: [13:34:10][C][wifi:353]: Local MAC: 50:02:91:3C:3D:54 [13:34:10][C][wifi:354]: SSID: [redacted] [13:34:10][C][wifi:355]: IP Address: 192.168.0.110 [13:34:10][C][wifi:356]: BSSID: [redacted] [13:34:10][C][wifi:358]: Hostname: 'myespir' [13:34:10][C][wifi:360]: Signal strength: -25 dB ▂▄▆█ [13:34:10][C][wifi:364]: Channel: 6 [13:34:10][C][wifi:365]: Subnet: 255.255.255.0 [13:34:10][C][wifi:366]: Gateway: 192.168.0.1 [13:34:10][C][wifi:367]: DNS1: 192.168.0.1 [13:34:10][C][wifi:368]: DNS2: 192.168.0.1 [13:34:10][C][logger:274]: Logger: [13:34:10][C][logger:275]: Level: DEBUG [13:34:10][C][logger:276]: Log Baud Rate: 115200 [13:34:10][C][logger:277]: Hardware UART: UART0 [13:34:10][C][remote_transmitter:018]: Remote Transmitter... [13:34:10][C][remote_transmitter:019]: Carrier Duty: 50% [13:34:10][C][remote_transmitter:020]: Pin: GPIO14 [13:34:10][C][mdns:084]: mDNS: [13:34:10][C][mdns:085]: Hostname: myespir [13:34:10][C][ota:085]: Over-The-Air Updates: [13:34:10][C][ota:086]: Address: myespir.local:8266 [13:34:10][C][ota:089]: Using Password. [13:34:10][C][api:138]: API Server: [13:34:10][C][api:139]: Address: myespir.local:6053 [13:34:10][C][api:141]: Using noise encryption: YES

Additional context

I already have experience with HA, but I'm a complete noob when it comes to SmartIR and ESP_home "raw" programming.

Tried to understand what was going on, but i couldn't find anything.

rodsolmi avatar Jun 10 '22 11:06 rodsolmi

The SmartIR needs the supportedController in the codes json file to create the controller. So the IR codes configuration files cannot be generic currently. Mostly IR codes configuration files are the broadlink.

I'm developing the IR config format conversion function in order to let the config file support more controllers.

snowyu avatar Jun 24 '22 00:06 snowyu

So that means i cant use the 1385 json IR commands because I'm using and ESP 8266 chipset instead of a commercial broadlink emitter?

Is there any way to just translate that specific IR command library and call it from HA/ESP?

rodsolmi avatar Jun 24 '22 09:06 rodsolmi

I've just finished broadlink2lirc function to do so. but I found I have to change the way to create controller first.

snowyu avatar Jun 24 '22 09:06 snowyu

That'd be awesome.

Can you tag me whenever so that i try if that'd work?

El vie, 24 jun 2022 11:54, Riceball LEE @.***> escribió:

I've just finished broadlink2lirc function to do so. but I found I have to change the way to create controller first.

— Reply to this email directly, view it on GitHub https://github.com/smartHomeHub/SmartIR/issues/862#issuecomment-1165408499, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYNKIPB7JOHIFNBSPQ6R7PDVQWAUDANCNFSM5YNNAYFQ . You are receiving this because you authored the thread.Message ID: @.***>

rodsolmi avatar Jun 24 '22 11:06 rodsolmi

@rodsolmi now you can test it: https://github.com/snowyu/SmartIR/tree/refactor/reused-codes

snowyu avatar Jun 25 '22 09:06 snowyu

@rodsolmi now you can test it: https://github.com/snowyu/SmartIR/tree/refactor/reused-codes

Hey, just tried your branch, ESPHome didn't seem to work because you forgot to register it, I fixed it and did a pull request. It still doesn't work though.

Guy293 avatar Jun 25 '22 19:06 Guy293

you need add the new option "controller" to specify your controller in HA configuration. see the sensor's README.

snowyu avatar Jun 25 '22 22:06 snowyu

I've already added the new option.

Guy293 avatar Jun 25 '22 22:06 Guy293

@Guy293 What's the problem? more detail please.

snowyu avatar Jun 26 '22 01:06 snowyu

@Guy293 fixed a broadlink2lirc index error. You can try again now.

snowyu avatar Jun 26 '22 05:06 snowyu

To be honest guys, I'm a little lost of how should I try this. Is it when the function is called or when it is compiled?

meaning, is this change to be done on ESP or in the configuration.yaml file?

climate:

  • platform: smartir name: AC_despacho unique_id: myespir device_code: 1385 controller_data: myespir_send_raw_command //Is there a change to be done here? temperature_sensor: sensor.temperature humidity_sensor: sensor.humidity power_sensor: binary_sensor.ac_power

rodsolmi avatar Jun 29 '22 16:06 rodsolmi

@rodsolmi Just add the controller option in he configuration.yaml file:

- platform: smartir
  name: AC_despacho
  unique_id: myespir
  device_code: 1385
  controller: ESPHome  // <-- add here
  controller_data: myespir_send_raw_command 
  temperature_sensor: sensor.temperature
  humidity_sensor: sensor.humidity
  power_sensor: binary_sensor.ac_power

snowyu avatar Jun 30 '22 11:06 snowyu

@rodsolmi Just add the controller option in he configuration.yaml file:

- platform: smartir
  name: AC_despacho
  unique_id: myespir
  device_code: 1385
  controller: ESPHome  // <-- add here
  controller_data: myespir_send_raw_command 
  temperature_sensor: sensor.temperature
  humidity_sensor: sensor.humidity
  power_sensor: binary_sensor.ac_power

Adding that codeline "controller: ESPHome" results in an error in the configuration.yaml file....

The system cannot restart because the configuration is not valid: Invalid config for [climate.smartir]: [controller] is an invalid option for [climate.smartir]. Check: climate.smartir->controller. (See ?, line ?).

Funny enough, i can see the "controller.py" file in the smartir integration:

image

rodsolmi avatar Jul 03 '22 08:07 rodsolmi

  1. first you should use my branch instead of original one
    • the controller.py is removed and controllers folder added.
  2. then restart the HA core
  3. change the configuration.yaml at last

snowyu avatar Jul 03 '22 09:07 snowyu

I'm actually using your branch, i don't see any "controllers" folder:

image

and installed through HACS:

image

rodsolmi avatar Jul 03 '22 10:07 rodsolmi

this will install the master branch, not the refactor/reused-codes branch. you need to copy-paste files into custom-components/smartir.

All right, I've merge the refactor/reused-codes branch to the master branch. you can try it now.

snowyu avatar Jul 03 '22 11:07 snowyu

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 13 '22 10:08 stale[bot]

hey frindes i have esp32devkit1 and I do like you @snowyu said, and I get this error "my HA system is last version (on rpib4 )" "smartir last version"

error

Logger: custom_components.smartir.climate Source: custom_components/smartir/init.py:213 Integration: SmartIR (documentation) First occurred: 01:22:37 (3 occurrences) Last logged: 01:22:46

unpack requires a buffer of 2 bytes Traceback (most recent call last): File "/config/custom_components/smartir/climate.py", line 372, in send_command await self._controller.send( File "/config/custom_components/smartir/controllers/abstract_controller.py", line 67, in send await self._send(self.decode(command, data), data) File "/config/custom_components/smartir/controllers/abstract_controller.py", line 47, in decode ok, command = to_lirc(command, data) File "/config/custom_components/smartir/controllers/abstract_controller.py", line 19, in to_lirc return Controller.toLirc(command, data) File "/config/custom_components/smartir/controllers/broadlink_controller.py", line 31, in toLirc command = Helper.broadlink2lirc(command) File "/config/custom_components/smartir/init.py", line 213, in broadlink2lirc current = struct.unpack('>H', subview)[0] struct.error: unpack requires a buffer of 2 bytes

esphome logs

INFO Reading configuration /config/esphome/myespir.yaml... INFO Starting log output from myespir.local using esphome API INFO Successfully connected to myespir.local [01:40:53][I][app:102]: ESPHome version 2022.8.0 compiled on Aug 19 2022, 22:54:01 [01:40:53][C][wifi:491]: WiFi: [01:40:53][C][wifi:353]: Local MAC: C8:C9:A3:CF:99:18 [01:40:53][C][wifi:354]: SSID: [redacted] [01:40:53][C][wifi:355]: IP Address: 10.100.102.191 [01:40:53][C][wifi:357]: BSSID: [redacted] [01:40:53][C][wifi:358]: Hostname: 'myespir' [01:40:53][C][wifi:360]: Signal strength: -63 dB ▂▄▆█ [01:40:53][C][wifi:364]: Channel: 8 [01:40:53][C][wifi:365]: Subnet: 255.255.255.0 [01:40:53][C][wifi:366]: Gateway: 10.100.102.1 [01:40:53][C][wifi:367]: DNS1: 10.100.102.108 [01:40:53][C][wifi:368]: DNS2: 1.1.1.1 [01:40:53][C][logger:275]: Logger: [01:40:53][C][logger:276]: Level: DEBUG [01:40:53][C][logger:277]: Log Baud Rate: 115200 [01:40:53][C][logger:278]: Hardware UART: UART0 [01:40:53][C][remote_transmitter:015]: Remote Transmitter... [01:40:53][C][remote_transmitter:016]: Channel: 0 [01:40:53][C][remote_transmitter:017]: RMT memory blocks: 1 [01:40:53][C][remote_transmitter:018]: Clock divider: 80 [01:40:53][C][remote_transmitter:019]: Pin: GPIO14 [01:40:53][C][remote_transmitter:022]: Carrier Duty: 50% [01:40:53][C][captive_portal:088]: Captive Portal: [01:40:53][C][mdns:094]: mDNS: [01:40:53][C][mdns:095]: Hostname: myespir [01:40:53][C][ota:085]: Over-The-Air Updates: [01:40:53][C][ota:086]: Address: myespir.local:3232 [01:40:53][C][ota:089]: Using Password. [01:40:53][C][api:138]: API Server: [01:40:53][C][api:139]: Address: myespir.local:6053 [01:40:53][C][api:141]: Using noise encryption: YES

pls help I am newbie :)

Ei187 avatar Aug 19 '22 22:08 Ei187

@Ei187 It seems that broadlink data can not be converted.

snowyu avatar Aug 20 '22 10:08 snowyu

@snowyu Can you fix it my friend or tell me how pls? Thx about all the help ❤️

Ei187 avatar Aug 20 '22 13:08 Ei187

You should show your broadlink data first.

snowyu avatar Aug 20 '22 13:08 snowyu

@snowyu how i do it, can you tell me, i will upload all you want and all you need just say my friend . your a god man thx about all

Ei187 avatar Aug 20 '22 14:08 Ei187

@snowyu ?

Ei187 avatar Aug 21 '22 20:08 Ei187