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

标题: 向日葵C1插座esphome插件 [打印本页]

作者: gl695133087    时间: 2022-3-23 20:20
标题: 向日葵C1插座esphome插件
本帖最后由 gl695133087 于 2022-3-23 20:36 编辑

     首先申明,我是一个小白、纯新手,这个帖子是在我前期学习esphome的基础和借鉴了坛内大神trz0332的分享贴《向日葵插座(esp8266)刷ESPHOME固件(完美版本)》(链接  https://bbs.hassbian.com/thread-15595-1-1.html)的基础上才得以成形的,在这里再次感谢大神的无私奉献。发帖的主要目的是让跟我一样的新手兄弟们少走弯路。

       C语言以前接触过,但忘得差不多了,因此只能走esphome这种不需要太多编程知识的路径。之前我自己把C1刷了esphome,但是我只是在esphome官网上学习到了switch和light两种配置的一些超简单的形式(esphome官网纯英文,可以用浏览器自带的网页翻译功能凑合着看),自己搞的固件只能开关和指示灯的功能,物理按键都刷废了,研究了几天也没搞出个所以然。直到今天在论坛看到trz0332大神的帖子,当然,配置我也没完全看懂,但是不影响我修改使用。


                               
登录/注册后可看大图



作者: gl695133087    时间: 2022-3-23 20:32

                               
登录/注册后可看大图

一、打开esphome管理界面,随便写增加一个设备,命名按照c语言的对变量的命名要求就行,随意取。


作者: gl695133087    时间: 2022-3-23 20:33


                               
登录/注册后可看大图

二、进去之后点edit进入编辑界面,代码“captive_portal:”及之前的内容都不用修改。在之后增加下面的代码:
  1. status_led:
  2. pin: GPIO16

  3. globals:
  4. - id: auto_gl
  5. type: int
  6. restore_value: yes
  7. initial_value: "1"


  8. binary_sensor:
  9. - platform: gpio
  10. pin:
  11. number: 13
  12. inverted: true
  13. name: "paicha_B1"
  14. device_class: motion
  15. id: "paicha_B1"
  16. on_click:
  17. - min_length: 50ms
  18. max_length: 1000ms
  19. then:
  20. - if:
  21. condition:
  22. lambda: 'return id(paicha_auto).state ;'
  23. then:
  24. - switch.toggle: "paicha_relay"
  25. - min_length: 5000ms
  26. max_length: 10000ms
  27. then:
  28. - switch.toggle: 'paicha_auto'



  29. light:
  30. - platform: binary
  31. output: light_output
  32. name: "blue_led"
  33. id: "paicha_blue_led"

  34. output:
  35. - id: light_output
  36. platform: gpio
  37. pin: GPIO12

  38. switch:
  39. - platform: gpio #继电器
  40. pin: GPIO14
  41. name: "relay"
  42. id: "paicha_relay"
  43. on_turn_on:
  44. then:
  45. - light.turn_on: "paicha_blue_led"
  46. on_turn_off:
  47. then:
  48. - light.turn_off: "paicha_blue_led"

  49. - platform: template
  50. name: "auto"
  51. id: "paicha_auto"
  52. turn_on_action:
  53. then:
  54. - lambda: |-
  55. id(auto_gl)=1;
  56. ESP_LOGD("main", "I am at execution number %d", id(auto_gl));
  57. turn_off_action:
  58. then:
  59. - lambda: |-
  60. id(auto_gl)=0;
  61. ESP_LOGD("main", "I am at execution number %d", id(auto_gl));
  62. lambda: |-
  63. return id(auto_gl);
复制代码



粘贴代码之后格式是不正确的,直接编译要报错,原因在于代码复制粘贴后对齐被改变了。需要自己手动把代码对齐一下,对齐的要求按照C语言对代码对齐的要求。不清楚的网上自己找下C语言教程,不需要学得太深,简单的了解变量命名规则和代码对齐规则就够用了。


现在功能就齐全了,再次申明,我基本上就是个搬运工,只是分享点折腾经验帮助新手兄弟们少走点弯路。

作者: huang7dede    时间: 2022-3-24 18:43
可惜,,我的是c2
作者: coli06    时间: 2022-9-24 15:32
本帖最后由 coli06 于 2022-9-24 20:20 编辑

感谢~~编译下载固件那边卡住了~~~============
后面换了个esphome版本的docker镜像,ok了





欢迎光临 『瀚思彼岸』» 智能家居技术论坛 (https://bbs.hassbian.com/) Powered by Discuz! X3.5