Alessandro Polselli
Published © GPL3+

Turn M5StickC Into Universal IR Remote (Home Automation)

Take a $9 M5StickC, few lines of YAML configuration to build ESPHome, Home Assistant and start controlling your TVs and climates in minutes.

IntermediateFull instructions provided1 hour21,920
Turn M5StickC Into Universal IR Remote (Home Automation)

Things used in this project

Hardware components

M5StickC ESP32-PICO Mini IoT Development Board
M5Stack M5StickC ESP32-PICO Mini IoT Development Board
×1

Software apps and online services

Home Assistant
Home Assistant
ESPHome

Story

Read more

Schematics

M5StickC schematics

All schematics:
http://m5edu.com/Product/m5stick-c-micro-core/

Code

m5stick-lg.yaml to build esphome

YAML
This is the configuration yaml file used to build the esphome firmware for m5stickc with internal IR transmitter (it supports also an optional external grove IR transmitter and receiver)
esphome:
  name: m5stick-lg
  friendly_name: M5Stick-C LG

esp32:
  board: m5stick-c

logger:

ota:
  platform: esphome

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

sensor:
  - platform: wifi_signal
    name: WiFi Signal
  - platform: uptime
    name: Uptime

button:
  - platform: restart
    name: Restart

web_server:

mqtt:
  broker: !secret mqtt_broker
  username: !secret mqtt_username
  password: !secret mqtt_password
  discovery_unique_id_generator: mac
  on_json_message:
    topic: m5stick-lg/transmit_lg        # Examples of json payload : { "data": 551494620, "nbits": 32 }
    then:                                #                            { "data": 551494620 }
      - remote_transmitter.transmit_lg:
          data: !lambda |-
            uint32_t data = 0;
            if (x.containsKey("data"))
              data = x["data"];
            return data;
          nbits: !lambda |-
            uint8_t nbits = 32;
            if (x.containsKey("nbits"))
              nbits = x["nbits"];
            return nbits;

#api:

i2c:
  - id: bus_a
    # Internal/system i2c bus
    sda: GPIO21
    scl: GPIO22
  - id: bus_b 
    # external/second i2c bus
    sda: GPIO0
    scl: GPIO26

spi:
  clk_pin: GPIO13
  mosi_pin: GPIO15

output:
  - platform: ledc
    id: builtin_led
    pin: 10
    inverted: true

light:
  - platform: monochromatic
    id: led1
    output: builtin_led
    name: Led

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO37
      inverted: true
    name: Button A
    on_press:
      then:
        - light.turn_on: led1
        - remote_transmitter.transmit_lg:
            data: 0x20DF10EF # power on/off
            nbits: 32
    on_release:
      then:
        - light.turn_off: led1

# Grove IR Receiver
#remote_receiver:
#  pin:
#    number: GPIO33
#    inverted: true
#  dump: all

# Grove IR Transmitter
remote_transmitter:
#  - pin:
#      number: GPIO32
#    carrier_duty_percent: 50%
#    id: grove
# M5StickC internal IR Transmitter
  - pin:
      number: GPIO9
    carrier_duty_percent: 50%
    id: ir1

json file with IR codes for my LG TV

JSON
This is the JSON file with the IR codes that I use to configure the SmartIR component of Home Assistant to control my LG TV OLED55B6V. It is stored in a file custom_components/smartir/codes/media_player/3000.json
{
    "manufacturer": "LG",
    "supportedModels": [
      "OLED55B6V via transmit_lg"
    ],
    "supportedController": "MQTT",
    "commandsEncoding": "Raw",
    "commands": {
        "off": "{\"data\": 551527260 }",
        "on": "{\"data\": 551494620 }",
        "previousChannel": "{\"data\": 551518335 }",
        "nextChannel": "{\"data\": 551485695 }",
        "volumeDown": "{\"data\": 551534655 }",
        "volumeUp": "{\"data\": 551502015 }",
        "mute": "{\"data\": 551522415 }",
        "sources": {
            "Channel 1": "{\"data\": 551520375 }",
            "Channel 2": "{\"data\": 551504055 }",
            "Channel 3": "{\"data\": 551536695 }",
            "Channel 4": "{\"data\": 551495895 }",
            "Channel 5": "{\"data\": 551528535 }",
            "Channel 6": "{\"data\": 551512215 }",
            "Channel 7": "{\"data\": 551544855 }",
            "Channel 8": "{\"data\": 551491815 }",
            "Channel 9": "{\"data\": 551524455 }",
            "Channel 0": "{\"data\": 551487735 }"
        }
    }
}

Home Assistant configuration.yaml snippet

YAML
This is the Home Assistant configuration.yaml config snippet
# This is the configuration.yaml part
smartir:

media_player:
  - platform: smartir
    name: LG TV via M5StickC LG
    unique_id: lg_tv_mqtt
    device_code: 3000
    controller_data: m5stick-lg/transmit_lg

Credits

Alessandro Polselli
3 projects • 17 followers
Contact

Comments

Please log in or sign up to comment.