syssi / esphome-jnge-mppt-controller

ESPHome component to monitor and control a JN-MPPT or JN-W/S Controller via RS485
Apache License 2.0
14 stars 5 forks source link

JN-MPPT-AL Buck Solar Charge Controller #30

Closed MasterCATZ closed 2 years ago

MasterCATZ commented 2 years ago

I have 30A chargers , I did buy them with wifi modules but could never get them to work

I also can not seem to get this to work either

most data I get is

[12:21:53][D][sensor:124]: 'jn-mppt status operation mode id': Sending state -1.00000  with 0 decimals of accuracy
[12:21:53][D][text_sensor:067]: 'jn-mppt status operation mode': Sending state 'Offline'
...
[12:25:38][W][jnge_mppt_controller:460]: The device didn't respond to the last 15 status requests

anyway to test the MPPT RJ45 ports that they are actually working ? or could they have changed the pinout ?

on the Elfin-EW11A Pin 8 GND Brown X Pin 5 Pin 7 VCC Blue X Pin 7 Pin 6 B- Orange X Pin 1 Pin 5 A+ Green X Pin 3 Pin 4 Reload Empty Pin 3 Empty Pin 2 Empty Pin 1 Empty

20220527_114803

The schematic I have does show Pins 1/2 RS485-B RS485-B 3/4 RS485-A RS485-A 5/6 GND Powerground 7/8 +12VDC 12V/400mA

everything seems fine apart from no communication going on , all the wifi module does is reboot loops all 20+ of them ... I was really hoping to get this going , using these TTL turn RS485 module 485 to serial UART level mutual conversion hardware automatic flow control with esphome + Home Assistant

https://www.aliexpress.com/item/1005002970555534.html

also currently testing with a spare Wemos mini D1 , until esp32's arrive

syssi commented 2 years ago

Could you do two measurements:

  1. Please measure the voltage between Pin 6 and Pin 8. You have to make sure the device is connected to a battery.
  2. If there is no voltage at step 1 please measure the voltage between Pin 7 and Pin 8.

I'm aware of two pinouts of the RJ485 jack. Please compare the pinout of the JN-MPPT README with the JN-WIND README.

syssi commented 2 years ago

It looks like your WiFi module/adapter cable has the JN-WIND pinouts (may be the "new pinout"). Your solar charger has the JN-MPPT pinout (may be the "old pinout"). If you prepare a new cable you should be able to get both solutions up and running.

MasterCATZ commented 2 years ago

using 568B

Green and Brown Pin 6 Green -13.8v Pin 8 Brown +13.8v

Brown stripe and Brown skipped assuming ++ 0V

Blue Stripe + Green amusing both - - 0V

so assuming the pinout is still correct and I have Flipped TX/RX a few times now what else can I do to see data from the controller ?

some of the code their has been trying to get logger off the tx/rx pins of the wemos

esphome:
  name: esphome-web-410164

esp8266:
  board: d1_mini

# Enable logging
logger:
  baud_rate: 0
#  level: DEBUG
#  hardware_uart: UART1
#uart: UART1
#  tx_pin: GPIO2
# Enable Home Assistant API
api:
  password: !secret api_password

ota:

switch:
  - platform: gpio
    pin: GPIO4   #D2
    name: "Battery Bank 1 Heater Relay 1" 
    id: BB1HR1
  - platform: gpio 
    pin: GPIO5  #D1
    name: "Battery Bank 1 Heater Relay 2"
    id: BB1HR2
  - platform: jnge_mppt_controller
    buzzer:
      name: "${config} buzzer"
    street_light_mode:
      name: "${config} street light mode"
    charging:
      name: "${config} charging"
    load:
      name: "${config} load"

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO4   #D2
      mode: INPUT_PULLUP
      inverted: True
    name: "Battery Bank 1 Heater Relay 1 Toggle"
    id: BB1HR1T
    internal: true
    on_press:
      - switch.toggle: BB1HR1
  - platform: jnge_mppt_controller
    fan_running:
      name: "${status} fan running"
    load_detected:
      name: "${status} load detected"
    load:
      name: "${status} load"
    charging:
      name: "${status} charging"

