『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
楼主: zjmhlxp

[求助] 求教三木大大 的DC1 MQTT编译配置文件写法?

[复制链接]

9

主题

171

帖子

868

积分

论坛积极会员

积分
868
金钱
697
HASS币
0
 楼主| 发表于 2019-6-4 16:02:23 | 显示全部楼层
netsnake 发表于 2019-6-4 15:42
如果还不清楚,你可以将mqtt相关信息和wifi相关信息发我,给你编一个固件试试,这些参数会加入固件的,es ...

你可以把wifi和MQTT信息备注下,发我下吗?我有8个DC1要刷,我好改下自己编译刷。
回复

使用道具 举报

5

主题

322

帖子

1345

积分

金牌会员

Rank: 6Rank: 6

积分
1345
金钱
1023
HASS币
0
发表于 2019-6-4 16:12:12 | 显示全部楼层
基本这样的:
esphome:
  name: $device_name
  platform: ESP8266
  board: $board_model
  #状态恢复保持
  esp8266_restore_from_flash: yes
#--------------指定esphome_core来源------------------
  esphome_core_version:
    #指定本地来源
    #local: path/to/esphome-core
    #指定外部来源
    repository: [url]https://github.com/Samuel-0-0/esphome-core.git[/url]
    #指定分支
    branch: dc1
#----------------------------------------------------
  #指定编译临时文件存放位置
  build_path: build\$device_name
  #指定arduino版本
  arduino_version: 2.5.0
#-----------------platform相关设置-------------------
  platformio_options:
    #指定platform-espressif8266来源
    platform: [url]https://github.com/Samuel-0-0/platform-espressif8266.git#dc1[/url]
#----------------------------------------------------

#--------------------- 只需要改这下面的内容 ---------------------
substitutions:
  #WiFi芯片版本,型号中带B的为csm64f02_b,不带B的为csm64f02
  board_model: csm64f02
  #设备名称(多个dc1改成不一样的)
  device_name: phicomm_dc1
  #WiFi_SSID名称
  wifi_ssid: '??????'
  #WiFi密码
  wifi_password: '??????'
  #如果SSID是隐藏的,设置为true
  wifi_fast_connect: 'false'
  #WiFi离线多久后重启设备,秒s/分钟min/小时h,不需要此功能设置为0s
  wifi_reboot_timeout: 600s
  #OTA密码
  ota_password: '??????'
  #与客户端(如Home Assistant)失去连接多久后重启设备,秒s/分钟min/小时h,不需要此功能设置为0s
  api_reboot_timeout: 600s
  #电量统计的数据更新时间,秒s/分钟min/小时h
  cse7766_update_interval: 1s
#--------------------- 只需要改这上面的内容 ---------------------
# mqtt功能
mqtt:
  broker: ?????? # mqtt服务器ip/域名
  username: ?????? # 账号
  password: ?????? # 密码
  #-------------------------------#
  birth_message: # 连接通知,设备发起
    topic: phicomm_dc1/state # 默认{TOPIC_PREFIX}/status
    payload: online # 默认通知online状态
  will_message: # 离线通知,由mqtt服务器发起
    topic: phicomm_dc1/state # 默认{TOPIC_PREFIX}/status
    payload: offline # 默认通知offline状态
  # 如果不设置,默认就是如上配置;如果birth_message、will_message的topic为空或不一样,则不生效。
  #-------------------------------#
  topic_prefix: phicomm_dc1 # 不设置默认{NodeName}
  discovery: True # 发现标记设置(全局)
  discovery_prefix: homeassistant # 配置数据topic,默认homeassistant,要与Home Assistant的mqtt组件设置保持一直(默认也是homeassistant)

##############################################################
wifi:
  ssid: $wifi_ssid
  password: $wifi_password
