Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TO-Q-SY1-JWT DIN Rail Switch with Energy Meter config incomplete. #15

Open
dwmw2 opened this issue Aug 11, 2024 · 1 comment
Open

TO-Q-SY1-JWT DIN Rail Switch with Energy Meter config incomplete. #15

dwmw2 opened this issue Aug 11, 2024 · 1 comment

Comments

@dwmw2
Copy link

dwmw2 commented Aug 11, 2024

The config at https://upk.libretiny.eu/?profile=tongou-to-q-sy1-jwt-din-rail-switch-with-energy-meter is missing the relay switch, the button, and the LED which indicates that the main relay is on.

  "pins": {
    "9": "LED_n;1",
    "15": "WifiLED_n;0",
    "17": "Btn;1",
    "24": "BridgeFWD;1",
    "26": "BridgeREV;1"
  },

I've added them, and my config looks like this (not tested with the relay as the power supply in this unit is broken, which is why I took it out of service and opened it up and finally got round to liberating it).

There may be better ways to tie the LED to the relay state, but there isn't a suitable H-Bridge driver in esphome for relays so manually pulsing for 100ms when the LED goes on/off seemed reasonable enough.

esphome:
  name: upk2esphome-bk7231n
  on_boot:
    - switch.turn_on: relay

bk72xx:
  board: generic-bk7231n-qfn32-tuya

packages:
  base: !include base.yaml # My wifi and MQTT settings

logger:
  level: DEBUG

mqtt:
  on_connect:
    then:
      - light.turn_on: led
  on_disconnect:
    then:
      - light.turn_off: led

text_sensor:
  - platform: libretiny
    version:
      name: LibreTiny Version

light:
  - platform: status_led
    name: "Status LED"
    pin:
      number: P15
      inverted: true
    id: led
    restore_mode: ALWAYS_OFF

binary_sensor:
  - platform: gpio
    name: button
    id: button
    internal: true
    pin:
      number: P17
      inverted: true
    filters:
     - delayed_off: 10ms
    on_press:
      then:
         switch.toggle: relay

switch:
  - platform: gpio
    internal: true
    pin: P24
    id: relay_on
    restore_mode: ALWAYS_OFF
  - platform: gpio
    internal: true
    pin: P26
    id: relay_off
    restore_mode: ALWAYS_OFF
  - platform: gpio
    pin:
      number: P9
      inverted: true
    id: relay
    name: Relay
    restore_mode: ALWAYS_OFF # Will by turned on (with relay) at boot
    on_turn_on:
      then:
       - switch.turn_off: relay_off
       - switch.turn_on: relay_on
       - delay: 100ms
       - switch.turn_off: relay_on
    on_turn_off:
      then:
       - switch.turn_off: relay_on
       - switch.turn_on: relay_off
       - delay: 100ms
       - switch.turn_off: relay_off

uart:
  id: uart_bus
  tx_pin: TX1
  rx_pin: RX1
  baud_rate: 4800
  stop_bits: 1

sensor:
  - platform: bl0942
    uart_id: uart_bus
    current:
      name: BL0942 Current
    voltage:
      name: BL0942 Voltage
    power:
      name: BL0942 Power
      filters:
        multiply: -1
    energy:
      name: BL0942 Energy
    frequency:
      name: BL0942 Frequency
      accuracy_decimals: 2
@dwmw2
Copy link
Author

dwmw2 commented Sep 7, 2024

FWIW we now know a lot more about extracting the calibration data from the original firmware too: libretiny-eu/ltchiptool#38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant