Archive for the ‘Home Assistant’ Category

0254 | ต่อ Sofar Inverter HYD 6000-EP เข้า Home Assistant

Saturday, November 12th, 2022 Posted in Home Assistant | No Comments »

วิธีนี้สำหรับ Sofar Inverter ที่ตัว logger มี serial ขึ้นต้นด้วย 23xxxxxxxx นะครับ

[แก้ไข]

สิ่งที่ต้องมีก่อน

  • home assistant
  • mqtt broker (ใช้ public หรือ private ก็ได้ตามสะดวก)
  • linux x86 ซักเครื่องที่เชื่อมต่อไปหา inverter wifi interface ได้ (ใช้บน raspberry pi/arm ไม่ได้เนื่องจากคนเขียนเค้าบอกว่าเขียนรีบๆ มาใช้เอง)
  • โปรแกรม fetch data => load ได้จาก XtheOne/Inverter-Data-Logger issue #37 ดู link sofar-export.zip
  • docker compose

ขั้นตอน

  • แตกไฟล์ sofar-export.zip แล้วเข้าไปใน folder ที่เก็บไฟล์
  • แก้ไฟล์ Dockerfile เป็นตามนี้
FROM golang:1.19-bullseye

ADD . /src

RUN apt update && apt install -y ca-certificates tzdata && \
  cd /src && go build && cp -av /src/sofar /

CMD ["/sofar"]
  • สร้างไฟล์ docker-compose.yml ตามด้านล่าง ใน folder เดียวกัน แก้ค่าสามจุดตามนี้
    • 23xxxxxxxx เป็นเลข serial ที่โชว์ในหน้าเว็บที่เข้าไปดู inverter (login user admin/admin)
    • แก้ค่า tcp://user:pass@mqttserverip:mqttport ตาม mqtt broker ที่ใช้
    • แก้ sofarinverterip เป็นเลข IP ของตัว inverter
services:
  sofar-export:
    image: sofar-export
    build: ./
    restart: unless-stopped
    command: /sofar -logger-serial 23xxxxxxxx -mqtt-url tcp://user:pass@mqttserverip:mqttport -port sofarinverterip:8899
  • เสร็จแล้วสั่ง start docker service ขึ้นมา
docker compose up -d
  • แล้วไปเซ็ต mqtt sensor ใน home assistant (ใส่ใน configuration.yaml) ประมาณนี้ *** parameter ยังไม่ได้ทดสอบ แก้ไขเองตามสะดวก ***
mqtt:
  sensor:
    - name: inverter_Frequency_Grid
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.Frequency_Grid / 100 }}"
      unit_of_measurement: "Hz"
      state_class: "measurement"
      device_class: "frequency"
    - name: inverter_PV_Generation_Today
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.PV_Generation_Today * 10}}"
      unit_of_measurement: "Wh"
      state_class: "measurement"
      device_class: "energy"
    - name: inverter_PV_Generation_Total
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.PV_Generation_Total * 100}}"
      unit_of_measurement: "Wh"
      state_class: "measurement"
      device_class: "energy"
    - name: inverter_ActivePower_Load_Sys
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.ActivePower_Load_Sys * 10}}"
      unit_of_measurement: "W"
      state_class: "measurement"
      device_class: "power"
    - name: inverter_ActivePower_PV_Ext
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.ActivePower_PV_Ext * 10}}"
      unit_of_measurement: "W"
      state_class: "measurement"
      device_class: "power"
    - name: inverter_ActivePower_Output_R
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.ActivePower_Output_R * 10}}"
      unit_of_measurement: "W"
      state_class: "measurement"
      device_class: "power"
    - name: inverter_ActivePower_Output_Total
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.ActivePower_Output_Total * 10}}"
      unit_of_measurement: "W"
      state_class: "measurement"
      device_class: "power"
    - name: inverter_ActivePower_PCC_R
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.ActivePower_PCC_R * 10}}"
      unit_of_measurement: "W"
      state_class: "measurement"
      device_class: "power"
    - name: inverter_ActivePower_PCC_Total
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.ActivePower_PCC_Total * 10}}"
      unit_of_measurement: "W"
      state_class: "measurement"
      device_class: "power"
    - name: inverter_Voltage_Phase_R
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.Voltage_Phase_R / 10}}"
      unit_of_measurement: "V"
      state_class: "measurement"
      device_class: "voltage"
    - name: inverter_Voltage_PV1
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.Voltage_PV1 / 10}}"
      unit_of_measurement: "V"
      state_class: "measurement"
      device_class: "voltage"
    - name: inverter_Voltage_PV2
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.Voltage_PV2 / 10}}"
      unit_of_measurement: "V"
      state_class: "measurement"
      device_class: "voltage"
    - name: inverter_Current_PV1
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.Current_PV1 / 100 }}"
      unit_of_measurement: "A"
      state_class: "measurement"
      device_class: "current"
    - name: inverter_Current_PV2
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.Current_PV2 / 100}}"
      unit_of_measurement: "A"
      state_class: "measurement"
      device_class: "current"
    - name: inverter_Current_Output_R
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.Current_Output_R / 100 }}"
      unit_of_measurement: "A"
      state_class: "measurement"
      device_class: "current"
    - name: inverter_Temperature_Env1
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.Temperature_Env1 }}"
      unit_of_measurement: "C"
      state_class: "measurement"
      device_class: "temperature"
    - name: inverter_Temperature_HeatSink1
      state_topic: "/sensors/energy/inverter2/All"
      value_template: "{{ value_json.HeatSink1 }}"
      unit_of_measurement: "C"
      state_class: "measurement"
      device_class: "temperature"