dallas:
  - pin: GPIO2  #D4
    update_interval: 5s
sensor:
  - platform: dallas
    address: 0xcc0517010efcff28
    name: "Tank 1 Water Temp"
    id:  T1WT
  - platform: dallas
    address: 0xbd051700dfb6ff28
    name: "Tank 1 Air Temp"
    id:  T1AT
  - platform: jnge_mppt_controller
    ## status MPPT
    firmware_version:
      name: "${status} firmware version"
    pv_voltage:
      name: "${status} pv voltage"
    battery_voltage:
      name: "${status} battery voltage"
    channel_a_current:
      name: "${status} channel a current"
    channel_b_current:
      name: "${status} channel b current"
    charging_current:
      name: "${status} charging current"
    charger_temperature:
      name: "${status} charger temperature"
    charging_power:
      name: "${status} charging power"
    discharge_power:
      name: "${status} discharge power"
    battery_capacity:
      name: "${status} battery capacity"
    operation_mode_id:
      name: "${status} operation mode id"
    discharge_current:
      name: "${status} discharge current"
    discharge_times:
      name: "${status} discharge times"
    total_charging_energy:
      name: "${status} total charging energy"
    total_discharge_energy:
      name: "${status} total discharge energy"
    battery_temperature:
      name: "${status} battery temperature"
    error_bitmask:
      name: "${status} error bitmask"
    controller_voltage_level:
      name: "${status} controller voltage level"
    pv_standby_voltage:
      name: "${status} pv standby voltage"
    controller_current_level:
      name: "${status} controller current level"
    battery_strings:
      name: "${status} battery strings"
    battery_temperature_compensation_voltage_point:
      name: "${status} battery temperature compensation voltage point"

    ## config MPPT
    battery_overvoltage:
      name: "${config} battery overvoltage"
    charging_limit_voltage:
      name: "${config} charging limit voltage"
    battery_overvoltage_recovery:
      name: "${config} battery overvoltage recovery"
    equalizing_charging_voltage:
      name: "${config} equalizing charging voltage"
    boost_charging_voltage:
      name: "${config} boost charging voltage"
    boost_charging_return_voltage:
      name: "${config} boost charging return voltage"
    floating_charge_voltage:
      name: "${config} floating charge voltage"
    over_discharge_voltage:
      name: "${config} over discharge voltage"
    over_discharge_recovery_voltage:
      name: "${config} over discharge recovery voltage"
    battery_undervoltage:
      name: "${config} battery undervoltage"
    equalization_charging_time:
      name: "${config} equalization charging time"
    improve_charging_time:
      name: "${config} improve charging time"
    temperature_compensation_coefficient:
      name: "${config} temperature compensation coefficient"
    device_address:
      name: "${config} device address"
    light_control_on_voltage:
      name: "${config} light control on voltage"
    light_control_off_voltage:
      name: "${config} light control off voltage"
    light_control_on_period_1:
      name: "${config} light control on period 1"
    light_control_on_period_2:
      name: "${config} light control on period 2"
    load_turn_off_time:
      name: "${config} load turn off time"
  - platform: adc
    pin: A0
    name: "Air Pressure LP-100 #1"
    id: 'APLP1001'
    unit_of_measurement: "MPa"
    #raw: true
    filters:
    - offset:  -0.17
    #- offset:  -0.560
    #- multiply: 3.3
    - lambda: return x * 3.3; #not sure if this should be the supply voltage of 5v or 3.3V
#    - lambda: return x * 3.3 / 1024; #not sure if this should be the supply voltage of 5v or 3.3V
    update_interval: 60s
#  - platform: adc ##ESP32Only
#    name: "Pressure"
#    pin: A0
#    id: pressure
#    update_interval: 1s
#    unit_of_measurement: "PSI"
#    accuracy_decimals: 2
#    attenuation: 11db
#    filters:
#      - calibrate_linear:
#        - 0.5 -> 0.0
#        - 2.5 -> 30.0
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  power_save_mode: none

 # Optional manual IP
  manual_ip:
    static_ip: 192.168.2.78
    gateway: 192.168.2.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Web-410164"
    password: "1DLNCAUFPIRw"

captive_portal:

substitutions:
  name: jn-mppt
  status: "${name} status"
  config: "${name} config"

external_components:
  - source: github://syssi/esphome-jnge-mppt-controller@main
    refresh: 0s

#mqtt:
#  broker: !secret mqtt_host
#  username: !secret mqtt_username
#  password: !secret mqtt_password
#  id: mqtt_client

  ## MPPT TTL
#hardware_uart: UART0
uart:
  baud_rate: 9600
  tx_pin: GPIO1
  rx_pin: GPIO3

jnge_mppt_controller:
  update_interval: 5s

text_sensor:
  - platform: jnge_mppt_controller
    battery_type:
      name: "${status} battery type"
    errors:
      name: "${status} errors"
    operation_mode:
      name: "${status} operation mode"

jnge.log

I enabled debug both ways and yes wifi connection in the shed is terrible

syssi commented 2 years ago

This is what I've understood:

You have measured the voltage between pin 6 and 8 and it's 13.8V. Could you measure the voltage between pin 5 (GND) and 6 (GND). It should be 0V.

If the above is true we have identified this pinout:

https://github.com/syssi/esphome-jnge-mppt-controller/blob/main/jnge_mppt_controller.md#rj45-jack

Pin 1: B-
Pin 2: B-
Pin 3: B-
Pin 4: B-
Pin 5: GND
Pin 6: GND
Pin 7: VCC
Pin 8: VCC

The next step is to attach the RS485 converter to the RX/TX pins of your ESP:

https://raw.githubusercontent.com/syssi/esphome-jnge-mppt-controller/main/images/circuit.jpg

If you have flashed and powered the ESP the TXD LED (of the RS485 converter) must blink periodically. If the RX LED blinks periodically you have to swap RX/TX.

The RS485 lines must not be crossed. You have to attach "B-" (orange-white) to "B-" of the converter and "A+" (green-white) to "A+".

If everything is ready please provide a photo of your circuit/wiring.

MasterCATZ commented 2 years ago

yes the RS485 does blink

syssi commented 2 years ago

It's important the TX LED of the RS485 does blink. ;-) As next step I would like to see your wiring.

MasterCATZ commented 2 years ago

Video clip and some pics https://drive.google.com/drive/folders/17dD09No1H9q71I7gLnj-KpSR9HYUSzxJ?usp=sharing

ESP8266-WeMos-D1-Mini-pinout-gpio-pin

Screenshot from 2022-05-27 16-58-49

the leads may not look like they are on the pins fully but I have the pins jammed into the little holes so they are firmly attached

and the temp sensor was killed before and the pressure sensor is disconnected I really should pull that sensor off the board I guess

Orange VCC (3.3v ) - 3V3 Blue TX - GPIO1 TXD0 (just had a thought maybe I need to say TXD0 ?) Yellow RX -GPIO3 RXD0 (maybe config should be RXD0) Green GND - GND

Green Stripe A+ Orange Stripe B-
Blue Stripe GND

how should I be logging while using the rx / tx pins ? I tried this before and it shuts it up but still no data

  hardware_uart: UART1
[W][uart.arduino_esp8266:127]:   You're using the same serial port for logging and the UART component. Please disable logging over the serial port by setting logger->baud_rate to 0.

Currently

# Enable logging
logger:
  baud_rate: 0

...

uart:
  id: uart0
  baud_rate: 9600
  tx_pin: TX #TXD0 #GPIO1
  rx_pin: RX #RXD0 #GPIO3
  debug:
    direction: BOTH
syssi commented 2 years ago

I will try to replicate your setup to provide some details. The videos doesn't look good. I assume your setup crashs/reboots periodically.

MasterCATZ commented 2 years ago

no just wifi losses

its just for testing , I have been waiting for shelves to arrive since last year ... just like the ESP32's I ordered ...
Currently it is RS485 to TTL RX to RX on ESP8266 RS485 to TTL TX to TX on ESP8266

are you positive is should not be

