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 hour316
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

m5stickc_ir.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)
substitutions:
  devicename: m5stickc_ir
  upper_devicename: M5StickC IR Remote

esphome:
  name: $devicename
  platform: ESP32
  board: m5stick-c

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
  ap:
    ssid: $devicename Fallback Hotspot
    password: !secret wifi_password

captive_portal:

logger:

api:

ota:

web_server:

binary_sensor:

  - platform: gpio
    pin:
      number: GPIO37
      inverted: true
    name: ${upper_devicename} Button A
    on_press:
      then:
        - switch.turn_on: led1
    on_release:
      then:
        - switch.turn_off: led1
        
  - platform: gpio
    pin:
      number: GPIO39
      inverted: true
    name: ${upper_devicename} Button B
    on_press:
      then:
        - switch.turn_on: led1
    on_release:
      then:
        - switch.turn_off: led1

sensor:
  - platform: wifi_signal
    name: ${upper_devicename} WiFi Signal
  - platform: uptime
    name: ${upper_devicename} Uptime

switch:

  - platform: restart
    name: ${upper_devicename} Restart

  - platform: gpio
    pin:
      number: GPIO10
      inverted: true
    name: ${upper_devicename} Led
    id: led1

  - platform: template
    name: ${upper_devicename} LG TV Power On
    turn_on_action:
      - remote_transmitter.transmit_lg:
          data: 0x20DF23DC              # = 551494620
          nbits: 32
          transmitter_id: internal

mqtt:
  broker: 192.168.1.200
  discovery: false
  on_json_message:
    topic: ${devicename}/transmit_lg        # Examples of json payload : { "data": 551494620, "nbits": 32 }
    then:                                   #                            { "data": 551494620 }
      - remote_transmitter.transmit_lg:
          transmitter_id: internal
          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;

# 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: internal

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 called 1001.json under the custom component directory
{
    "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\": 551538225 }",
        "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 IR
    device_code: 1001
    controller_data: m5stickc_ir/transmit_lg

Credits

Alessandro Polselli

Alessandro Polselli

1 project • 1 follower

Comments

Add projectSign up / Login