523 lines
13 KiB
YAML
523 lines
13 KiB
YAML
packages:
|
|
- !include common/wifi.yaml
|
|
- !include common/felicityinverter.yaml
|
|
- !include common/canbus.yaml
|
|
- !include common/modbus.yaml
|
|
|
|
substitutions:
|
|
name: sthome-ut2
|
|
friendly_name: "sthome-ut2"
|
|
|
|
esphome:
|
|
name: "${name}"
|
|
friendly_name: "${friendly_name}"
|
|
includes:
|
|
- source # copies folder with files to relevant to be included in esphome compile
|
|
- <source/solar/cb_frame.h> # angle brackets ensure file is included above globals in main.cpp. Make sure to use include GUARDS in the file to prevent double inclusion
|
|
- <source/solar/cbf_store.h>
|
|
- <source/solar/cbf_pylon.h>
|
|
- <source/solar/cbf_store_pylon.h>
|
|
- <source/solar/cbf_sthome.h>
|
|
- <source/solar/cbf_store_sthome.h>
|
|
- <source/solar/cbf_cache.h>
|
|
|
|
#external_components:
|
|
# - source: github://pr#8103
|
|
# components: [uart]
|
|
# - source: github://pr#8032
|
|
# components: [modbus, modbus_controller, growatt_solar]
|
|
# refresh: 1h
|
|
globals:
|
|
- id: can_msgctr
|
|
type: int
|
|
restore_value: no
|
|
- id: can2_msgctr
|
|
type: int
|
|
restore_value: no
|
|
- id: last_battery_message_time
|
|
type: time_t
|
|
restore_value: no
|
|
- id: g_cb_cache # the cache is used to only accept a frame after it has been received a specified number of times within a specified period. this hopefully will iron out spurious corrupted frames
|
|
type: solar::cbf_cache
|
|
restore_value: no
|
|
- id: g_cb_request_queue
|
|
type: std::queue< std::set<uint32_t> >
|
|
restore_value: no
|
|
|
|
esp32:
|
|
board: esp32dev
|
|
framework:
|
|
type: esp-idf
|
|
|
|
# Enable logging
|
|
logger:
|
|
level: VERY_VERBOSE
|
|
initial_level: INFO
|
|
logs:
|
|
canbus: INFO
|
|
uart_debug: VERY_VERBOSE
|
|
modbus: VERBOSE
|
|
modbus_controller: VERBOSE
|
|
|
|
# Enable Home Assistant API
|
|
api:
|
|
encryption:
|
|
key: "o+fgr4qh0rTegCxXE3jbfJ/0si8+W9wxgnnYX9Xucqw="
|
|
|
|
ota:
|
|
- platform: esphome
|
|
password: "cb8a82d04c2f4dcf9bd273f903c7c378"
|
|
|
|
wifi:
|
|
manual_ip:
|
|
static_ip: 10.0.2.2
|
|
|
|
# Enable fallback hotspot (captive portal) in case wifi connection fails
|
|
ap:
|
|
ssid: "${name} Fallback Hotspot"
|
|
password: "geuZrJgQo7cg"
|
|
|
|
captive_portal:
|
|
|
|
spi:
|
|
- id: spi_bus0
|
|
clk_pin: GPIO18
|
|
mosi_pin: GPIO23
|
|
miso_pin: GPIO19
|
|
interface: any
|
|
|
|
uart:
|
|
- id: sth_uart
|
|
rx_pin:
|
|
number: GPIO17
|
|
inverted: false
|
|
mode:
|
|
input: true
|
|
pullup: true
|
|
tx_pin: GPIO16
|
|
baud_rate: 9600
|
|
stop_bits: 1
|
|
parity: NONE
|
|
debug:
|
|
direction: BOTH
|
|
dummy_receiver: false
|
|
after:
|
|
delimiter: "\n"
|
|
sequence:
|
|
- lambda: UARTDebug::log_hex(direction, bytes, ',');
|
|
|
|
sun:
|
|
id: sun_sensor
|
|
latitude: !secret latitude
|
|
longitude: !secret longitude
|
|
|
|
time:
|
|
- platform: homeassistant
|
|
id: time_source
|
|
|
|
switch:
|
|
- platform: restart
|
|
name: "${name} Restart"
|
|
id: "restart_switch"
|
|
|
|
interval:
|
|
- interval: 10s
|
|
then:
|
|
- lambda: |-
|
|
id(canbus_send_heartbeat).execute();
|
|
# - interval: 2.36s
|
|
# then:
|
|
# - uart.write:
|
|
# data: "sthome2 heartbeat\r\n"
|
|
# - sth_uart.write: !lambda
|
|
# return std::vector<uint8_t>({0x0D, 0x0A, 0x43, 0x50, 0x53, 0x00, 0x0D, 0x0A, 0x43, 0x50, 0x53, 0x00});
|
|
|
|
canbus:
|
|
- platform: mcp2515
|
|
cs_pin: GPIO32 # CBCS
|
|
spi_id: spi_bus0
|
|
id: canbus_sthome
|
|
mode: NORMAL
|
|
can_id: ${CB_CANBUS_ID03}
|
|
bit_rate: 500KBPS
|
|
on_frame:
|
|
- can_id: 0
|
|
can_id_mask: 0
|
|
then:
|
|
- lambda: |-
|
|
id(can_msgctr)++;
|
|
using namespace solar;
|
|
auto time_obj = id(time_source).now();
|
|
//ESP_LOGI("CB REC", "%s", id(time_source).now().strftime("%a %d %b %Y - %I:%M:%S %p"));
|
|
if(time_obj.is_valid()) {
|
|
if (can_id >= 0x380 && can_id < 0x3C0) {
|
|
auto cbitem = cbf_store_sthome(id(can_msgctr), can_id, x, remote_transmission_request, time_obj.timestamp);
|
|
bool publish = id(g_cb_cache).additem(cbitem);
|
|
if(publish) {
|
|
ESP_LOGI(cbitem.tag().c_str(), "%s", cbitem.to_string().c_str());
|
|
}
|
|
} else {
|
|
auto cbitem = cbf_store_sthome(id(can_msgctr), can_id, x, remote_transmission_request, time_obj.timestamp);
|
|
ESP_LOGI(cbitem.tag().c_str(), "%s", cbitem.to_string().c_str());
|
|
}
|
|
}
|
|
|
|
modbus:
|
|
- id: modbus_server
|
|
uart_id: sth_uart
|
|
send_wait_time: 1200ms #250ms
|
|
disable_crc: false
|
|
role: server
|
|
|
|
modbus_controller:
|
|
- id: modbus_alarm_server
|
|
modbus_id: modbus_server
|
|
address: 0x01
|
|
server_registers:
|
|
- address: 0x0001
|
|
value_type: S_DWORD_R
|
|
read_lambda: |-
|
|
uint16_t alarm_status = id(person_detected_switch).state ? 1 : 0;
|
|
alarm_status |= id(alarm_zone4_relay).state ? 2 : 0;
|
|
alarm_status |= id(lights_backyard_relay).state ? 4 : 0;
|
|
alarm_status |= id(lights_frontyard_relay).state ? 8 : 0;
|
|
alarm_status |= id(floodlight_test).state ? 16 : 0;
|
|
alarm_status |= id(night_time).state ? 32 : 0;
|
|
alarm_status |= id(zone1_triggered).state ? 64 : 0;
|
|
alarm_status |= id(zone2_triggered).state ? 128 : 0;
|
|
alarm_status |= id(zone3_triggered).state ? 256 : 0;
|
|
alarm_status |= id(zone4_triggered).state ? 512 : 0;
|
|
alarm_status |= id(zone5_triggered).state ? 1024 : 0;
|
|
alarm_status |= id(zone6_triggered).state ? 2048 : 0;
|
|
return alarm_status;
|
|
binary_sensor:
|
|
- platform: template
|
|
id: person_detected_switch
|
|
name: "Person Detected Switch"
|
|
lambda: |-
|
|
return true;
|
|
- platform: template
|
|
id: alarm_zone4_relay
|
|
name: "Alarm Zone 4 Relay"
|
|
lambda: |-
|
|
return true;
|
|
- platform: template
|
|
id: lights_backyard_relay
|
|
name: "Lights Backyard Relay"
|
|
lambda: |-
|
|
return true;
|
|
- platform: template
|
|
id: lights_frontyard_relay
|
|
name: "Lights Frontyard Relay"
|
|
lambda: |-
|
|
return true;
|
|
- platform: template
|
|
id: floodlight_test
|
|
name: "Floodlight Test"
|
|
lambda: |-
|
|
return true;
|
|
- platform: template
|
|
id: night_time
|
|
name: "Night Time"
|
|
lambda: |-
|
|
return true;
|
|
- platform: template
|
|
id: zone1_triggered
|
|
name: "Zone 1 Triggered"
|
|
lambda: |-
|
|
return true;
|
|
- platform: template
|
|
id: zone2_triggered
|
|
name: "Zone 2 Triggered"
|
|
lambda: |-
|
|
return true;
|
|
- platform: template
|
|
id: zone3_triggered
|
|
name: "Zone 3 Triggered"
|
|
lambda: |-
|
|
return true;
|
|
- platform: template
|
|
id: zone4_triggered
|
|
name: "Zone 4 Triggered"
|
|
lambda: |-
|
|
return true;
|
|
- platform: template
|
|
id: zone5_triggered
|
|
name: "Zone 5 Triggered"
|
|
lambda: |-
|
|
return true;
|
|
- platform: template
|
|
id: zone6_triggered
|
|
name: "Zone 6 Triggered"
|
|
lambda: |-
|
|
return true;
|
|
|
|
|
|
#modbus:
|
|
# - id: modbus_client
|
|
# uart_id: sth_uart
|
|
# send_wait_time: 1200ms #250ms
|
|
# disable_crc: false
|
|
# role: client
|
|
#
|
|
#modbus_controller:
|
|
# - id: modbus_alarm_client
|
|
# modbus_id: modbus_client
|
|
# address: 0x01
|
|
# allow_duplicate_commands: False
|
|
# command_throttle: 700ms #2022ms
|
|
# update_interval: 10s #305s
|
|
# offline_skip_updates: 2
|
|
# max_cmd_retries: 1
|
|
# setup_priority: -10
|
|
#
|
|
#binary_sensor:
|
|
#- platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: person_detected
|
|
# name: "Person Detected"
|
|
# register_type: read
|
|
# address: 0x0001
|
|
# bitmask: 0x1
|
|
#- platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: alarm_zone4_relay
|
|
# name: "Alarm Zone 4 Relay"
|
|
# register_type: read
|
|
# address: 0x0001
|
|
# bitmask: 0x2
|
|
#- platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: lights_backyard_relay
|
|
# name: "Lights Backyard Relay"
|
|
# register_type: read
|
|
# address: 0x0001
|
|
# bitmask: 0x4
|
|
#- platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: lights_frontyard_relay
|
|
# name: "Lights Frontyard Relay"
|
|
# register_type: read
|
|
# address: 0x0001
|
|
# bitmask: 0x8
|
|
#- platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: floodlight_test
|
|
# name: "Floodlight Test"
|
|
# register_type: read
|
|
# address: 0x0001
|
|
# bitmask: 0x10
|
|
#- platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: night_time
|
|
# name: "Night Time"
|
|
# register_type: read
|
|
# address: 0x0001
|
|
# bitmask: 0x20
|
|
#- platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: zone1_triggered
|
|
# name: "Zone 1 Triggered"
|
|
# register_type: read
|
|
# address: 0x0001
|
|
# bitmask: 0x40
|
|
#- platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: zone2_triggered
|
|
# name: "Zone 2 Triggered"
|
|
# register_type: read
|
|
# address: 0x0001
|
|
# bitmask: 0x80
|
|
#- platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: zone3_triggered
|
|
# name: "Zone 3 Triggered"
|
|
# register_type: read
|
|
# address: 0x0001
|
|
# bitmask: 0x100
|
|
#- platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: zone4_triggered
|
|
# name: "Zone 4 Triggered"
|
|
# register_type: read
|
|
# address: 0x0001
|
|
# bitmask: 0x200
|
|
#- platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: zone5_triggered
|
|
# name: "Zone 5 Triggered"
|
|
# register_type: read
|
|
# address: 0x0001
|
|
# bitmask: 0x400
|
|
#- platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: zone6_triggered
|
|
# name: "Zone 6 Triggered"
|
|
# register_type: read
|
|
# address: 0x0001
|
|
# bitmask: 0x800
|
|
#
|
|
#sensor:
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: z1z4_current
|
|
# name: "Z1Z4 Current"
|
|
# address: 0x0002
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "mA"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
#
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: z2z5_current
|
|
# name: "Z2Z5 Current"
|
|
# address: 0x0006
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "mA"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
#
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: z3z6_current
|
|
# name: "Z3Z6 Current"
|
|
# address: 0x000A
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "mA"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
#
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: z1z4_bus_voltage
|
|
# name: "Z1Z4 Bus Voltage"
|
|
# address: 0x000E
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "V"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
#
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: z2z5_bus_voltage
|
|
# name: "Z2Z5 Bus Voltage"
|
|
# address: 0x0012
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "V"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
#
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: z3z6_bus_voltage
|
|
# name: "Z3Z6 Bus Voltage"
|
|
# address: 0x0016
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "V"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
#
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: z1z4_power
|
|
# name: "Z1Z4 Power"
|
|
# address: 0x001A
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "W"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
#
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: z2z5_power
|
|
# name: "Z2Z5 Power"
|
|
# address: 0x001E
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "W"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
#
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: z3z6_power
|
|
# name: "Z3Z6 Power"
|
|
# address: 0x0022
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "W"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
#
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: z1z4_shunt_voltage
|
|
# name: "Z1Z4 Shunt Voltage"
|
|
# address: 0x0026
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "V"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
#
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: z2z5_shunt_voltage
|
|
# name: "Z2Z5 Shunt Voltage"
|
|
# address: 0x002A
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "V"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
#
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: z3z6_shunt_voltage
|
|
# name: "Z3Z6 Shunt Voltage"
|
|
# address: 0x002E
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "V"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
#
|
|
# - platform: modbus_controller
|
|
# modbus_controller_id: modbus_alarm_client
|
|
# id: alarm_signal
|
|
# name: "Alarm Signal"
|
|
# address: 0x0032
|
|
# register_type: holding
|
|
# value_type: S_WORD
|
|
# register_count: 4
|
|
# unit_of_measurement: "V"
|
|
# lambda: |-
|
|
# return x / 1024.0;
|
|
|
|
script:
|
|
- id: canbus_send_heartbeat
|
|
then:
|
|
lambda: |-
|
|
using namespace solar;
|
|
std::vector<uint8_t> x(cbf_sthome::heartbeat.begin(), cbf_sthome::heartbeat.end());
|
|
id(g_cb_cache).send_frame(id(canbus_sthome), cbf_sthome::CB_CANBUS_ID02, x); |