- substitutions:
- devicename: esp32-tools
- sdm1_entity: "SDM-AC"
- pzem_entity: "PZEM-RACK"
- sdm1_entity_under: "sdm_ac"
- pzem_entity_under: "pzem_rack"
- esp_entity: "ESP-TOOLS"
- hostname: $devicename
- update_interval: 20s
- esphome:
- name: $devicename
- comment: "ESP32/RS485/CC1101/DHT11/PZEM004"
- esp32:
- board: esp32dev
- # framework:
- # type: arduino
- # version: 2.0.6
- external_components:
- - source:
- type: git
- url: https://github.com/zdzichu6969/esphome-components
- components: [ heapmon, backup, startup ]
- refresh: 0s
- - source:
- type: git
- url: https://github.com/SzczepanLeon/esphome-components
- components: [ wmbus ]
- refresh: 0s
- - source: github://pr#4444
- components: [async_tcp, web_server_base]
- refresh: always
- # Enable logging
- logger:
- level: DEBUG
- baud_rate: 0
- api:
- encryption:
- key: !secret api_encryption_key
- reboot_timeout: 0s
- ota:
- - platform: esphome
- password: !secret ota_password
- #safe_mode: True
- wifi:
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- reboot_timeout: 300s
- power_save_mode: none
- fast_connect: true
- domain: .iot.r.local
- use_address: 10.87.65.19
- #use_address: 10.87.65.27
- ap:
- ssid: "Fallback-AP-${hostname}"
- password: ""
- ap_timeout: 300s
- captive_portal:
- web_server:
- version: 3
- port: 80
- ota: false
- include_internal: false
- local: true
- time:
- - platform: sntp
- id: sntp_time1
- servers:
- - 10.87.65.1
- timezone: Europe/Warsaw
- on_time_sync:
- then:
- - logger.log: "Synchronized system clock"
- uart:
- - id: uart_sdm
- tx_pin: GPIO17
- rx_pin: GPIO16
- baud_rate: 2400
- stop_bits: 1
- rx_buffer_size: 512
- - id: uart_pzem
- tx_pin: GPIO1
- rx_pin: GPIO3
- baud_rate: 9600
- modbus:
- - id: mod_bus_sdm
- send_wait_time: 500ms
- uart_id: uart_sdm
- disable_crc: true
- - id: mod_bus_pzem
- send_wait_time: 200ms
- uart_id: uart_pzem
- disable_crc: false
- wmbus:
- mosi_pin: GPIO23
- clk_pin: GPIO22
- miso_pin: GPIO19
- gdo0_pin: GPIO21
- gdo2_pin: GPIO18
- cs_pin: GPIO5
- log_unknown: True
- modbus_controller:
- - id: pzem
- # The current device address.
- address: 0x1
- # The special address 0xF8 is a broadcast address accepted by any pzem device,
- # so if you use this address, make sure there is only one pzem device connected
- # to the uart bus.
- # address: 0xF8
- modbus_id: mod_bus_pzem
- command_throttle: 0ms
- setup_priority: -10
- - id: sdm
- modbus_id: mod_bus_sdm
- update_interval: ${update_interval}
- address: 1
- setup_priority: -10
- interval:
- - interval: ${update_interval}
- then:
- - delay: 500ms
- - lambda: "id(${pzem_entity_under}).update();"
- sensor:
- ### PZEM ###
- - platform: pzemac
- id: ${pzem_entity_under}
- modbus_id: mod_bus_pzem
- current:
- name: "${pzem_entity} Current"
- filters:
- - lambda: |-
- float MAX_DIFFERENCE = 20.0;
- static float last_value = NAN;
- if (isnan(last_value) || std::abs(x - last_value) < MAX_DIFFERENCE)
- return last_value = x;
- else
- return {};
- voltage:
- name: "${pzem_entity} Voltage"
- filters:
- - lambda: |-
- float MAX_DIFFERENCE = 300.0;
- static float last_value = NAN;
- if (isnan(last_value) || std::abs(x - last_value) < MAX_DIFFERENCE)
- return last_value = x;
- else
- return {};
- energy:
- name: "${pzem_entity} Energy"
- unit_of_measurement: "kWh"
- filters:
- - multiply: 0.001
- - lambda: |-
- float MAX_DIFFERENCE = 1.0;
- static float last_value = NAN;
- if (isnan(last_value) || std::abs(x - last_value) < MAX_DIFFERENCE)
- return last_value = x;
- else
- return {};
- accuracy_decimals: 3
- id: "${pzem_entity_under}_energy"
- power:
- name: "${pzem_entity} Power"
- filters:
- - lambda: |-
- float MAX_DIFFERENCE = 10000.0;
- static float last_value = NAN;
- if (isnan(last_value) || std::abs(x - last_value) < MAX_DIFFERENCE)
- return last_value = x;
- else
- return {};
- frequency:
- name: "${pzem_entity} Frequency"
- filters:
- - lambda: |-
- float MAX_DIFFERENCE = 2.0;
- static float last_value = NAN;
- if (isnan(last_value) || std::abs(x - last_value) < MAX_DIFFERENCE)
- return last_value = x;
- else
- return {};
- power_factor:
- name: "${pzem_entity} Power Factor"
- filters:
- - lambda: |-
- float MAX_DIFFERENCE = 2.0;
- static float last_value = NAN;
- if (isnan(last_value) || std::abs(x - last_value) < MAX_DIFFERENCE)
- return last_value = x;
- else
- return {};
- ### DHT-11 ###
- - platform: dht
- pin: GPIO13
- temperature:
- name: "Szafa temperature"
- humidity:
- name: "Szafa humidity"
- update_interval: 30s
- model: DHT11
- - platform: wmbus
- meter_id: 0x03300600
- type: apator162
- key: "00000000000000000000000000000000"
- add_prefix: False
- lqi:
- name: "Apator 03300600 lqi"
- rssi:
- name: "Apator 03300600 RSSI"
- total_water_m3:
- name: "Apator 03300600"
- - platform: wmbus
- meter_id: 0x00340449
- type: apator162
- key: "00000000000000000000000000000000"
- add_prefix: false
- lqi:
- name: "Apator 00340449 lqi"
- rssi:
- name: "Apator 00340449 RSSI"
- total_water_m3:
- name: "Apator 00340449"
- ### SDM120-M KLIMA ###
- - platform: modbus_controller
- modbus_controller_id: sdm
- id: sdm1_current
- name: "${sdm1_entity} Current"
- register_type: read
- address: 0x0006
- value_type: FP32
- device_class: "current"
- state_class: "measurement"
- unit_of_measurement: A
- accuracy_decimals: 3
- - platform: modbus_controller
- modbus_controller_id: sdm
- name: "${sdm1_entity} Voltage"
- register_type: read
- address: 0x0000
- value_type: FP32
- unit_of_measurement: V
- device_class: "voltage"
- state_class: "measurement"
- accuracy_decimals: 2
- - platform: modbus_controller
- modbus_controller_id: sdm
- name: "${sdm1_entity} Power"
- register_type: read
- address: 0x000C
- value_type: FP32
- unit_of_measurement: W
- device_class: "power"
- state_class: "measurement"
- accuracy_decimals: 2
- - platform: modbus_controller
- modbus_controller_id: sdm
- name: "${sdm1_entity} Power Factor"
- register_type: read
- address: 0x001E
- value_type: FP32
- device_class: "power_factor"
- state_class: "measurement"
- unit_of_measurement: ""
- accuracy_decimals: 3
- - platform: modbus_controller
- modbus_controller_id: sdm
- name: "${sdm1_entity} Apparent Power"
- register_type: read
- address: 0x0012
- value_type: FP32
- device_class: ""
- state_class: "measurement"
- unit_of_measurement: VA
- accuracy_decimals: 3
- - platform: modbus_controller
- modbus_controller_id: sdm
- name: "${sdm1_entity} Reactive Power"
- register_type: read
- address: 0x0018
- value_type: FP32
- device_class: ""
- state_class: "measurement"
- unit_of_measurement: var
- accuracy_decimals: 2
- - platform: modbus_controller
- modbus_controller_id: sdm
- name: "${sdm1_entity} Frequency"
- register_type: read
- address: 0x0046
- value_type: FP32
- unit_of_measurement: Hz
- state_class: "measurement"
- accuracy_decimals: 2
- - platform: modbus_controller
- modbus_controller_id: sdm
- name: "${sdm1_entity} Import Active Energy"
- register_type: read
- address: 0x0048
- value_type: FP32
- unit_of_measurement: kWh
- state_class: "total_increasing"
- device_class: "energy"
- accuracy_decimals: 3
- id: "${sdm1_entity_under}_import_active_energy"
- - platform: modbus_controller
- modbus_controller_id: sdm
- name: "${sdm1_entity} Import Reactive Energy"
- register_type: read
- address: 0x004C
- value_type: FP32
- unit_of_measurement: kVArh
- state_class: "total_increasing"
- device_class: "energy"
- ### OTHER ###
- - platform: wifi_signal
- id: esp_mcc_wifisignal
- name: "${esp_entity} WiFi Signal"
- update_interval: 60s
- - platform: uptime
- id: esp_mcc_uptime
- name: "${esp_entity} Uptime"
- filters:
- - lambda: return x / 60.0;
- unit_of_measurement: minutes
- - platform: heapmon
- id: esp_mcc_heapspace
- name: "${esp_entity} Heapsize"
- entity_category: diagnostic
- - platform: copy
- source_id: esp_mcc_wifisignal
- id: esp_mcc_wifisignal_hr
- name: "${esp_entity} WiFi %"
- filters:
- - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
- unit_of_measurement: "%"
- icon: mdi:wifi
- entity_category: "diagnostic"
- - platform: startup
- name: ${esp_entity} Startup
- entity_category: diagnostic
- text_sensor:
- - platform: version
- name: ${esp_entity} ESPHome Version
- hide_timestamp: true
- - platform: wifi_info
- ip_address:
- name: ${esp_entity} IP Address
- icon: mdi:ip-network
- switch:
- - platform: restart
- name: "${esp_entity} Restart"
- - platform: factory_reset
- name: "${esp_entity} Factory reset"
- backup: