找回密码
 立即注册
查看: 80|回复: 0

[基础教程] X12 esphome固件,led灯可开关,基本完美

[复制链接]

3

主题

102

回帖

1230

积分

金牌会员

积分
1230
金钱
1125
HASS币
0
发表于 8 小时前 | 显示全部楼层 |阅读模式
站在各位大佬的肩膀上整合修改了下代码,有需要的自取。因为好像8266的原因,不能像esp32那样自动以mac生成实体名称,对于有多个X12的,请将esphome: name: 修改成不同的名称。本人esphome 2025.2.2编译通过,本人的格力空调控制无问题,有问题的请使用大佬的SmartAC集成smartac for ha 2025.1.0 - 『HomeAssistant』综合讨论区 - 『瀚思彼岸』» 智能家居技术论坛 - Powered by Discuz!。

esphome:
  name: x12

esp8266:
  board: esp01_1m

# Enable logging
logger:
  level: debug
    
ota:
  platform: esphome
  password: !secret ota_password

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

  ap:
    ssid: "X12 Fallback Hotspot"
    password: !secret fallwifi_pswd

captive_portal:

web_server:
    port: 80

api:
  encryption:
  password: !secret api_password
  services:
    - service: send_raw_command
      variables:
        command: int[]
      then:
        - remote_transmitter.transmit_raw:
            code: !lambda 'return command;'
            carrier_frequency: 38kHz
    - service: send_nec_command
      variables:
        address: int
        command: int
      then:
        - remote_transmitter.transmit_nec:
            address: !lambda 'return address;'
            command: !lambda 'return command;'
    - service: send_pronto_command
      variables:
        command: string
      then:
        - remote_transmitter.transmit_pronto:
            data: !lambda 'return command;'

remote_transmitter:
  pin: GPIO14
  carrier_duty_percent: 50%

remote_receiver:
  id: rcvr
  dump: all
  pin:
    number: GPIO13
    inverted: true
    mode:
      input: true
      pullup: true
  tolerance: 50%

climate:
  - platform: heatpumpir
    protocol: greeyan
    horizontal_default: auto
    vertical_default: auto
    max_temperature: 30.0
    min_temperature: 16.0
    name: climate AC
    receiver_id: rcvr

binary_sensor:
  - platform: template
    name: "Power status"
    id: power_status
    device_class: power

sensor:
  - platform: hlw8012
    model: BL0937
    sel_pin: 
      number: GPIO12
      inverted: true
    cf_pin: GPIO4
    cf1_pin: GPIO5
    current_resistor: 0.001
    voltage_divider: 1711
    current:
      name: "Current"
    voltage:
      name: "Voltage"
    power:
      id: my_power
      filters:
        - multiply: 0.001
      unit_of_measurement: kW
      name: "Power"
      on_value:
        then:
          - lambda: |-
              if(x > 0.003){  
                id(power_status).publish_state(true);
              }else{
                id(power_status).publish_state(false);
              }
    energy:
      filters:
        - multiply: 0.001
      unit_of_measurement: kWh
      name: "Energy"
    update_interval: 10s

  - platform: total_daily_energy
    name: 'Total Daily Energy'
    power_id: my_power
    unit_of_measurement: 'kWh'
    state_class: total_increasing
    device_class: energy
    accuracy_decimals: 2
    filters:
      - multiply: 0.001
time:
  - platform: homeassistant
    id: homeassistant_time

text_sensor:
  - platform: wifi_info
    ip_address:
      name: IP Address
    ssid:
      name: Connected SSID
    mac_address:
      name: Mac Address

output:
  - platform: gpio
    pin: GPIO15
    id: led_output

light:
  - platform: binary
    name: "Led status"
    output: led_output
    restore_mode: ALWAYS_OFF  # 断电后默认关闭


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian ( 晋ICP备17001384号-1 )

GMT+8, 2025-6-9 19:29 , Processed in 0.078299 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表