346 lines
7.8 KiB
YAML
346 lines
7.8 KiB
YAML
esphome:
|
||
name: modbus-pwm
|
||
friendly_name: Modbus PWM
|
||
comment: Testovací yaml pro pwm modul arduino
|
||
|
||
esp32:
|
||
board: esp32dev
|
||
framework:
|
||
type: esp-idf
|
||
|
||
# Enable logging
|
||
logger:
|
||
level: DEBUG
|
||
|
||
ota:
|
||
- platform: esphome
|
||
password: !secret ota_passwd
|
||
|
||
wifi:
|
||
ssid: !secret wifi_ssid
|
||
password: !secret wifi_password
|
||
|
||
web_server:
|
||
port: 80
|
||
version: 3
|
||
sorting_groups:
|
||
- id: sorting_group_testing
|
||
name: "Testing components"
|
||
sorting_weight: 10
|
||
- id: sorting_group_pwm_config
|
||
name: "PWM settings"
|
||
sorting_weight: 20
|
||
|
||
mqtt:
|
||
broker: !secret conf_mqtt_broker
|
||
username: !secret conf_mqtt_username
|
||
password: !secret conf_mqtt_password
|
||
discovery: true
|
||
discover_ip: true
|
||
# Načtu si teploty pro termostat
|
||
on_json_message:
|
||
topic: 'zigbee2mqtt/SNZB-02_01'
|
||
then:
|
||
- lambda: |-
|
||
id(temperature).publish_state(x["temperature"].as<float>());
|
||
- lambda: |-
|
||
id(humidity).publish_state(x["humidity"].as<float>());
|
||
|
||
|
||
|
||
# -------------------------
|
||
# UART → Modbus přes RS485
|
||
# -------------------------
|
||
uart:
|
||
tx_pin: GPIO18
|
||
rx_pin: GPIO19
|
||
baud_rate: 9600
|
||
stop_bits: 1
|
||
|
||
modbus:
|
||
id: modbus1
|
||
|
||
modbus_controller:
|
||
- id: slave_device
|
||
address: 3 # adresa Arduino Modbus zařízení
|
||
modbus_id: modbus1
|
||
update_interval: 10s
|
||
command_throttle: 100ms
|
||
setup_priority: -10
|
||
|
||
# --------------------------------------------------
|
||
# 6× PWM výstupy → zapisují 0–100 % do holding reg.
|
||
# Použity jen 4 PWM
|
||
# 4x PWM group → zapisují 0–100 % do holding reg.
|
||
# Použitá jen jedna group
|
||
# --------------------------------------------------
|
||
# --------------------------------------------------
|
||
# NO/NC přepínače (holding 5–8)
|
||
# 0 = NC (normal closed → HIGH = otevře)
|
||
# 1 = NO (normal open → HIGH = zavře)
|
||
# --------------------------------------------------
|
||
packages:
|
||
## PWM1
|
||
pwm1_out: !include
|
||
file: common/pwm_pin_output.yaml
|
||
vars:
|
||
id: pwm1_out
|
||
address: 16
|
||
switch_no_nc_1: !include
|
||
file: common/pwm_set_no_nc.yaml
|
||
vars:
|
||
id_name: 1
|
||
address: 17
|
||
pwm_to_group_1: !include
|
||
file: common/pwm_to_group.yaml
|
||
vars:
|
||
id: 1
|
||
address: 18
|
||
## PWM2
|
||
pwm2_out: !include
|
||
file: common/pwm_pin_output.yaml
|
||
vars:
|
||
id: pwm2_out
|
||
address: 19
|
||
|
||
switch_no_nc_2: !include
|
||
file: common/pwm_set_no_nc.yaml
|
||
vars:
|
||
id_name: 2
|
||
address: 20
|
||
pwm_to_group_2: !include
|
||
file: common/pwm_to_group.yaml
|
||
vars:
|
||
id: 2
|
||
address: 21
|
||
## PWM3
|
||
pwm3_out: !include
|
||
file: common/pwm_pin_output.yaml
|
||
vars:
|
||
id: pwm3_out
|
||
address: 22
|
||
switch_no_nc_3: !include
|
||
file: common/pwm_set_no_nc.yaml
|
||
vars:
|
||
id_name: 3
|
||
address: 23
|
||
pwm_to_group_3: !include
|
||
file: common/pwm_to_group.yaml
|
||
vars:
|
||
id: 3
|
||
address: 24
|
||
## PVM4
|
||
pwm4_out: !include
|
||
file: common/pwm_pin_output.yaml
|
||
vars:
|
||
id: pwm4_out
|
||
address: 25
|
||
switch_no_nc_4: !include
|
||
file: common/pwm_set_no_nc.yaml
|
||
vars:
|
||
id_name: 4
|
||
address: 26
|
||
pwm_to_group_4: !include
|
||
file: common/pwm_to_group.yaml
|
||
vars:
|
||
id: 4
|
||
address: 27
|
||
|
||
|
||
group1_pwm: !include
|
||
file: common/pwm_pin_output.yaml
|
||
vars:
|
||
id: group_pwm_1
|
||
address: 11
|
||
|
||
switch:
|
||
# --------------------------------------------------
|
||
# Test Mode (holding reg. 9)
|
||
# --------------------------------------------------30.5
|
||
- platform: modbus_controller
|
||
modbus_controller_id: slave_device
|
||
name: "Test Mode"
|
||
register_type: holding
|
||
icon: mdi:toggle-switch-variant-off
|
||
address: 1
|
||
write_lambda: |-
|
||
return x ? 1 : 0;
|
||
# read_lambda: |-
|
||
# return (uint16_t)x == 1;
|
||
|
||
|
||
# --------------------------------------------------
|
||
# LED SWITCH → D13 (holding register 12)
|
||
# 0 = OFF, 1 = ON
|
||
# --------------------------------------------------
|
||
|
||
- platform: modbus_controller
|
||
modbus_controller_id: slave_device
|
||
name: "LED D13"
|
||
register_type: holding
|
||
icon: mdi:toggle-switch-variant-off
|
||
address: 9
|
||
write_lambda: |-
|
||
return x ? 1 : 0;
|
||
# read_lambda: |-
|
||
# return (uint16_t)x == 1;
|
||
|
||
# --------------------------------------------------
|
||
# STATUS & ERROR → monitoring (registers 10 & 11)
|
||
# Bitmask status_flags:
|
||
# bit0 = config OK
|
||
# bit1 = CRC OK
|
||
# bit2 = defaults loaded
|
||
# --------------------------------------------------
|
||
sensor:
|
||
- platform: template
|
||
name: "Target climate temperature"
|
||
id: target_tmp
|
||
update_interval: 60s
|
||
unit_of_measurement: "°C"
|
||
icon: "mdi:thermometer"
|
||
device_class: "temperature"
|
||
state_class: "measurement"
|
||
accuracy_decimals: 1
|
||
|
||
- platform: pid
|
||
name: "PID Climate heat"
|
||
type: HEAT
|
||
unit_of_measurement: "%"
|
||
icon: mdi:valve
|
||
device_class: "power_factor"
|
||
state_class: "measurement"
|
||
accuracy_decimals: 1
|
||
|
||
- platform: template
|
||
name: "Teplota"
|
||
id: temperature
|
||
unit_of_measurement: "°C"
|
||
icon: "mdi:thermometer"
|
||
device_class: "temperature"
|
||
state_class: "measurement"
|
||
accuracy_decimals: 1
|
||
|
||
- platform: template
|
||
name: Vlhkost
|
||
id: humidity
|
||
unit_of_measurement: "%"
|
||
icon: "mdi:water-percent"
|
||
device_class: "humidity"
|
||
state_class: "measurement"
|
||
accuracy_decimals: 1
|
||
|
||
- platform: modbus_controller
|
||
modbus_controller_id: slave_device
|
||
name: "Status Flags"
|
||
register_type: holding
|
||
address: 2
|
||
unit_of_measurement: "flags"
|
||
|
||
- platform: modbus_controller
|
||
modbus_controller_id: slave_device
|
||
name: "Last Error Code"
|
||
register_type: holding
|
||
address: 3
|
||
unit_of_measurement: "code"
|
||
|
||
- platform: modbus_controller
|
||
modbus_controller_id: slave_device
|
||
name: "Modbus age"
|
||
register_type: holding
|
||
address: 4
|
||
unit_of_measurement: "ms"
|
||
|
||
- platform: modbus_controller
|
||
modbus_controller_id: slave_device
|
||
name: "Temperature 1"
|
||
register_type: holding
|
||
address: 5
|
||
unit_of_measurement: "°C"
|
||
icon: "mdi:thermometer"
|
||
device_class: "temperature"
|
||
state_class: "measurement"
|
||
accuracy_decimals: 1
|
||
filters:
|
||
- multiply: 0.01
|
||
|
||
- platform: modbus_controller
|
||
modbus_controller_id: slave_device
|
||
name: "Temperature 2"
|
||
register_type: holding
|
||
address: 6
|
||
unit_of_measurement: "°C"
|
||
icon: "mdi:thermometer"
|
||
device_class: "temperature"
|
||
state_class: "measurement"
|
||
accuracy_decimals: 1
|
||
filters:
|
||
- multiply: 0.01
|
||
|
||
- platform: modbus_controller
|
||
modbus_controller_id: slave_device
|
||
name: "Temperature 3"
|
||
register_type: holding
|
||
address: 7
|
||
unit_of_measurement: "°C"
|
||
icon: "mdi:thermometer"
|
||
device_class: "temperature"
|
||
state_class: "measurement"
|
||
accuracy_decimals: 1
|
||
filters:
|
||
- multiply: 0.01
|
||
|
||
- platform: modbus_controller
|
||
modbus_controller_id: slave_device
|
||
name: "Temperature 4"
|
||
register_type: holding
|
||
address: 8
|
||
unit_of_measurement: "°C"
|
||
icon: "mdi:thermometer"
|
||
device_class: "temperature"
|
||
state_class: "measurement"
|
||
accuracy_decimals: 1
|
||
filters:
|
||
- multiply: 0.01
|
||
|
||
button:
|
||
- platform: restart
|
||
name: "Restart"
|
||
|
||
|
||
number:
|
||
- platform: modbus_controller
|
||
id: pwm_period_ms
|
||
modbus_controller_id: slave_device
|
||
name: "PWM Period (s)"
|
||
web_server:
|
||
sorting_group_id: sorting_group_pwm_config
|
||
register_type: holding
|
||
address: 0
|
||
unit_of_measurement: "s"
|
||
min_value: 1
|
||
max_value: 600
|
||
step: 1
|
||
mode: slider
|
||
|
||
climate:
|
||
- platform: pid
|
||
id: pid_climate
|
||
name: "Pokoj"
|
||
sensor: temperature
|
||
default_target_temperature: 20.5°C
|
||
heat_output: group_pwm_1
|
||
control_parameters:
|
||
kp: 0.35
|
||
ki: 0.000015
|
||
kd: 0.0 # Není třeba protože velká setvačnost
|
||
visual:
|
||
min_temperature: 18
|
||
max_temperature: 23
|
||
temperature_step: 0.5
|
||
icon: mdi:thermostat
|
||
on_state:
|
||
- lambda: |-
|
||
id(target_tmp).publish_state(id(pid_climate).target_temperature);
|
||
|