RS485 to TTL RX to TX on ESP8266 RS485 to TTL TX to RX on ESP8266

 enable_fake_traffic: True

Proves everything else works

well was working , will be the last re-flash tonight its bricked now will have to bring back to pc tomorrow

INFO Compressed to 318634 bytes
Uploading: [===============================================             ] 79% 
ERROR Error sending data: [Errno 104] Connection reset by peer
syssi commented 2 years ago

I've prepared a small demo. I've used this config example:

substitutions:
  name: jn-mppt
  status: "${name} status"
  config: "${name} config"
  external_components_source: github://syssi/esphome-jnge-mppt-controller@main
  tx_pin: GPIO4
  rx_pin: GPIO5

esphome:
  name: ${name}
  platform: ESP8266
  board: d1_mini

external_components:
  - source: ${external_components_source}
    refresh: 0s

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

ota:
logger:

api:
# mqtt:
#   broker: !secret mqtt_host
#   username: !secret mqtt_username
#   password: !secret mqtt_password
#   id: mqtt_client

uart:
  baud_rate: 9600
  tx_pin: ${tx_pin}
  rx_pin: ${rx_pin}

jnge_mppt_controller:
  enable_fake_traffic: false
  suppress_battery_temperature_errors: false
  update_interval: 2s

binary_sensor:
  - platform: jnge_mppt_controller
    fan_running:
      name: "${status} fan running"
    load_detected:
      name: "${status} load detected"
    load:
      name: "${status} load"
    charging:
      name: "${status} charging"

sensor:
  - platform: jnge_mppt_controller
    # status
    firmware_version:
      name: "${status} firmware version"
    pv_voltage:
      name: "${status} pv voltage"
    battery_voltage:
      name: "${status} battery voltage"
    channel_a_current:
      name: "${status} channel a current"
    channel_b_current:
      name: "${status} channel b current"
    charging_current:
      name: "${status} charging current"
    charger_temperature:
      name: "${status} charger temperature"
    charging_power:
      name: "${status} charging power"
    discharge_power:
      name: "${status} discharge power"
    battery_capacity:
      name: "${status} battery capacity"
    operation_mode_id:
      name: "${status} operation mode id"
    discharge_current:
      name: "${status} discharge current"
    discharge_times:
      name: "${status} discharge times"
    total_charging_energy:
      name: "${status} total charging energy"
    total_discharge_energy:
      name: "${status} total discharge energy"
    battery_temperature:
      name: "${status} battery temperature"
    error_bitmask:
      name: "${status} error bitmask"
    controller_voltage_level:
      name: "${status} controller voltage level"
    pv_standby_voltage:
      name: "${status} pv standby voltage"
    controller_current_level:
      name: "${status} controller current level"
    battery_strings:
      name: "${status} battery strings"
    battery_temperature_compensation_voltage_point:
      name: "${status} battery temperature compensation voltage point"

    # config
    battery_overvoltage:
      name: "${config} battery overvoltage"
    charging_limit_voltage:
      name: "${config} charging limit voltage"
    battery_overvoltage_recovery:
      name: "${config} battery overvoltage recovery"
    equalizing_charging_voltage:
      name: "${config} equalizing charging voltage"
    boost_charging_voltage:
      name: "${config} boost charging voltage"
    boost_charging_return_voltage:
      name: "${config} boost charging return voltage"
    floating_charge_voltage:
      name: "${config} floating charge voltage"
    over_discharge_voltage:
      name: "${config} over discharge voltage"
    over_discharge_recovery_voltage:
      name: "${config} over discharge recovery voltage"
    battery_undervoltage:
      name: "${config} battery undervoltage"
    equalization_charging_time:
      name: "${config} equalization charging time"
    improve_charging_time:
      name: "${config} improve charging time"
    temperature_compensation_coefficient:
      name: "${config} temperature compensation coefficient"
    device_address:
      name: "${config} device address"
    light_control_on_voltage:
      name: "${config} light control on voltage"
    light_control_off_voltage:
      name: "${config} light control off voltage"
    light_control_on_period_1:
      name: "${config} light control on period 1"
    light_control_on_period_2:
      name: "${config} light control on period 2"
    load_turn_off_time:
      name: "${config} load turn off time"

