mightea / esphome-mystrom-devices

ESPHome configurations for mystrom devices
GNU Affero General Public License v3.0
14 stars 5 forks source link

myStrom switch [EU] support #2

Open MayorBug opened 11 months ago

MayorBug commented 11 months ago

I have successfully converted the EU version switch to esphome thanks to your project

This one: image image image

Discoveries:

Feel free to add this to your repo or just leave it here for others to find.

Here is a pic of it working:

image

Here is my code:

esphome:
  friendly_name: myStrom Switch
  name: mystrom-switch

esp32:
  board: esp32doit-devkit-v1
  framework:
    type: esp-idf
    sdkconfig_options:
      COMPILER_OPTIMIZATION_SIZE: y
    advanced:
      ignore_efuse_mac_crc: true

# Enable logging
logger:
  level: WARN

# Enable Home Assistant API
api:
  encryption:
    key: " "

ota:

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

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

  enable_btm: True
  enable_rrm: True

captive_portal:

# Enable NTP
time:
  - platform: sntp
    id: my_time

preferences:
  flash_write_interval: 5min

i2c:
  sda: 22
  scl: 19
  scan: false

light:
  - platform: binary
    name: "Identify LED"
    disabled_by_default: true
    restore_mode: RESTORE_DEFAULT_OFF
    output: output_mystrom_led_red
  - platform: binary
    id: light_mystrom_status
    restore_mode: RESTORE_DEFAULT_ON
    output: output_mystrom_led_white

output:
  - id: output_mystrom_led_red
    platform: gpio
    pin: GPIO16
    inverted: false
  - id: output_mystrom_led_white
    platform: gpio
    pin: GPIO17
    inverted: true

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO23
      mode:
        input: true
        pullup: true
      inverted: true
    id: button_mystrom_side
    on_press:
      then:
        - switch.toggle: switch_mystrom_relay
  - platform: gpio
    pin:
      number: GPIO18
      mode:
        input: true
        pullup: true
      inverted: true
    id: button_mystrom_bottom
    on_press:
      then:
        - switch.toggle: switch_mystrom_relay

sensor:
  - platform: pulse_counter
    pin: 4
    update_interval: 10s
    id: sensor_mystrom_energy_usage
    name: "Power"
    unit_of_measurement: "W"
    accuracy_decimals: 0
    filters:
      # Map from sensor -> measured value
      - calibrate_linear:
          - 0.0 -> 1.55
          - 2698.5 -> 85
          - 4397.25 -> 146
          - 30900 -> 1005
          - 44634.56 -> 1439
          - 59643.75 -> 1930
      # Make everything below 1W appear as just 0W.
      # Furthermore it corrects 1.55W for the power usage of the plug.
      - lambda: if (x < (1 + 1.55)) return 0; else return (x - 1.55);

  - platform: total_daily_energy
    name: "Total Daily Energy"
    power_id: sensor_mystrom_energy_usage
    filters:
      # Multiplication factor from W to kW is 0.001
      - multiply: 0.001
    unit_of_measurement: kWh
    accuracy_decimals: 1

  - platform: shtcx
    id: sensor_mystrom_temperature
    temperature:
      name: "Internal Temperature"
      on_value_range:
        above: 80
        then:
          - switch.turn_off: switch_mystrom_relay
    humidity:
      name: "Internal Humidity"
    update_interval: 60s
    address: 0x70

  - platform: uptime
    name: Uptime
    entity_category: "diagnostic"

    # Reports the WiFi signal strength/RSSI in dB
  - platform: wifi_signal
    name: "WiFi Strength"
    id: wifi_signal_db
    update_interval: 60s
    #Converts the WiFi signal strength to %
    filters:
      - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
    unit_of_measurement: "%"
    entity_category: "diagnostic"

switch:
  - platform: gpio
    name: "Relay"
    pin: GPIO27
    id: switch_mystrom_relay
    restore_mode: RESTORE_DEFAULT_ON
    on_turn_on:
      - output.turn_on: output_mystrom_led_white
    on_turn_off:
      - output.turn_off: output_mystrom_led_white

button:
  - platform: restart
    name: "Restart"
mightea commented 11 months ago

Hey @MayorBug thanks for the documentation on flashing the EU switch! Great to hear that this repo helped to get you started. I will happily integrate this device into this repo.