#----------需要设置静态地址的改下面的配置------------
#  manual_ip:
#    static_ip: 192.168.178.230
#    gateway: 192.168.178.1
#    subnet: 255.255.255.0
#    dns1: 1.1.1.1
#    dns2: 1.2.2.1
#----------------------------------------------------
  domain: .local
  reboot_timeout: $wifi_reboot_timeout
  power_save_mode: none
  fast_connect: $wifi_fast_connect

#---------不使用api与设备连接的话删除api配置---------
#api:
#  reboot_timeout: $api_reboot_timeout
#----------------------------------------------------

ota:
  safe_mode: true
  password: $ota_password
#  port: 3286

#----------------------WEB后台----------------------
#web_server:
#  port: 80
#  css_url: [url]https://esphome.io/_static/webserver-v1.min.css[/url]
#  js_url: [url]https://esphome.io/_static/webserver-v1.min.js[/url]
#----------------------------------------------------

#----------------------深度睡眠----------------------
#deep_sleep:
#  run_duration: 20s
#  sleep_duration: 50s
#----------------------------------------------------

i2c:
  sda: GPIO3
  scl: GPIO12
  scan: false
  frequency: 20kHz

cat9554:
  - id: cat9554_hub
    address: 0x20
    irq: GPIO4

uart:
  rx_pin: GPIO13
  baud_rate: 4800

#debug:

logger:
#  hardware_uart: UART1
#  level: DEBUG
  level: info

sensor:
  - platform: cse7766
    voltage:
      name: "${device_name} voltage"
    current:
      name: "${device_name} current"
    power:
      name: "${device_name} power"
    update_interval: $cse7766_update_interval
  - platform: uptime
    name: "${device_name} uptime"
  - platform: wifi_signal
    name: "${device_name} wifi_signal"

binary_sensor:
  - platform: status
    #设备状态
    name: "${device_name} status"
    #是否对外隐藏(true/false)
    internal: false
  - platform: gpio
    #第一个按钮(内部引用,对外隐藏)
    name: "${device_name} key1"
    #是否对外隐藏(true/false)
    internal: true
    pin:
      cat9554: cat9554_hub
      # Use pin number 0
      number: 0
      mode: INPUT
    filters:
      - invert:
      - delayed_on: 40ms
      - delayed_off: 40ms
    on_click:
      - min_length: 50ms
        max_length: 350ms
        then:
          - switch.toggle: switch1
  - platform: gpio
    #第二个按钮(内部引用,对外隐藏)
    name: "${device_name} key2"
    #是否对外隐藏(true/false)
    internal: true
    pin:
      cat9554: cat9554_hub
      # Use pin number 1
      number: 1
      mode: INPUT
    filters:
      - invert:
      - delayed_on: 40ms
      - delayed_off: 40ms
    on_click:
      - min_length: 50ms
        max_length: 350ms
        then:
          - switch.toggle: switch2
  - platform: gpio
    #第三个按钮(内部引用,对外隐藏)
    name: "${device_name} key3"
    #是否对外隐藏(true/false)
    internal: true
    pin:
      cat9554: cat9554_hub
      # Use pin number 2
      number: 2
      mode: INPUT
    filters:
      - invert:
      - delayed_on: 40ms
      - delayed_off: 40ms
    on_click:
      - min_length: 50ms
        max_length: 350ms
        then:
          - switch.toggle: switch3
  - platform: gpio
    #总开关(内部引用,对外隐藏)
    name: "${device_name} key0"
    #是否对外隐藏(true/false)
    id: key0
    internal: true
    pin:
      number: GPIO16
      mode: INPUT_PULLDOWN_16
    filters:
      - invert:
      - delayed_on: 40ms
      - delayed_off: 40ms
    on_click:
      - min_length: 50ms
        max_length: 350ms
        then:
          - switch.toggle: switch0
  #影子
  - platform: template
    name: "shadow1"
    id: shadow1
    internal: true
  - platform: template
    name: "shadow2"
    id: shadow2
    internal: true
  - platform: template
    name: "shadow3"
    id: shadow3
    internal: true
    
#WiFi状态灯
status_led:
  pin: GPIO0

text_sensor:
  - platform: template
    #配置文件版本
    name: "${device_name} config_version"
    lambda: |-
      return {"v2019.03.28.002"};
  - platform: version
    #esphome版本
    name: "${device_name} esphome_version"
    icon: mdi:information-outline
  - platform: wifi_info
    ip_address:
      name: "${device_name} IP Address"
    ssid:
      name: "${device_name} Connected SSID"
#    bssid:
#      name: "${device_name} Connected BSSID"

output:
  - platform: gpio
    #继电器3(内部引用,对外隐藏)
    id: realy3
    pin:
      cat9554: cat9554_hub
      # Use pin number 4
      number: 4
      mode: OUTPUT
      inverted: false
  - platform: gpio
    #继电器2(内部引用,对外隐藏)
    id: realy2
    pin:
      cat9554: cat9554_hub
      # Use pin number 5
      number: 5
      mode: OUTPUT
      inverted: false
  - platform: gpio
    #继电器1(内部引用,对外隐藏)
    id: realy1
    pin:
      cat9554: cat9554_hub
      # Use pin number 6
      number: 6
      mode: OUTPUT
      inverted: false
  - platform: gpio
    #总继电器(内部引用,对外隐藏)
    id: realy0
    pin:
      cat9554: cat9554_hub
      # Use pin number 7
      number: 7
      mode: OUTPUT
      inverted: false

switch:
  - platform: output
    #总开关(显示为一个开关)
    name: "${device_name} switch0"
    output: realy0
    id: switch0
    on_turn_on:
      - switch.turn_on: LOGO_light
      - lambda: |-
          if (id(shadow1).state) {
            id(switch1).turn_on();
            id(shadow1).publish_state(false);
          }
          if (id(shadow2).state) {
            id(switch2).turn_on();
            id(shadow2).publish_state(false);
          }
          if (id(shadow3).state) {
            id(switch3).turn_on();
            id(shadow3).publish_state(false);
          }
    on_turn_off:
      - switch.turn_off: LOGO_light
      - lambda: |-
          if (id(switch1).state) {
            id(switch1).turn_off();
            id(shadow1).publish_state(true);
          }
          if (id(switch2).state) {
            id(switch2).turn_off();
            id(shadow2).publish_state(true);
          }
          if (id(switch3).state) {
            id(switch3).turn_off();
            id(shadow3).publish_state(true);
          }
  - platform: output
    #开关1(显示为一个开关)
    name: "${device_name} switch1"
    output: realy1
    id: switch1
    on_turn_on:
      - lambda: |-
          if (!id(switch0).state) {
            id(switch0).turn_on();
          }
  - platform: output
    #开关2(显示为一个开关)
    name: "${device_name} switch2"
    output: realy2
    id: switch2
    on_turn_on:
      - lambda: |-
          if (!id(switch0).state) {
            id(switch0).turn_on();
          }
  - platform: output
    #开关3(显示为一个开关)
    name: "${device_name} switch3"
    output: realy3
    id: switch3
    on_turn_on:
      - lambda: |-
          if (!id(switch0).state) {
            id(switch0).turn_on();
          }
  - platform: gpio
    pin: GPIO14
    #LOGO灯
    name: "${device_name} LOGO_light"
    id: LOGO_light
    internal: false
    inverted: true

回复

使用道具 举报

9

主题

171

帖子

868

积分

论坛积极会员

积分
868
金钱
697
HASS币
0
 楼主| 发表于 2019-6-4 16:13:54 | 显示全部楼层
netsnake 发表于 2019-6-4 16:12
基本这样的:
[code]esphome:
  name: $device_name

感谢大神分享,马上刷了试试,另外DC1好像必须要5V单独供电,不然搞不定,对吧。
回复

使用道具 举报

5

主题

322

帖子

1345

积分

金牌会员

Rank: 6Rank: 6

积分
1345
金钱
1023
HASS币
0
发表于 2019-6-4 16:14:56 | 显示全部楼层
其中还有device_name 也应该改下,因为你有多个设备!
按700大侠说的,mqtt应该是如下:
# state_topic
phicomm_dc1/switch/phicomm_dc1_logo_light/state
# command_tpoic,payload设置ON/OFF进行打开/关闭操作
phicomm_dc1/switch/phicomm_dc1_logo_light/command
可以用上述topic测试下!

回复

使用道具 举报

9

主题

171

帖子

868

积分

论坛积极会员

积分
868
金钱
697
HASS币
0
 楼主| 发表于 2019-6-4 16:16:02 | 显示全部楼层
netsnake 发表于 2019-6-4 16:14
其中还有device_name 也应该改下,因为你有多个设备!
按700大侠说的,mqtt应该是如下:
# state_topic

非常感谢,我试试。其它我都看懂了,主要的YAML里开关内容写法没看懂
回复

使用道具 举报

5

主题

322

帖子

1345

积分

金牌会员

Rank: 6Rank: 6

积分
1345
金钱
1023
HASS币
0
发表于 2019-6-4 16:18:45 | 显示全部楼层
esphome里面light需要配合一个output才能控制,很奇怪!switch就直接可控制!
回复

使用道具 举报

9

主题

171

帖子

868

积分

论坛积极会员

积分
868
金钱
697
HASS币
0
 楼主| 发表于 2019-6-4 16:47:26 | 显示全部楼层
netsnake 发表于 2019-6-4 16:18
esphome里面light需要配合一个output才能控制,很奇怪!switch就直接可控制!

针脚的名字有什么将就?
回复

使用道具 举报

5

主题

322

帖子

1345

积分

金牌会员

Rank: 6Rank: 6

积分
1345
金钱
1023
HASS币
0
发表于 2019-6-4 16:49:36 | 显示全部楼层
那是设备内部的,和多个设备无关!可以不用改,但device_name必须不同,否则在mqtt的topic上就重复了
回复

使用道具 举报

9

主题

171

帖子

868

积分

论坛积极会员

积分
868
金钱
697
HASS币
0
 楼主| 发表于 2019-6-4 20:20:54 | 显示全部楼层
netsnake 发表于 2019-6-4 16:49
那是设备内部的,和多个设备无关!可以不用改,但device_name必须不同,否则在mqtt的topic上就重复了 ...

好的,多谢
回复

使用道具 举报

9

主题

171

帖子

868

积分

论坛积极会员

积分
868
金钱
697
HASS币
0
 楼主| 发表于 2019-6-4 20:25:15 | 显示全部楼层
本帖最后由 zjmhlxp 于 2019-6-4 20:27 编辑
netsnake 发表于 2019-6-4 16:49
那是设备内部的,和多个设备无关!可以不用改,但device_name必须不同,否则在mqtt的topic上就重复了 ...
# mqtt功能
mqtt:
  broker: 10.0.20.80
  username: mqtt
  password: mqtt
  #-------------------------------#
  birth_message: # 连接通知,设备发起
    topic: phicomm_dc1/state # 默认{TOPIC_PREFIX}/status
    payload: online # 默认通知online状态
  will_message: # 离线通知,由mqtt服务器发起
    topic: phicomm_dc1/state # 默认{TOPIC_PREFIX}/status
    payload: offline # 默认通知offline状态
  # 如果不设置,默认就是如上配置;如果birth_message、will_message的topic为空或不一样,则不生效。
  #-------------------------------#
  topic_prefix: phicomm_dc1 # 不设置默认{NodeName}
  discovery: True # 发现标记设置(全局)
  discovery_prefix: homeassistant # 配置数据topic,默认homeassistant,要与Home Assistant的mqtt组件设置保持一直(默认也是homeassistant)
 
##############################################################


这里的{TOPIC_PREFIX},默认是NodeName 的值是yaml,配置文件名吗?比如我编译的yaml名字为,phicomm_dc1_a,nodename就是phicomm_dc1_a,对吗?
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-19 22:41 , Processed in 0.057559 second(s), 29 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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