switch:
  - platform: jnge_mppt_controller
    buzzer:
      name: "${config} buzzer"
    street_light_mode:
      name: "${config} street light mode"
    charging:
      name: "${config} charging"
    load:
      name: "${config} load"

text_sensor:
  - platform: jnge_mppt_controller
    battery_type:
      name: "${status} battery type"
    errors:
      name: "${status} errors"
    operation_mode:
      name: "${status} operation mode"

number:
  - platform: jnge_mppt_controller
    battery_overvoltage:
      name: "${config} battery overvoltage"
    charging_limit_voltage:
      name: "${config} charging limit voltage"
    battery_overvoltage_recovery:
      name: "${config} battery overvoltage recovery"
    equalizing_charging_voltage:
      name: "${config} equalizing charging voltage"
    boost_charging_voltage:
      name: "${config} boost charging voltage"
    boost_charging_return_voltage:
      name: "${config} boost charging return voltage"
    floating_charge_voltage:
      name: "${config} floating charge voltage"
    over_discharge_voltage:
      name: "${config} over discharge voltage"
    over_discharge_recovery_voltage:
      name: "${config} over discharge recovery voltage"
    battery_undervoltage:
      name: "${config} battery undervoltage"
    equalization_charging_time:
      name: "${config} equalization charging time"
    improve_charging_time:
      name: "${config} improve charging time"
    light_control_on_voltage:
      name: "${config} light control on voltage"
    light_control_off_voltage:
      name: "${config} light control off voltage"
    light_control_on_period_1:
      name: "${config} light control on period 1"
    light_control_on_period_2:
      name: "${config} light control on period 2"
    load_turn_off_time:
      name: "${config} load turn off time"
    battery_strings:
      name: "${config} battery strings"

I've used GPIO4 and GPIO5 (software serial) on purpose to be able to receive log message via UART0 (GPIO1, GPIO3).

Please have a look at this video. The update_interval of the component is 2 seconds therefore the component transmits one request per 2 seconds. The TX LED must blink every 2 seconds. Please compare this behavior with your TX LED. Something wrong is going on here with your setup.

https://user-images.githubusercontent.com/2735933/170672002-502a9455-8a5a-4e49-976a-705f37cdd950.mp4

syssi commented 2 years ago

As next step I've attached a JN-MPPT-Mini to the setup powered by a small 12V battery:

IMG_20220527_110353 IMG_20220527_110432 IMG_20220527_110438

syssi commented 2 years ago

If the JN-MPPT responds you should see something like this:

https://user-images.githubusercontent.com/2735933/170672525-2c48eccd-8171-412c-ae4c-5001b54f8923.mp4

Plus some debug output at the log:

[11:04:43][D][sensor:124]: 'jn-mppt status firmware version': Sending state 4.00000  with 0 decimals of accuracy
[11:04:43][D][sensor:124]: 'jn-mppt status pv voltage': Sending state 0.00000 V with 1 decimals of accuracy
[11:04:43][D][sensor:124]: 'jn-mppt status battery voltage': Sending state 12.20000 V with 1 decimals of accuracy
[11:04:43][D][sensor:124]: 'jn-mppt status channel a current': Sending state 0.00000 A with 1 decimals of accuracy
[11:04:43][D][sensor:124]: 'jn-mppt status channel b current': Sending state 0.00000 A with 1 decimals of accuracy
[11:04:43][D][sensor:124]: 'jn-mppt status charging current': Sending state 0.00000 A with 1 decimals of accuracy
[11:04:43][D][sensor:124]: 'jn-mppt status charger temperature': Sending state 22.00000 °C with 0 decimals of accuracy
[11:04:43][D][sensor:124]: 'jn-mppt status charging power': Sending state 0.00000 W with 1 decimals of accuracy
[11:04:43][D][sensor:124]: 'jn-mppt status discharge power': Sending state 0.00000 W with 1 decimals of accuracy
[11:04:43][D][sensor:124]: 'jn-mppt status battery capacity': Sending state 40.00000 % with 0 decimals of accuracy
[11:04:43][D][sensor:124]: 'jn-mppt status operation mode id': Sending state 0.00000  with 0 decimals of accuracy
[11:04:43][D][text_sensor:067]: 'jn-mppt status operation mode': Sending state 'Not charging'
[11:04:43][D][binary_sensor:036]: 'jn-mppt status load detected': Sending state ON
[11:04:43][D][sensor:124]: 'jn-mppt status discharge current': Sending state 0.00000 A with 1 decimals of accuracy
[11:04:44][D][sensor:124]: 'jn-mppt status discharge times': Sending state 0.00000  with 0 decimals of accuracy
[11:04:44][D][sensor:124]: 'jn-mppt status total charging energy': Sending state 0.40000 kWh with 1 decimals of accuracy
[11:04:44][D][sensor:124]: 'jn-mppt status total discharge energy': Sending state 0.00000 kWh with 1 decimals of accuracy
[11:04:44][D][sensor:124]: 'jn-mppt status battery temperature': Sending state 0.00000 °C with 0 decimals of accuracy
[11:04:44][D][sensor:124]: 'jn-mppt status error bitmask': Sending state 24576.00000  with 0 decimals of accuracy
[11:04:44][D][text_sensor:067]: 'jn-mppt status errors': Sending state 'Battery temperature sensor failure;PV array undervoltage'
[11:04:44][D][sensor:124]: 'jn-mppt status controller voltage level': Sending state 12.00000 V with 0 decimals of accuracy
[11:04:44][D][sensor:124]: 'jn-mppt status pv standby voltage': Sending state 11.30000 V with 1 decimals of accuracy
[11:04:44][D][sensor:124]: 'jn-mppt status controller current level': Sending state 30.00000 A with 0 decimals of accuracy
[11:04:44][D][sensor:124]: 'jn-mppt status battery strings': Sending state 1.00000  with 0 decimals of accuracy
[11:04:44][D][text_sensor:067]: 'jn-mppt status battery type': Sending state 'Lead-Acid'
[11:04:44][D][binary_sensor:036]: 'jn-mppt status charging': Sending state ON
[11:04:44][D][binary_sensor:036]: 'jn-mppt status fan running': Sending state OFF
[11:04:44][D][sensor:124]: 'jn-mppt status battery temperature compensation voltage point': Sending state 0.00000 mV with 0 decimals of accuracy
[11:04:44][D][binary_sensor:036]: 'jn-mppt status load': Sending state ON
MasterCATZ commented 2 years ago

d1minibackup.txt

Backup file for me and going to try yours I tried swapping the tx / rx again all it did was change which led went so both leds do work , its just both do not run ...

and bugga forgotten to slip in the manual networking details

and the api

# Enable Home Assistant API
api:
  password: !secret api_password

I was going to say it now only flashes TX every 30 sec , but then just realized I need to change the pins so back I go

MasterCATZ commented 2 years ago

Ok D1 and D2 are a win

now to find what my issue was

THANK YOU

I'll donate soon

syssi commented 2 years ago

You are welcome! No donation required.

MasterCATZ commented 2 years ago

well the esphome terminal is showing data but home assistant is not and it did before using the fake stuff ... I'll keep digging around at least I know its not hardware now

syssi commented 2 years ago

The "esphome node name" has changed because of my yaml. You have to remove the (old node) and add the new one. Or you have to change the node name back to the registered one.

MasterCATZ commented 2 years ago

yep gone back to my config all working now with just RX/TX pins changed

  tx_pin: GPIO4 #D2
  rx_pin: GPIO5 #D1

now I just have to find a way to deal with "unavailable " data when ever the wifi drops

wanting to use this to help control the grid battery charger so its not idling @ 30 watts 24/7 as a backup charger for when we have weeks worth of rain , like we just had ..

syssi commented 2 years ago

Last question out of curiosity: Where are you from?

MasterCATZ commented 2 years ago

Australia QLD

now wondering if I can make use of the Elfin EW11A Directly with Home Assistant