mirror of
https://github.com/randybb/esphome-configs.git
synced 2026-12-06 01:06:52 +01:00
Compare commits
10
Commits
3d5a77bd13
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3f3d90b2b | ||
|
|
a909041263 | ||
|
|
70d1079ccd | ||
|
|
0f1b32b1ed | ||
|
|
feaa161653 | ||
|
|
8aee65e697 | ||
|
|
0da0cd1544 | ||
|
|
6591b47c01 | ||
|
|
9a158bab19 | ||
|
|
bba78dbb17 |
No files matched your search
@@ -56,7 +56,9 @@ jobs:
|
||||
run: |
|
||||
for f in ${{ steps.changed.outputs.all_changed_files }}; do
|
||||
# Zephyr RTOS platforms need the esphomeplatformzephyr fork, upstream doesn't know them yet
|
||||
if grep -qE '^(nrf|stm32|nxp|renesas|silabs):' "$f"; then echo "Skipping $f (zephyr fork)"; continue; fi
|
||||
# (the platform key may also come from an !include'd package, e.g. common/xiao_stm32c5_canopen.yaml)
|
||||
files="$f $(grep -oE '!include [^ ]+' "$f" | cut -d' ' -f2)"
|
||||
if grep -qsE '^(nrf|stm32|nxp|renesas|silabs):' $files; then echo "Skipping $f (zephyr fork)"; continue; fi
|
||||
echo "Validating $f..."
|
||||
esphome config "$f"
|
||||
done
|
||||
+86
-83
@@ -1,14 +1,7 @@
|
||||
esp32:
|
||||
variant: esp32
|
||||
toolchain: esp-idf
|
||||
framework:
|
||||
advanced:
|
||||
flash_chip: gd # ESP32-PICO-D4, like every other ATOM Lite
|
||||
type: esp-idf
|
||||
|
||||
external_components:
|
||||
- source: components
|
||||
|
||||
# Vehicle iBeacon on an M5Stack ATOM Lite: BLE only, Wi-Fi + OTA by holding the button.
|
||||
# LED: short blue blink at boot, then dark; blue while the home beacon (mcu-gate) is seen;
|
||||
# green while Wi-Fi is on.
|
||||
#
|
||||
# PINOUTS: M5ATOM
|
||||
# IR G12
|
||||
# NEO G27
|
||||
@@ -24,85 +17,95 @@ external_components:
|
||||
# 1-WIRE G22
|
||||
# NC G19
|
||||
|
||||
esp32:
|
||||
variant: esp32
|
||||
toolchain: esp-idf
|
||||
framework:
|
||||
advanced:
|
||||
flash_chip: gd # ESP32-PICO-D4, like every other ATOM Lite
|
||||
type: esp-idf
|
||||
|
||||
# iBeacon on air from boot without the empty standard advertisement every 10 s
|
||||
packages:
|
||||
wifi: !include wifi.yaml
|
||||
|
||||
esphome:
|
||||
on_loop:
|
||||
on_boot:
|
||||
then:
|
||||
lambda: |-
|
||||
static uint32_t last_state = 0;
|
||||
auto state = App.get_app_state();
|
||||
if (state != last_state) {
|
||||
if (state & STATUS_LED_ERROR) {
|
||||
auto call = id(led).turn_on();
|
||||
call.set_effect("ERROR");
|
||||
call.perform();
|
||||
} else if (state & STATUS_LED_WARNING) {
|
||||
auto call = id(led).turn_on();
|
||||
call.set_effect("BOOT");
|
||||
call.perform();
|
||||
} else {
|
||||
auto call = id(led).turn_on();
|
||||
call.set_effect("BEACON");
|
||||
call.perform();
|
||||
}
|
||||
last_state = state;
|
||||
}
|
||||
- light.turn_on:
|
||||
id: led
|
||||
red: 0%
|
||||
green: 0%
|
||||
blue: 50%
|
||||
transition_length: 0s
|
||||
- delay: 300ms
|
||||
- light.turn_off:
|
||||
id: led
|
||||
transition_length: 0s
|
||||
|
||||
wifi:
|
||||
enable_on_boot: false
|
||||
|
||||
# flashed over USB straight to encrypted OTA, no password migration needed
|
||||
ota:
|
||||
- platform: esphome
|
||||
encryption:
|
||||
key: !secret api_key
|
||||
|
||||
esp32_ble_tracker:
|
||||
scan_parameters:
|
||||
active: false
|
||||
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
id: button
|
||||
pin:
|
||||
number: 39
|
||||
inverted: true
|
||||
on_press:
|
||||
- delay: 3s
|
||||
- if:
|
||||
condition:
|
||||
binary_sensor.is_on: button
|
||||
then:
|
||||
- wifi.enable:
|
||||
- light.turn_on:
|
||||
id: led
|
||||
red: 0%
|
||||
green: 50%
|
||||
blue: 0%
|
||||
transition_length: 0s
|
||||
- platform: ble_presence
|
||||
id: home
|
||||
ibeacon_uuid: !secret ble_beacon_gate_uuid
|
||||
timeout: 1min
|
||||
on_press:
|
||||
- if:
|
||||
condition:
|
||||
not:
|
||||
wifi.enabled:
|
||||
then:
|
||||
- light.turn_on:
|
||||
id: led
|
||||
red: 0%
|
||||
green: 0%
|
||||
blue: 50%
|
||||
transition_length: 0s
|
||||
on_release:
|
||||
- if:
|
||||
condition:
|
||||
not:
|
||||
wifi.enabled:
|
||||
then:
|
||||
- light.turn_off:
|
||||
id: led
|
||||
transition_length: 0s
|
||||
|
||||
light:
|
||||
- platform: esp32_rmt_led_strip
|
||||
name: LED
|
||||
id: led
|
||||
rgb_order: GRB
|
||||
channel_colors: GRB
|
||||
pin: 27
|
||||
num_leds: 1
|
||||
chipset: ws2812
|
||||
restore_mode: ALWAYS_OFF
|
||||
effects:
|
||||
- strobe:
|
||||
name: "BEACON"
|
||||
colors:
|
||||
- state: true
|
||||
red: 0%
|
||||
green: 0%
|
||||
blue: 50%
|
||||
duration: 200ms
|
||||
- state: false
|
||||
duration: 200ms
|
||||
- state: true
|
||||
red: 0%
|
||||
green: 0%
|
||||
blue: 50%
|
||||
duration: 200ms
|
||||
- state: false
|
||||
duration: 10s
|
||||
- lambda:
|
||||
name: "ERROR"
|
||||
update_interval: 0.5s
|
||||
lambda: |-
|
||||
static bool state = false;
|
||||
auto call = id(led).turn_on();
|
||||
call.set_transition_length(500);
|
||||
call.set_rgb(1, 0, 0);
|
||||
if (!state) {
|
||||
call.set_brightness(1);
|
||||
} else {
|
||||
// If using 0, it freaks Home Assistant UI.
|
||||
call.set_brightness(0.01);
|
||||
}
|
||||
call.perform();
|
||||
state = !state;
|
||||
- lambda:
|
||||
name: "BOOT"
|
||||
update_interval: 0.5s
|
||||
lambda: |-
|
||||
static bool state = false;
|
||||
auto call = id(led).turn_on();
|
||||
call.set_transition_length(500);
|
||||
call.set_rgb(0, 1, 0);
|
||||
if (!state) {
|
||||
call.set_brightness(1);
|
||||
} else {
|
||||
// If using 0, it freaks Home Assistant UI.
|
||||
call.set_brightness(0.01);
|
||||
}
|
||||
call.perform();
|
||||
state = !state;
|
||||
@@ -28,6 +28,8 @@ logger:
|
||||
logs:
|
||||
# canbus logs every frame at DEBUG; over USB CDC that stalls the loop and the RX queue overflows
|
||||
canbus: INFO
|
||||
# the same for pitch/roll every 200 ms
|
||||
sensor: INFO
|
||||
|
||||
i2c:
|
||||
# pins come from the board DTS (i2c2: PB3/PB4), STM32C5 takes no sda:/scl:
|
||||
@@ -39,22 +41,69 @@ motion:
|
||||
id: imu
|
||||
i2c_id: i2c_imu
|
||||
address: 0x6A
|
||||
update_interval: 5s
|
||||
# a live inclinometer (maptool's dashboard / Terrain view) needs 100-200 ms
|
||||
update_interval: 200ms
|
||||
|
||||
sensor:
|
||||
- platform: lsm6ds
|
||||
id: imu_temp
|
||||
name: IMU Temperature
|
||||
# Levelled by the node itself (the mounting error belongs to the sensor, every reader of the bus gets it
|
||||
# corrected): raw = state + offset, so levelling again adds to the offsets
|
||||
- platform: motion
|
||||
motion_id: imu
|
||||
id: pitch
|
||||
type: pitch
|
||||
name: Pitch
|
||||
filters:
|
||||
- lambda: return x - id(pitch_offset).state;
|
||||
- platform: motion
|
||||
motion_id: imu
|
||||
id: roll
|
||||
type: roll
|
||||
name: Roll
|
||||
filters:
|
||||
- lambda: return x - id(roll_offset).state;
|
||||
|
||||
number:
|
||||
- platform: template
|
||||
id: pitch_offset
|
||||
name: Pitch Offset
|
||||
entity_category: config
|
||||
unit_of_measurement: "°"
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: 0
|
||||
min_value: -45
|
||||
max_value: 45
|
||||
step: 0.01
|
||||
- platform: template
|
||||
id: roll_offset
|
||||
name: Roll Offset
|
||||
entity_category: config
|
||||
unit_of_measurement: "°"
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: 0
|
||||
min_value: -45
|
||||
max_value: 45
|
||||
step: 0.01
|
||||
|
||||
# canopen_entities has no button: a switch that turns itself back off. On uneven ground: level, turn the car
|
||||
# 180° on the same spot, level again and take the mean (maptool writes the offsets for that)
|
||||
switch:
|
||||
- platform: template
|
||||
id: level_imu
|
||||
name: Level IMU
|
||||
entity_category: config
|
||||
lambda: return false;
|
||||
turn_on_action:
|
||||
- lambda: |-
|
||||
if (std::isnan(id(pitch).state) || std::isnan(id(roll).state))
|
||||
return;
|
||||
id(pitch_offset).make_call().set_value(id(pitch_offset).state + id(pitch).state).perform();
|
||||
id(roll_offset).make_call().set_value(id(roll_offset).state + id(roll).state).perform();
|
||||
ESP_LOGI("level", "levelled: pitch offset %.2f, roll offset %.2f", id(pitch_offset).state, id(roll_offset).state);
|
||||
|
||||
output:
|
||||
- platform: gpio
|
||||
@@ -80,11 +129,12 @@ canbus:
|
||||
# an SDO block (16 frames) arrives back to back and must fit the RX queue (default 8)
|
||||
rx_buffer_size: 32
|
||||
|
||||
# a list, so a node file can add a second local node (e.g. a PKP keypad emulation)
|
||||
canopen:
|
||||
id: can_gate
|
||||
canbus_id: can_bus
|
||||
node_id: ${node_id}
|
||||
heartbeat_interval: 5s
|
||||
- id: can_gate
|
||||
canbus_id: can_bus
|
||||
node_id: ${node_id}
|
||||
heartbeat_interval: 5s
|
||||
|
||||
canopen_entities:
|
||||
canopen_id: can_gate
|
||||
@@ -111,11 +161,20 @@ canopen_entities:
|
||||
size: 2
|
||||
min_value: -40
|
||||
max_value: 125
|
||||
# levelling (maptool /can.html): Level IMU = SDO 0x2022:1 <- 1; offsets REAL32, state 0x2101 / 0x2111,
|
||||
# command 0x2102:1 / 0x2112:1. 16/17: the nodes' own entities are 6..15
|
||||
- id: level_imu
|
||||
index: 2
|
||||
- id: pitch_offset
|
||||
index: 16
|
||||
- id: roll_offset
|
||||
index: 17
|
||||
remote_logs:
|
||||
level: INFO
|
||||
|
||||
ota:
|
||||
- platform: canopen_entities
|
||||
canopen_id: can_gate
|
||||
# the XIAO's board layout has slot0 one sector larger than slot1 (swap-move); with the fork's default
|
||||
# (offset) MCUboot finds the slots incompatible and never installs the update
|
||||
swap_method: move
|
||||
|
||||
@@ -79,6 +79,10 @@ external_components:
|
||||
- source: github://randybb/esphome-components
|
||||
components: [m5stack_keyboard]
|
||||
refresh: 1h
|
||||
# TEMP: esphome#23831 (OTA over CANopen, CiA 302-3); drop once merged
|
||||
- source: github://pr#23831
|
||||
components: [canopen]
|
||||
refresh: 1h
|
||||
|
||||
packages:
|
||||
common: !include common/common.yaml
|
||||
@@ -88,6 +92,11 @@ packages:
|
||||
vars:
|
||||
light_id: status_frame
|
||||
|
||||
logger:
|
||||
logs:
|
||||
# canbus logs every frame at DEBUG, which slows the loop during SDO block transfers
|
||||
canbus: INFO
|
||||
|
||||
i2c:
|
||||
- id: i2c_grove
|
||||
sda: 2
|
||||
@@ -105,6 +114,8 @@ canbus:
|
||||
tx_pin: 5
|
||||
can_id: 3
|
||||
bit_rate: 500kbps
|
||||
# IDF default is 5 frames; an SDO block (16 segments in ~8 ms) overflowed it (EMCY 0x8110, partial block acks)
|
||||
rx_queue_len: 32
|
||||
|
||||
canopen:
|
||||
- id: can_open
|
||||
@@ -150,6 +161,10 @@ script:
|
||||
uint8_t d[5] = {0, 0, 0, 0, (uint8_t) (millis() / 100)};
|
||||
id(pkp).send_frame(0x195, d, sizeof(d));
|
||||
|
||||
ota:
|
||||
- platform: canopen
|
||||
canopen_id: can_open
|
||||
|
||||
# CardKB sends only the press (Shift/Sym/Fn resolved in the CardKB): a consumer reacts to a change of key_count
|
||||
# and reads the key from key_code (both in the same frame), or watches key_event alone (count % 255 << 8 | key)
|
||||
canopen_entities:
|
||||
|
||||
+36
-53
@@ -24,14 +24,18 @@ esp32:
|
||||
type: esp-idf
|
||||
|
||||
external_components:
|
||||
- source: github://mrk-its/esphome-canopen@dev
|
||||
refresh: 1h
|
||||
- source: github://mrk-its/esphome-canbus-udp-multicast@dev
|
||||
- source: github://mrk-its/esphome-canopen@canopen_entities
|
||||
components: [canopen_entities]
|
||||
refresh: 1h
|
||||
|
||||
packages:
|
||||
common: !include common/common.yaml
|
||||
|
||||
logger:
|
||||
logs:
|
||||
# canbus logs every frame at DEBUG, which slows the loop during SDO block transfers
|
||||
canbus: INFO
|
||||
|
||||
canbus:
|
||||
- platform: esp32_can
|
||||
id: can_bus
|
||||
@@ -39,57 +43,29 @@ canbus:
|
||||
tx_pin: 23
|
||||
can_id: 1
|
||||
bit_rate: 500kbps
|
||||
# IDF default is 5 frames; an SDO block (16 segments in ~8 ms) overflowed it (EMCY 0x8110, partial block acks)
|
||||
rx_queue_len: 32
|
||||
|
||||
canopen:
|
||||
id: can_open
|
||||
canbus_id: can_bus
|
||||
node_id: 1
|
||||
entities:
|
||||
- index: 1
|
||||
id: light1_state
|
||||
rpdo:
|
||||
- node_id: 2
|
||||
tpdo: 0
|
||||
offset: 0
|
||||
cmd: 0
|
||||
|
||||
- index: 2
|
||||
id: light1_brightness
|
||||
size: 1
|
||||
min_value: 0.0
|
||||
max_value: 1.0
|
||||
rpdo:
|
||||
- node_id: 2
|
||||
tpdo: 0
|
||||
offset: 1
|
||||
cmd: 0
|
||||
|
||||
- index: 3
|
||||
id: light2_state
|
||||
rpdo:
|
||||
- node_id: 2
|
||||
tpdo: 0
|
||||
offset: 3
|
||||
cmd: 0
|
||||
|
||||
- index: 4
|
||||
id: light2_brightness
|
||||
size: 1
|
||||
min_value: 0.0
|
||||
max_value: 1.0
|
||||
rpdo:
|
||||
- node_id: 2
|
||||
tpdo: 0
|
||||
offset: 4
|
||||
cmd: 0
|
||||
canopen_entities:
|
||||
remote_nodes:
|
||||
node2: mcu-can-node-2.yaml
|
||||
|
||||
binary_sensor:
|
||||
- platform: template
|
||||
- platform: canopen_entities
|
||||
id: light1_state
|
||||
name: Light 1 State
|
||||
- platform: template
|
||||
node: node2
|
||||
entity: light1
|
||||
- platform: canopen_entities
|
||||
id: light2_state
|
||||
name: Light 2 State
|
||||
node: node2
|
||||
entity: light2
|
||||
|
||||
- platform: template
|
||||
id: light1_state_cmd
|
||||
@@ -105,26 +81,33 @@ binary_sensor:
|
||||
pullup: true
|
||||
on_press:
|
||||
then:
|
||||
- lambda: |-
|
||||
bool state = id(light1_state).state || id(light2_state).state;
|
||||
|
||||
// send command to entity #1 (light) on node #2
|
||||
id(can_open).send_entity_cmd(2, 1, !state);
|
||||
|
||||
// send command to entity #2 (light2) on node #2
|
||||
id(can_open).send_entity_cmd(2, 2, !state);
|
||||
# both lights on node 2 off if either is on, otherwise both on
|
||||
- if:
|
||||
condition:
|
||||
lambda: return id(light1_state).state || id(light2_state).state;
|
||||
then:
|
||||
- canopen_entities.light.turn_off: {node: node2, entity: light1}
|
||||
- canopen_entities.light.turn_off: {node: node2, entity: light2}
|
||||
else:
|
||||
- canopen_entities.light.turn_on: {node: node2, entity: light1}
|
||||
- canopen_entities.light.turn_on: {node: node2, entity: light2}
|
||||
|
||||
sensor:
|
||||
- platform: template
|
||||
- platform: canopen_entities
|
||||
id: light1_brightness
|
||||
name: Light 1 Brightness
|
||||
- platform: template
|
||||
node: node2
|
||||
entity: light1
|
||||
state: brightness
|
||||
- platform: canopen_entities
|
||||
id: light2_brightness
|
||||
name: Light 2 Brightness
|
||||
node: node2
|
||||
entity: light2
|
||||
state: brightness
|
||||
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: LED
|
||||
id: blue_led
|
||||
internal: true
|
||||
pin: 2
|
||||
+11
-3
@@ -28,14 +28,18 @@ esp32:
|
||||
type: esp-idf
|
||||
|
||||
external_components:
|
||||
- source: github://mrk-its/esphome-canopen@dev
|
||||
refresh: 1h
|
||||
- source: github://mrk-its/esphome-canbus-udp-multicast@dev
|
||||
- source: github://mrk-its/esphome-canopen@canopen_entities
|
||||
components: [canopen_entities]
|
||||
refresh: 1h
|
||||
|
||||
packages:
|
||||
common: !include common/common.yaml
|
||||
|
||||
logger:
|
||||
logs:
|
||||
# canbus logs every frame at DEBUG, which slows the loop during SDO block transfers
|
||||
canbus: INFO
|
||||
|
||||
canbus:
|
||||
- platform: esp32_can
|
||||
id: can_bus
|
||||
@@ -43,11 +47,15 @@ canbus:
|
||||
tx_pin: 23
|
||||
can_id: 2
|
||||
bit_rate: 500kbps
|
||||
# IDF default is 5 frames; an SDO block (16 segments in ~8 ms) overflowed it (EMCY 0x8110, partial block acks)
|
||||
rx_queue_len: 32
|
||||
|
||||
canopen:
|
||||
id: can_open
|
||||
canbus_id: can_bus
|
||||
node_id: 2
|
||||
|
||||
canopen_entities:
|
||||
entities:
|
||||
- index: 1
|
||||
id: light1
|
||||
|
||||
@@ -34,6 +34,7 @@ esp32:
|
||||
flash_chip: gd
|
||||
type: esp-idf
|
||||
|
||||
# iBeacon on air from boot without the empty standard advertisement every 10 s
|
||||
packages:
|
||||
common: !include common/common.yaml
|
||||
ipv6_only: !include common/ipv6_only.yaml
|
||||
@@ -107,8 +108,20 @@ globals:
|
||||
|
||||
esp32_ble_tracker:
|
||||
id: ${device}_ble_tracker
|
||||
# window 160/320 ms (default 30): hears the vehicle beacons sooner, half the airtime stays for Wi-Fi
|
||||
scan_parameters:
|
||||
duration: 1min
|
||||
interval: 320ms
|
||||
window: 160ms
|
||||
active: false
|
||||
|
||||
# home beacon: the vehicles light their LED while they see it
|
||||
esp32_ble_beacon:
|
||||
type: iBeacon
|
||||
uuid: !secret ble_beacon_gate_uuid
|
||||
min_interval: 1s
|
||||
max_interval: 1s
|
||||
tx_power: 9dBm
|
||||
|
||||
binary_sensor:
|
||||
- platform: ble_presence
|
||||
|
||||
+13
-5
@@ -1,11 +1,11 @@
|
||||
---
|
||||
# Hardware: M5StickC Plus + Hat CardKB + Hat Mini JoyC on the hat header, Unit CAN on Grove
|
||||
# Hardware: M5StickC Plus + Hat CardKB + Hat Mini JoyC on the hat header, TJA1050 CAN module on Grove
|
||||
# CANopen keypad + joystick (node 4), canopen from ESPHome dev + canopen_entities
|
||||
# Pinout:
|
||||
# GPIO0 hat SDA -> i2c_hat (i2c sda)
|
||||
# GPIO26 hat SCL -> i2c_hat (i2c scl)
|
||||
# GPIO32 Grove -> can_bus (canbus esp32_can tx_pin), swap with rx if the node stays silent
|
||||
# GPIO33 Grove -> can_bus (canbus esp32_can rx_pin)
|
||||
# GPIO32 Grove -> can_bus (canbus esp32_can rx_pin), TJA1050 module RX
|
||||
# GPIO33 Grove -> can_bus (canbus esp32_can tx_pin), TJA1050 module TX
|
||||
# GPIO21 internal SDA -> i2c_axp (i2c sda)
|
||||
# GPIO22 internal SCL -> i2c_axp (i2c scl)
|
||||
# GPIO10 red LED (active low) -> LED (light binary)
|
||||
@@ -107,13 +107,21 @@ m5stack_mini_joyc:
|
||||
id: joy_button
|
||||
name: Joystick Button
|
||||
|
||||
logger:
|
||||
logs:
|
||||
# canbus logs every frame at DEBUG, which slows the loop during SDO block transfers
|
||||
canbus: INFO
|
||||
|
||||
canbus:
|
||||
- platform: esp32_can
|
||||
id: can_bus
|
||||
tx_pin: 32
|
||||
rx_pin: 33
|
||||
tx_pin: 33
|
||||
rx_pin: 32
|
||||
can_id: 4
|
||||
bit_rate: 500kbps
|
||||
mode: LISTENONLY # TEMP: the node does not see the bus on RX (GPIO32), keep it off the bus
|
||||
# IDF default is 5 frames; an SDO block (16 segments in ~8 ms) overflowed it (EMCY 0x8110, partial block acks)
|
||||
rx_queue_len: 32
|
||||
|
||||
canopen:
|
||||
- id: can_open
|
||||
|
||||
+243
-151
@@ -56,6 +56,16 @@ esphome:
|
||||
- priority: 700
|
||||
then:
|
||||
- script.execute: bus_power_on
|
||||
# pitch end stops into the servo's own angle limits (no EEPROM unlock: until the next power cycle)
|
||||
- priority: -100
|
||||
then:
|
||||
- delay: 2s
|
||||
- lambda: |-
|
||||
auto *bus = id(y_servo).get_parent();
|
||||
bus->write_word(2, SCSCL_MIN_ANGLE_LIMIT_L, 645);
|
||||
bus->write_word(2, SCSCL_MAX_ANGLE_LIMIT_L, 912);
|
||||
ESP_LOGI("pitch", "Angle limits %d..%d", bus->read_word(2, SCSCL_MIN_ANGLE_LIMIT_L),
|
||||
bus->read_word(2, SCSCL_MAX_ANGLE_LIMIT_L));
|
||||
- priority: -100
|
||||
then:
|
||||
- light.turn_on:
|
||||
@@ -75,6 +85,11 @@ esp32:
|
||||
advanced:
|
||||
flash_chip: generic
|
||||
type: esp-idf
|
||||
sdkconfig_options:
|
||||
# per-task CPU time for the task_stats interval
|
||||
CONFIG_FREERTOS_USE_TRACE_FACILITY: y
|
||||
CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS: y
|
||||
CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID: y
|
||||
|
||||
psram:
|
||||
mode: quad
|
||||
@@ -89,7 +104,7 @@ external_components:
|
||||
components: [axp2101, aw88298, aw9523b, si12t, ftservo, scs9009]
|
||||
refresh: 0s
|
||||
- source: github://randybb/esphome-components
|
||||
components: [audio_spectrum, m5ioe1]
|
||||
components: [audio_spectrum, m5ioe1, robot_face]
|
||||
refresh: 1h
|
||||
# st25r upstream has SPI only, st25r_i2c is still on this branch
|
||||
- source: github://m5stack/esphome@feat-st25r3916
|
||||
@@ -97,38 +112,17 @@ external_components:
|
||||
refresh: 1d
|
||||
|
||||
globals:
|
||||
- id: in_love
|
||||
type: bool
|
||||
initial_value: 'false'
|
||||
- id: show_status
|
||||
type: bool
|
||||
initial_value: 'true'
|
||||
- id: mouth_open
|
||||
type: float
|
||||
initial_value: '0.0'
|
||||
- id: eyes_open
|
||||
type: bool
|
||||
initial_value: 'true'
|
||||
- id: speaking
|
||||
type: bool
|
||||
initial_value: 'false'
|
||||
- id: listening
|
||||
type: bool
|
||||
initial_value: 'false'
|
||||
- id: gaze_x
|
||||
type: int
|
||||
initial_value: '0'
|
||||
- id: gaze_y
|
||||
type: int
|
||||
initial_value: '0'
|
||||
- id: dizzy
|
||||
type: bool
|
||||
initial_value: 'false'
|
||||
- id: surprised
|
||||
type: bool
|
||||
initial_value: 'false'
|
||||
- id: speech
|
||||
type: std::string
|
||||
- id: spin_limits # yaw servo angle limits while spinning: max << 16 | min
|
||||
type: int
|
||||
initial_value: '0'
|
||||
|
||||
i2c:
|
||||
- id: i2c_bsp
|
||||
@@ -311,7 +305,6 @@ media_player:
|
||||
- platform: speaker
|
||||
id: media_out
|
||||
name: Player
|
||||
buffer_size: 14000
|
||||
# AW88298 maps volume linearly to -96..0 dB, the lower half is inaudible
|
||||
volume_min: 0.5
|
||||
volume_max: 1.0
|
||||
@@ -360,27 +353,33 @@ voice_assistant:
|
||||
- lambda: id(show_status) = true;
|
||||
- component.update: display_tft
|
||||
on_listening:
|
||||
# someone talks: a look with one eye, then with both
|
||||
- lambda: |-
|
||||
id(listening) = true;
|
||||
id(gaze_x) = 0;
|
||||
id(gaze_y) = 0;
|
||||
id(face).peek(0);
|
||||
id(face).look(0, 0);
|
||||
- component.update: display_tft
|
||||
- light.turn_on: {id: light_bar, brightness: 60%, red: 0%, green: 60%, blue: 100%}
|
||||
on_stt_end:
|
||||
- lambda: id(listening) = false;
|
||||
# thinking: looks up to the side
|
||||
- lambda: |-
|
||||
id(listening) = false;
|
||||
id(face).look(0.6f, -0.8f);
|
||||
- component.update: display_tft
|
||||
- light.turn_on: {id: light_bar, brightness: 40%, red: 80%, green: 50%, blue: 0%}
|
||||
on_tts_start:
|
||||
- lambda: id(speaking) = true;
|
||||
- lambda: |-
|
||||
id(face).look(0, 0);
|
||||
id(face).set_speaking(true);
|
||||
- light.turn_on: {id: light_bar, brightness: 60%, red: 0%, green: 100%, blue: 20%}
|
||||
on_end:
|
||||
- wait_until:
|
||||
not:
|
||||
media_player.is_announcing: media_out
|
||||
- lambda: |-
|
||||
id(speaking) = false;
|
||||
id(listening) = false;
|
||||
id(mouth_open) = 0.0f;
|
||||
id(face).set_speaking(false);
|
||||
id(face).set_idle(true);
|
||||
- component.update: display_tft
|
||||
- light.turn_on: {id: light_bar, brightness: 20%, red: 0%, green: 0%, blue: 100%}
|
||||
- wait_until:
|
||||
@@ -388,6 +387,10 @@ voice_assistant:
|
||||
- micro_wake_word.start:
|
||||
on_error:
|
||||
- light.turn_on: {id: light_bar, brightness: 60%, red: 100%, green: 0%, blue: 0%}
|
||||
- script.execute:
|
||||
id: show_mood
|
||||
mood: sad
|
||||
seconds: 3
|
||||
|
||||
script:
|
||||
# Powers the 5 V BUS from the battery (as in m5stack/esphome-yaml stackchan base).
|
||||
@@ -411,24 +414,53 @@ script:
|
||||
}
|
||||
id(bus_out_en).turn_on();
|
||||
delay(100);
|
||||
# shake: dizzy eyes for a while
|
||||
- id: shake_reaction
|
||||
# a mood for a while, then back to neutral (stroke: love, shake: dizzy, card: surprised)
|
||||
- id: show_mood
|
||||
mode: restart
|
||||
parameters:
|
||||
mood: string
|
||||
seconds: int
|
||||
then:
|
||||
- lambda: id(dizzy) = true;
|
||||
- component.update: display_tft
|
||||
- delay: 3s
|
||||
- lambda: id(dizzy) = false;
|
||||
- component.update: display_tft
|
||||
# a card laid on the head: big round eyes and an O mouth
|
||||
- id: surprise_reaction
|
||||
mode: restart
|
||||
- lambda: |-
|
||||
if (id(face).is_sleeping())
|
||||
id(face).peek(0);
|
||||
id(face).set_mood(mood);
|
||||
- delay: !lambda return seconds * 1000;
|
||||
- lambda: id(face).set_mood(robot_face::MOOD_NEUTRAL);
|
||||
# spins the head around (yaw servo, address 1) in wheel mode: angle limits 0/0 turn the SCS9009
|
||||
# into a motor driven by PWM. The limits are written without unlocking the EEPROM, so they are
|
||||
# only changed until the next power cycle, and they are put back once the spin is over.
|
||||
- id: spin
|
||||
mode: single
|
||||
parameters:
|
||||
seconds: float
|
||||
power: int # -1000..1000, the sign is the direction
|
||||
then:
|
||||
- lambda: id(surprised) = true;
|
||||
- component.update: display_tft
|
||||
- delay: 3s
|
||||
- lambda: id(surprised) = false;
|
||||
- component.update: display_tft
|
||||
- lambda: |-
|
||||
auto *bus = id(x_servo).get_parent();
|
||||
const int min = bus->read_word(1, SCSCL_MIN_ANGLE_LIMIT_L);
|
||||
const int max = bus->read_word(1, SCSCL_MAX_ANGLE_LIMIT_L);
|
||||
if (min < 0 || max <= 0) {
|
||||
ESP_LOGW("spin", "Angle limits not readable (%d/%d), not spinning", min, max);
|
||||
return;
|
||||
}
|
||||
id(spin_limits) = (max << 16) | min;
|
||||
ESP_LOGI("spin", "Spinning %.1f s at %d, limits %d..%d", seconds, power, min, max);
|
||||
bus->enable_torque(1, 1);
|
||||
bus->pwm_mode(1);
|
||||
bus->write_pwm(1, clamp(power, -1000, 1000));
|
||||
id(face).set_mood(robot_face::MOOD_DIZZY);
|
||||
- delay: !lambda return (uint32_t) (seconds * 1000);
|
||||
- lambda: |-
|
||||
auto *bus = id(x_servo).get_parent();
|
||||
bus->write_pwm(1, 0);
|
||||
bus->enable_torque(1, 0);
|
||||
// position mode again; torque is off, so the old goal position does not pull the head back
|
||||
bus->write_word(1, SCSCL_MIN_ANGLE_LIMIT_L, id(spin_limits) & 0xFFFF);
|
||||
bus->write_word(1, SCSCL_MAX_ANGLE_LIMIT_L, id(spin_limits) >> 16);
|
||||
ESP_LOGI("spin", "Stopped, limits back to %d..%d", id(spin_limits) & 0xFFFF, id(spin_limits) >> 16);
|
||||
- delay: 2s
|
||||
- lambda: id(face).set_mood(robot_face::MOOD_NEUTRAL);
|
||||
# text under the face with the mouth moving
|
||||
- id: say
|
||||
mode: restart
|
||||
@@ -437,22 +469,11 @@ script:
|
||||
then:
|
||||
- lambda: |-
|
||||
id(speech) = message;
|
||||
id(speaking) = true;
|
||||
- component.update: display_tft
|
||||
id(face).set_speaking(true);
|
||||
- delay: 8s
|
||||
- lambda: |-
|
||||
id(speech).clear();
|
||||
id(speaking) = false;
|
||||
- component.update: display_tft
|
||||
# stroking the head shows the in-love face for a while
|
||||
- id: head_stroke
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: id(in_love) = true;
|
||||
- component.update: display_tft
|
||||
- delay: 5s
|
||||
- lambda: id(in_love) = false;
|
||||
- component.update: display_tft
|
||||
id(face).set_speaking(false);
|
||||
# mic and speaker share one I2S bus - the mic must be released before playback
|
||||
- id: release_i2s_bus
|
||||
mode: single
|
||||
@@ -475,6 +496,41 @@ script:
|
||||
timeout: 2s
|
||||
|
||||
interval:
|
||||
# CPU time of every task over the last 10 s (100 % = one core), busiest first
|
||||
- interval: 10s
|
||||
then:
|
||||
- lambda: |-
|
||||
struct Prev { std::string name; uint64_t run; };
|
||||
static std::vector<Prev> prev;
|
||||
static uint64_t prev_total = 0;
|
||||
std::vector<TaskStatus_t> tasks(uxTaskGetNumberOfTasks() + 4);
|
||||
configRUN_TIME_COUNTER_TYPE total;
|
||||
tasks.resize(uxTaskGetSystemState(tasks.data(), tasks.size(), &total));
|
||||
const uint64_t span = total - prev_total;
|
||||
struct Row { const TaskStatus_t *t; uint64_t delta; };
|
||||
std::vector<Row> rows;
|
||||
std::vector<Prev> now;
|
||||
for (auto &t : tasks) {
|
||||
uint64_t before = 0;
|
||||
for (auto &p : prev)
|
||||
if (p.name == t.pcTaskName)
|
||||
before = p.run;
|
||||
rows.push_back({&t, t.ulRunTimeCounter - before});
|
||||
now.push_back({t.pcTaskName, t.ulRunTimeCounter});
|
||||
}
|
||||
const bool first = prev_total == 0;
|
||||
prev = std::move(now);
|
||||
prev_total = total;
|
||||
if (first || span == 0)
|
||||
return;
|
||||
std::sort(rows.begin(), rows.end(), [](const Row &a, const Row &b) { return a.delta > b.delta; });
|
||||
for (auto &r : rows) {
|
||||
const float pct = 100.0f * r.delta / span;
|
||||
if (pct < 0.5f)
|
||||
break;
|
||||
ESP_LOGI("task_stats", "%-16s core %2d prio %2u %5.1f %%", r.t->pcTaskName,
|
||||
r.t->xCoreID == tskNO_AFFINITY ? -1 : (int) r.t->xCoreID, (unsigned) r.t->uxCurrentPriority, pct);
|
||||
}
|
||||
- interval: 80ms # spectrum analyzer frame rate while music plays
|
||||
then:
|
||||
- if:
|
||||
@@ -544,7 +600,7 @@ interval:
|
||||
first_on[1] ? (int) (first_on[1] - earliest) : -1, first_on[2] ? (int) (first_on[2] - earliest) : -1);
|
||||
|
||||
if (pads >= 2 && spread >= 150 && duration >= 400) {
|
||||
id(head_stroke).execute();
|
||||
id(show_mood).execute(std::string("love"), 5);
|
||||
}
|
||||
- interval: 1s # status screen refresh until Home Assistant connects
|
||||
then:
|
||||
@@ -553,32 +609,6 @@ interval:
|
||||
lambda: return id(show_status);
|
||||
then:
|
||||
- component.update: display_tft
|
||||
- interval: 90ms
|
||||
then:
|
||||
- lambda: |-
|
||||
if (id(speaking)) {
|
||||
id(mouth_open) = 0.15f + (esp_random() % 85) / 100.0f;
|
||||
id(display_tft).update();
|
||||
} else if (id(mouth_open) > 0) {
|
||||
id(mouth_open) = 0;
|
||||
id(display_tft).update();
|
||||
}
|
||||
- interval: 3s # blinking
|
||||
then:
|
||||
- delay: !lambda return esp_random() % 3000;
|
||||
- lambda: id(eyes_open) = false;
|
||||
- component.update: display_tft
|
||||
- delay: 150ms
|
||||
- lambda: id(eyes_open) = true;
|
||||
- component.update: display_tft
|
||||
- interval: 7s # looking around while idle
|
||||
then:
|
||||
- lambda: |-
|
||||
if (!id(speaking) && !id(listening)) {
|
||||
id(gaze_x) = (int) (esp_random() % 21) - 10;
|
||||
id(gaze_y) = (int) (esp_random() % 11) - 5;
|
||||
id(display_tft).update();
|
||||
}
|
||||
|
||||
spi:
|
||||
- id: spi_bus
|
||||
@@ -706,30 +736,26 @@ display:
|
||||
return;
|
||||
}
|
||||
|
||||
// stack-chan face: 2 eyes + mouth, 320x240
|
||||
// stack-chan face (robot_face), 320x240
|
||||
// the whole screen is cleared only once, then just the face areas, so that only the
|
||||
// changed region is sent over SPI instead of the whole 150 kB buffer
|
||||
const bool love = id(in_love);
|
||||
const bool music = id(media_out).state == media_player::MEDIA_PLAYER_STATE_PLAYING && !id(va).is_running();
|
||||
// switching between face, in-love face and spectrum repaints everything
|
||||
static int last_mode = -1;
|
||||
const int mode = music ? 2 : love ? 1 : 0;
|
||||
if (mode != last_mode) {
|
||||
last_mode = mode;
|
||||
// switching between face and spectrum repaints everything
|
||||
static bool last_music = false;
|
||||
if (music != last_music) {
|
||||
last_music = music;
|
||||
first_draw = true;
|
||||
}
|
||||
|
||||
// the in-love face is drawn outside the partially cleared areas, so it always repaints everything
|
||||
static bool spectrum_reset = true;
|
||||
if (first_draw || love) {
|
||||
if (first_draw) {
|
||||
it.fill(id(face_bg));
|
||||
id(face).invalidate();
|
||||
first_draw = false;
|
||||
bar_drawn = false;
|
||||
spectrum_reset = true;
|
||||
} else if (!music) {
|
||||
it.filled_rectangle(66, 74, 189, 39, id(face_bg)); // eyes including gaze range and surprised eyes
|
||||
it.filled_rectangle(105, 130, 111, 38, id(face_bg)); // mouth
|
||||
it.filled_rectangle(0, 184, 320, 30, id(face_bg)); // speech text
|
||||
it.filled_rectangle(0, 216, 320, 22, id(face_bg)); // speech text
|
||||
if (dot_shown && !id(listening)) {
|
||||
it.filled_rectangle(254, 2, 28, 28, id(face_bg));
|
||||
}
|
||||
@@ -822,59 +848,33 @@ display:
|
||||
return;
|
||||
}
|
||||
|
||||
const int ex = id(gaze_x), ey = id(gaze_y);
|
||||
const int eye_y = 93 + ey, eye_r = 8;
|
||||
const int lx = 90 + ex, rx = 230 + ex;
|
||||
|
||||
if (love) {
|
||||
// heart eyes, blush and a wide smile
|
||||
for (int cx : {lx, rx}) {
|
||||
it.filled_circle(cx - 6, eye_y - 3, 7, id(love_red));
|
||||
it.filled_circle(cx + 6, eye_y - 3, 7, id(love_red));
|
||||
it.filled_triangle(cx - 13, eye_y - 1, cx + 13, eye_y - 1, cx, eye_y + 14, id(love_red));
|
||||
}
|
||||
it.filled_circle(60 + ex, 130 + ey, 12, Color(90, 20, 40));
|
||||
it.filled_circle(260 + ex, 130 + ey, 12, Color(90, 20, 40));
|
||||
if (!id(speaking)) {
|
||||
it.filled_circle(160 + ex / 2, 132 + ey / 2, 30, id(face_fg));
|
||||
it.filled_circle(160 + ex / 2, 122 + ey / 2, 30, id(face_bg));
|
||||
}
|
||||
} else if (id(surprised)) {
|
||||
it.filled_circle(lx, eye_y, 11, id(face_fg));
|
||||
it.filled_circle(rx, eye_y, 11, id(face_fg));
|
||||
} else if (id(dizzy)) {
|
||||
// X eyes, 3 px thick
|
||||
for (int cx : {lx, rx})
|
||||
for (int d = -1; d <= 1; d++) {
|
||||
it.line(cx - 9 + d, eye_y - 9, cx + 9 + d, eye_y + 9, id(face_fg));
|
||||
it.line(cx - 9 + d, eye_y + 9, cx + 9 + d, eye_y - 9, id(face_fg));
|
||||
}
|
||||
} else if (id(eyes_open)) {
|
||||
it.filled_circle(lx, eye_y, eye_r, id(face_fg));
|
||||
it.filled_circle(rx, eye_y, eye_r, id(face_fg));
|
||||
} else {
|
||||
it.filled_rectangle(lx - eye_r, eye_y - 2, eye_r * 2, 4, id(face_fg));
|
||||
it.filled_rectangle(rx - eye_r, eye_y - 2, eye_r * 2, 4, id(face_fg));
|
||||
}
|
||||
|
||||
const float m = id(mouth_open);
|
||||
if (id(surprised) && !id(speaking)) {
|
||||
it.filled_circle(160 + ex / 2, 148 + ey / 2, 15, id(face_fg));
|
||||
it.filled_circle(160 + ex / 2, 148 + ey / 2, 9, id(face_bg));
|
||||
} else if (!love || id(speaking)) {
|
||||
const int mw = 90 - (int) (40 * m);
|
||||
const int mh = 4 + (int) (26 * m);
|
||||
it.filled_rectangle(160 - mw / 2 + ex / 2, 148 - mh / 2 + ey / 2, mw, mh, id(face_fg));
|
||||
}
|
||||
id(face).draw(it);
|
||||
|
||||
if (!id(speech).empty()) {
|
||||
it.print(160, 186, id(font_status), id(face_fg), TextAlign::TOP_CENTER, id(speech).c_str());
|
||||
it.print(160, 218, id(font_status), id(face_fg), TextAlign::TOP_CENTER, id(speech).c_str());
|
||||
}
|
||||
|
||||
if (id(listening)) {
|
||||
it.image(254, 2, id(icon_listening), id(face_fg), id(face_bg)); // left of the wifi bars
|
||||
}
|
||||
|
||||
robot_face:
|
||||
id: face
|
||||
display_id: display_tft
|
||||
foreground: face_fg
|
||||
background: face_bg
|
||||
love_color: love_red
|
||||
devil_color: status_low
|
||||
# eyes only, centered between the status bar and the speech line
|
||||
eyes_y: 120
|
||||
eye_width: 72
|
||||
eye_height: 84
|
||||
eye_radius: 20
|
||||
eye_spacing: 50
|
||||
gaze_x: 34
|
||||
gaze_y: 22
|
||||
sleep_after: 5min
|
||||
|
||||
motion:
|
||||
- platform: bmi270
|
||||
id: imu
|
||||
@@ -891,7 +891,10 @@ event:
|
||||
threshold: 1.5
|
||||
cooldown: 500ms
|
||||
on_event:
|
||||
- script.execute: shake_reaction
|
||||
- script.execute:
|
||||
id: show_mood
|
||||
mood: dizzy
|
||||
seconds: 3
|
||||
|
||||
st25r_i2c:
|
||||
id: nfc_reader
|
||||
@@ -899,7 +902,10 @@ st25r_i2c:
|
||||
update_interval: never # polled from the head touch interval, see there
|
||||
on_tag:
|
||||
- lambda: id(speech) = x; // UID under the face while the card lies there
|
||||
- script.execute: surprise_reaction
|
||||
- script.execute:
|
||||
id: show_mood
|
||||
mood: surprised
|
||||
seconds: 3
|
||||
- text_sensor.template.publish:
|
||||
id: nfc_tag
|
||||
state: !lambda return x;
|
||||
@@ -910,6 +916,14 @@ st25r_i2c:
|
||||
id: nfc_tag
|
||||
state: ""
|
||||
|
||||
# an update needs the network to itself: playback, wake word and the assistant stop first
|
||||
ota:
|
||||
- id: !extend ota_esphome
|
||||
on_begin:
|
||||
- media_player.stop: media_out
|
||||
- voice_assistant.stop:
|
||||
- micro_wake_word.stop:
|
||||
|
||||
# the StackChan base right under the Core spoils the WiFi link (ping 160-250 ms, stuttering audio,
|
||||
# m5stack/StackChan#119); 11 dB brings it to ~20 ms. A ~1 cm gap from the base fixes it fully.
|
||||
wifi:
|
||||
@@ -926,10 +940,47 @@ api:
|
||||
message: !lambda return message;
|
||||
- action: stackchan_pet
|
||||
then:
|
||||
- script.execute: head_stroke
|
||||
- script.execute:
|
||||
id: show_mood
|
||||
mood: love
|
||||
seconds: 5
|
||||
# spins the head around: seconds, power -1000..1000 (sign = direction)
|
||||
- action: stackchan_spin
|
||||
variables:
|
||||
seconds: float
|
||||
power: int
|
||||
then:
|
||||
- script.execute:
|
||||
id: spin
|
||||
seconds: !lambda return seconds;
|
||||
power: !lambda return power;
|
||||
- action: stackchan_shake
|
||||
then:
|
||||
- script.execute: shake_reaction
|
||||
- script.execute:
|
||||
id: show_mood
|
||||
mood: dizzy
|
||||
seconds: 3
|
||||
# neutral, happy, sad, angry, tired, surprised, love, dizzy, puppy, devil, curious, suspicious;
|
||||
# laugh and confused are short animations, sleep/wake close and open the eyes, wink winks
|
||||
- action: stackchan_set_emotion
|
||||
variables:
|
||||
emotion: string
|
||||
then:
|
||||
- lambda: |-
|
||||
if (emotion == "laugh")
|
||||
id(face).laugh();
|
||||
else if (emotion == "confused")
|
||||
id(face).confused();
|
||||
else if (emotion == "sleep")
|
||||
id(face).set_eyes_open(false);
|
||||
else if (emotion == "wake")
|
||||
id(face).peek(0);
|
||||
else if (emotion == "wink")
|
||||
id(face).wink(1);
|
||||
else {
|
||||
id(show_mood).stop();
|
||||
id(face).set_mood(emotion);
|
||||
}
|
||||
|
||||
touchscreen:
|
||||
- platform: ft63x6
|
||||
@@ -967,6 +1018,25 @@ esp32_camera:
|
||||
frame_buffer_location: PSRAM
|
||||
|
||||
sensor:
|
||||
# raw servo positions, 1024 steps = 360 degrees (2.844 steps per degree, as in ftservo)
|
||||
- platform: ftservo
|
||||
id: servo_x_feedback
|
||||
ftservo_id: x_servo
|
||||
update_interval: 500ms
|
||||
position:
|
||||
name: Servo X Position
|
||||
entity_category: diagnostic
|
||||
filters:
|
||||
- delta: 2
|
||||
- platform: ftservo
|
||||
id: servo_y_feedback
|
||||
ftservo_id: y_servo
|
||||
update_interval: 500ms
|
||||
position:
|
||||
name: Servo Y Position
|
||||
entity_category: diagnostic
|
||||
filters:
|
||||
- delta: 2
|
||||
- platform: axp2101
|
||||
id: axp2101_sensor
|
||||
battery_level:
|
||||
@@ -1060,16 +1130,38 @@ ftservo:
|
||||
id: y_servo
|
||||
address: 2
|
||||
|
||||
button:
|
||||
- platform: template
|
||||
name: Spin
|
||||
icon: mdi:rotate-360
|
||||
on_press:
|
||||
- script.execute:
|
||||
id: spin
|
||||
seconds: 3
|
||||
power: 600
|
||||
|
||||
number:
|
||||
- platform: ftservo
|
||||
ftservo_id: x_servo
|
||||
# yaw: 0 = straight ahead = raw 461 (measured), 2.844 steps per degree
|
||||
angle:
|
||||
id: servo_x_angle
|
||||
name: Servo X Angle
|
||||
min_value: -164
|
||||
max_value: 164
|
||||
min_value: -160
|
||||
max_value: 160
|
||||
use_raw_angle: false
|
||||
angle_offset: 164
|
||||
angle_offset: 162.1
|
||||
step: 5
|
||||
# pitch: 0 = all the way down = raw 642, the top stop is raw 928 (~100 degrees, measured)
|
||||
- platform: ftservo
|
||||
ftservo_id: y_servo
|
||||
angle:
|
||||
id: servo_y_angle
|
||||
name: Servo Y Angle
|
||||
min_value: 0
|
||||
max_value: 95
|
||||
use_raw_angle: false
|
||||
angle_offset: 225.7
|
||||
step: 5
|
||||
|
||||
light:
|
||||
|
||||
@@ -2,12 +2,274 @@
|
||||
# Hardware: Seeed XIAO STM32C5 #1, CANopen node 0x20 (see common/xiao_stm32c5_canopen.yaml); its LED is light
|
||||
# entity 1 (0x2011:1 / 0x2012:1), the server for mcu-stm32-xiao-c5-sdo-client.yaml (esphome#22410 test)
|
||||
# USB serial: 3838333031365105001F005D (TinyUF2: 5D001F000551363130333838)
|
||||
# Keypad prototype (Blink Marine PKP compatible) until the MCP23017 board exists, M5 units on Grove:
|
||||
# D4/D5 (i2c1, PB7 SDA, PB6 SCL) -> i2c_grove; two i2c buses: esphomeplatformzephyr/esphome#247, merged in framework-zephyr
|
||||
# I2C:
|
||||
# 0x41 enc (m5stack_8encoder), Unit 8Encoder
|
||||
# 0x47 byte_button (m5stack_byte), Unit ByteButton -> PKP 2400SI (2x4) emulation, node 0x14
|
||||
substitutions:
|
||||
node_id: "0x20"
|
||||
|
||||
esphome:
|
||||
name: mcu-stm32-xiao-c5
|
||||
friendly_name: XIAO STM32C5
|
||||
on_boot:
|
||||
- lambda: |-
|
||||
// PKP RPDOs: 0x200 LED on, 0x300 LED blink (bytes 0-2: R, G, B masks of keys 1-8), 0x400 brightness 0-3F
|
||||
static canopen::FrameListener pkp_rx{0x014, 0x0FF, [](void *, uint32_t can_id, const uint8_t *d, uint8_t len) {
|
||||
if (id(pkp).get_nmt_state() != canopen::NMTState::NMT_STATE_OPERATIONAL || len == 0)
|
||||
return;
|
||||
uint32_t bits = d[0] | (len > 1 ? d[1] << 8 : 0) | (len > 2 ? d[2] << 16 : 0);
|
||||
if (can_id == 0x214)
|
||||
id(pkp_led_on) = bits;
|
||||
else if (can_id == 0x314)
|
||||
id(pkp_led_blink) = bits;
|
||||
else if (can_id == 0x414)
|
||||
id(pkp_brightness) = d[0] > 0x3F ? 0x3F : d[0];
|
||||
}, nullptr};
|
||||
id(pkp).add_frame_listener(pkp_rx);
|
||||
|
||||
packages:
|
||||
node: !include common/xiao_stm32c5_canopen.yaml
|
||||
|
||||
external_components:
|
||||
- source: github://randybb/esphome-components
|
||||
components: [m5stack_byte, m5stack_8encoder]
|
||||
refresh: 1h
|
||||
|
||||
i2c:
|
||||
- id: i2c_grove
|
||||
dts_node_override: i2c1
|
||||
|
||||
# Blink Marine PKP 2400SI emulation (docs: home-gitops canopen-nodes.adoc): like the real one, not active until
|
||||
# NMT Start (000#0114); 0x14, because the AtomS3 emulates a PKP 2600SI at 0x15
|
||||
canopen:
|
||||
- id: pkp
|
||||
canbus_id: can_bus
|
||||
node_id: 0x14
|
||||
nmt_startup: pre_operational
|
||||
device_name: PKP2400SI
|
||||
|
||||
m5stack_byte:
|
||||
- id: byte_button
|
||||
i2c_id: i2c_grove
|
||||
address: 0x47
|
||||
|
||||
# encoders: position 0..8 (min/max here) or free turning (bit set in Encoder Relative Modes, for the map and menus);
|
||||
# both go to CAN as one byte: the position, or the counter mod 256 (the consumer takes the difference)
|
||||
m5stack_8encoder:
|
||||
- id: enc
|
||||
i2c_id: i2c_grove
|
||||
encoders:
|
||||
- id: encoder_1
|
||||
min_value: 0
|
||||
max_value: 8
|
||||
filters: &enc_filters
|
||||
- lambda: return (int32_t) x & 0xFF;
|
||||
- id: encoder_2
|
||||
min_value: 0
|
||||
max_value: 8
|
||||
filters: *enc_filters
|
||||
- id: encoder_3
|
||||
min_value: 0
|
||||
max_value: 8
|
||||
filters: *enc_filters
|
||||
- id: encoder_4
|
||||
min_value: 0
|
||||
max_value: 8
|
||||
filters: *enc_filters
|
||||
- id: encoder_5
|
||||
min_value: 0
|
||||
max_value: 8
|
||||
filters: *enc_filters
|
||||
- id: encoder_6
|
||||
min_value: 0
|
||||
max_value: 8
|
||||
filters: *enc_filters
|
||||
- id: encoder_7
|
||||
min_value: 0
|
||||
max_value: 8
|
||||
filters: *enc_filters
|
||||
- id: encoder_8
|
||||
min_value: 0
|
||||
max_value: 8
|
||||
filters: *enc_filters
|
||||
buttons:
|
||||
- id: encoder_button_1
|
||||
- id: encoder_button_2
|
||||
- id: encoder_button_3
|
||||
- id: encoder_button_4
|
||||
- id: encoder_button_5
|
||||
- id: encoder_button_6
|
||||
- id: encoder_button_7
|
||||
- id: encoder_button_8
|
||||
switch:
|
||||
id: encoder_switch
|
||||
|
||||
number:
|
||||
# 8Encoder LED colours 0xRRGGBB (1-8 at the encoders, 9 at the switch), set over CAN (SDO), kept over reboots
|
||||
- &led_color
|
||||
platform: template
|
||||
id: led_color_1
|
||||
name: LED 1 Color
|
||||
entity_category: config
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: 0
|
||||
min_value: 0
|
||||
max_value: 0xFFFFFF
|
||||
step: 1
|
||||
- {<<: *led_color, id: led_color_2, name: LED 2 Color}
|
||||
- {<<: *led_color, id: led_color_3, name: LED 3 Color}
|
||||
- {<<: *led_color, id: led_color_4, name: LED 4 Color}
|
||||
- {<<: *led_color, id: led_color_5, name: LED 5 Color}
|
||||
- {<<: *led_color, id: led_color_6, name: LED 6 Color}
|
||||
- {<<: *led_color, id: led_color_7, name: LED 7 Color}
|
||||
- {<<: *led_color, id: led_color_8, name: LED 8 Color}
|
||||
- {<<: *led_color, id: led_color_9, name: LED 9 Color}
|
||||
# bit i = encoder i turns freely (navigation), else a position 0..8; set over CAN by the consumer (SDO)
|
||||
- platform: template
|
||||
id: encoder_relative_modes
|
||||
name: Encoder Relative Modes
|
||||
entity_category: config
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: 0
|
||||
min_value: 0
|
||||
max_value: 255
|
||||
step: 1
|
||||
on_value:
|
||||
- lambda: |-
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if ((int) x >> i & 1)
|
||||
id(enc).set_range(i, INT32_MIN, INT32_MAX);
|
||||
else
|
||||
id(enc).set_range(i, 0, 8);
|
||||
}
|
||||
|
||||
globals:
|
||||
- id: pkp_keys_sent
|
||||
type: uint8_t
|
||||
initial_value: '0'
|
||||
- id: pkp_led_on
|
||||
type: uint32_t
|
||||
initial_value: '0'
|
||||
- id: pkp_led_blink
|
||||
type: uint32_t
|
||||
initial_value: '0'
|
||||
- id: pkp_brightness
|
||||
type: uint8_t
|
||||
initial_value: '0x3F'
|
||||
|
||||
interval:
|
||||
# keys TPDO 0x194 (byte 0: keys 1-8) on every change, as the real one (event-driven)
|
||||
# TODO on arrival: ByteButton bit polarity is not documented; here a pressed key reads 0 (drop the ~ if not)
|
||||
- interval: 20ms
|
||||
then:
|
||||
- lambda: |-
|
||||
uint8_t keys = ~id(byte_button).get_state();
|
||||
if (keys == id(pkp_keys_sent) || id(pkp).get_nmt_state() != canopen::NMTState::NMT_STATE_OPERATIONAL)
|
||||
return;
|
||||
if (id(pkp).send_frame(0x194, &keys, 1))
|
||||
id(pkp_keys_sent) = keys;
|
||||
# LEDs: the on colour; with blink, alternating with the blink colour every 500 ms (off if not on)
|
||||
- interval: 500ms
|
||||
then:
|
||||
- lambda: |-
|
||||
static bool phase = false;
|
||||
phase = !phase;
|
||||
uint8_t lvl = 255 * id(pkp_brightness) / 0x3F;
|
||||
uint8_t rgb[8 * 3];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
auto col = [i](uint32_t b) { return (b >> i & 1) | (b >> (i + 8) & 1) << 1 | (b >> (i + 16) & 1) << 2; };
|
||||
int on = col(id(pkp_led_on)), bl = col(id(pkp_led_blink));
|
||||
int c = phase && bl ? bl : (bl && !on ? 0 : on);
|
||||
rgb[i * 3] = c & 1 ? lvl : 0;
|
||||
rgb[i * 3 + 1] = c & 2 ? lvl : 0;
|
||||
rgb[i * 3 + 2] = c & 4 ? lvl : 0;
|
||||
}
|
||||
id(byte_button).set_leds(rgb, 8);
|
||||
|
||||
# 8Encoder LEDs: the colours from led_color_1..9 (set remotely); turning an encoder shows its position 0..8 on the
|
||||
# 8 encoder LEDs for ENC_SHOW_MS (bar on dark, none in free turning), its own LED blinks white, then the colours
|
||||
# come back; the switch LED (9th) is green while the switch is on. Written only when something changed.
|
||||
- interval: 50ms
|
||||
then:
|
||||
- lambda: |-
|
||||
static const uint32_t ENC_SHOW_MS = 3000;
|
||||
static const uint8_t BAR[3] = {0, 64, 255}, ACTIVE[3] = {255, 255, 255}, SWITCH_ON[3] = {0, 255, 0};
|
||||
sensor::Sensor *encs[8] = {id(encoder_1), id(encoder_2), id(encoder_3), id(encoder_4),
|
||||
id(encoder_5), id(encoder_6), id(encoder_7), id(encoder_8)};
|
||||
number::Number *colors[9] = {id(led_color_1), id(led_color_2), id(led_color_3), id(led_color_4), id(led_color_5),
|
||||
id(led_color_6), id(led_color_7), id(led_color_8), id(led_color_9)};
|
||||
static float last[8] = {NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN};
|
||||
static int active = -1;
|
||||
static uint32_t changed_at = 0;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
float v = encs[i]->state;
|
||||
if (std::isnan(v) || v == last[i])
|
||||
continue;
|
||||
if (!std::isnan(last[i])) { // not the first read after boot
|
||||
active = i;
|
||||
changed_at = millis();
|
||||
}
|
||||
last[i] = v;
|
||||
}
|
||||
uint8_t rgb[9 * 3];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
uint32_t c = std::isnan(colors[i]->state) ? 0 : (uint32_t) colors[i]->state;
|
||||
rgb[i * 3] = c >> 16;
|
||||
rgb[i * 3 + 1] = c >> 8;
|
||||
rgb[i * 3 + 2] = c;
|
||||
}
|
||||
if (active >= 0 && millis() - changed_at < ENC_SHOW_MS) {
|
||||
// free turning: only its own LED
|
||||
int pos = (int) id(encoder_relative_modes).state >> active & 1 ? 0 : encs[active]->state;
|
||||
memset(rgb, 0, 8 * 3);
|
||||
for (int led = 0; led < 8 && led < pos; led++)
|
||||
memcpy(&rgb[led * 3], BAR, 3);
|
||||
if (millis() / 250 & 1)
|
||||
memcpy(&rgb[active * 3], ACTIVE, 3);
|
||||
}
|
||||
if (id(encoder_switch).state)
|
||||
memcpy(&rgb[8 * 3], SWITCH_ON, 3);
|
||||
static uint8_t sent[9 * 3];
|
||||
static bool written = false;
|
||||
if (written && memcmp(rgb, sent, sizeof(rgb)) == 0)
|
||||
return; // no I2C traffic
|
||||
if (id(enc).set_leds(rgb, 9)) {
|
||||
memcpy(sent, rgb, sizeof(rgb));
|
||||
written = true;
|
||||
}
|
||||
|
||||
# 8Encoder as entities of node 0x20 (the package uses 1-5, 16, 17); LED colours 50-58: command 0x2322:1 + 0x10 per LED (REAL32)
|
||||
# encoders: one byte each, the position 0..8 (as the PKP3500-MT with its default TOP position 8) or the counter mod 256
|
||||
canopen_entities:
|
||||
entities:
|
||||
- {id: encoder_switch, index: 6, tpdo: 1}
|
||||
- {id: encoder_relative_modes, index: 7}
|
||||
- {id: led_color_1, index: 50}
|
||||
- {id: led_color_2, index: 51}
|
||||
- {id: led_color_3, index: 52}
|
||||
- {id: led_color_4, index: 53}
|
||||
- {id: led_color_5, index: 54}
|
||||
- {id: led_color_6, index: 55}
|
||||
- {id: led_color_7, index: 56}
|
||||
- {id: led_color_8, index: 57}
|
||||
- {id: led_color_9, index: 58}
|
||||
- {id: encoder_button_1, index: 30, tpdo: 3}
|
||||
- {id: encoder_button_2, index: 31, tpdo: 3}
|
||||
- {id: encoder_button_3, index: 32, tpdo: 3}
|
||||
- {id: encoder_button_4, index: 33, tpdo: 3}
|
||||
- {id: encoder_button_5, index: 34, tpdo: 3}
|
||||
- {id: encoder_button_6, index: 35, tpdo: 3}
|
||||
- {id: encoder_button_7, index: 36, tpdo: 3}
|
||||
- {id: encoder_button_8, index: 37, tpdo: 3}
|
||||
- {id: encoder_1, index: 40, tpdo: 4, size: 1}
|
||||
- {id: encoder_2, index: 41, tpdo: 4, size: 1}
|
||||
- {id: encoder_3, index: 42, tpdo: 4, size: 1}
|
||||
- {id: encoder_4, index: 43, tpdo: 4, size: 1}
|
||||
- {id: encoder_5, index: 44, tpdo: 4, size: 1}
|
||||
- {id: encoder_6, index: 45, tpdo: 4, size: 1}
|
||||
- {id: encoder_7, index: 46, tpdo: 4, size: 1}
|
||||
- {id: encoder_8, index: 47, tpdo: 4, size: 1}
|
||||
@@ -103,6 +103,13 @@ modem:
|
||||
init_at:
|
||||
- AT+CPSI=60 # URC +CPSI every 60 s, for the operator
|
||||
- AT+CGNSSINFO=30 # URC +CGNSSINFO every 30 s while GNSS runs; dev has no GNSS sensors
|
||||
# GPS + GLONASS + Galileo (mask: 1 GLONASS, 2 BeiDou, 4 Galileo, 8 QZSS; GPS always on; was 15),
|
||||
# DPO (power saving) kept. LE11B04SIM7600M21-A doesn't count Galileo in +CGNSSINFO
|
||||
- AT+CGNSSMODE=5,1
|
||||
# gpsOne XTRA: orbits from the net, kept in the modem's flash, so a fix in seconds after a power
|
||||
# cycle (every ESP reset cycles the modem). Downloaded by the modem itself when expired (+CGPSXD: 0 = done)
|
||||
- AT+CGPSXE=1
|
||||
- AT+CGPSXDAUTO=1
|
||||
on_connect:
|
||||
# Survives an ESP reboot without a modem power cycle; the modem answers ERROR if GNSS already runs
|
||||
- if:
|
||||
|
||||
+25
-34
@@ -25,6 +25,9 @@ substitutions:
|
||||
light_workbench: light.mcu_basement_2_workbench_light
|
||||
light_exercise: light.exercise_room
|
||||
fan: light.trainer_fan_exercise_room_fan
|
||||
# Home Assistant: the training state and the automation that runs the lights and the fan from it
|
||||
training: input_boolean.training
|
||||
training_automation: automation.training
|
||||
|
||||
# Pages (480x320, navigation bar at the bottom):
|
||||
# clock, lights, training, fan, stopwatch, status
|
||||
@@ -145,6 +148,11 @@ packet_transport:
|
||||
- name: mcu-trainer-ant
|
||||
|
||||
binary_sensor:
|
||||
- platform: homeassistant
|
||||
id: training_on
|
||||
entity_id: ${training}
|
||||
on_state:
|
||||
- script.execute: update_training_status
|
||||
- platform: homeassistant
|
||||
id: basement_light
|
||||
entity_id: ${light_basement}
|
||||
@@ -456,14 +464,8 @@ text_sensor:
|
||||
value: !lambda return *parse_number<float>(x);
|
||||
# a running automation (e.g. its delay) has current > 0
|
||||
- platform: homeassistant
|
||||
id: training_start_running
|
||||
entity_id: automation.zwift_enable_fan
|
||||
attribute: current
|
||||
on_value:
|
||||
- script.execute: update_training_status
|
||||
- platform: homeassistant
|
||||
id: training_stop_running
|
||||
entity_id: automation.zwift_disable_fan
|
||||
id: training_running
|
||||
entity_id: ${training_automation}
|
||||
attribute: current
|
||||
on_value:
|
||||
- script.execute: update_training_status
|
||||
@@ -518,14 +520,17 @@ script:
|
||||
|
||||
- id: update_training_status
|
||||
then:
|
||||
- lambda: |-
|
||||
const bool on = id(training_on).state;
|
||||
lv_label_set_text(id(training_btn_label), on ? "Stop" : "Štart");
|
||||
lv_obj_set_style_bg_color(id(training_btn), lv_color_hex(on ? 0xB71C1C : 0x1E7D32), LV_PART_MAIN);
|
||||
- lvgl.label.update:
|
||||
id: training_status_label
|
||||
text: !lambda |-
|
||||
if (id(training_start_running).state != "0" && !id(training_start_running).state.empty())
|
||||
return std::string("Tréning sa spúšťa, ventilátor sa zapne o 10 min");
|
||||
if (id(training_stop_running).state != "0" && !id(training_stop_running).state.empty())
|
||||
return std::string("Tréning sa ukončuje, ventilátor sa vypne o 2 min");
|
||||
return std::string("");
|
||||
const bool running = !id(training_running).state.empty() && id(training_running).state != "0";
|
||||
if (id(training_on).state)
|
||||
return std::string(running ? "Tréning beží, ventilátor sa zapne o 10 min" : "Tréning beží");
|
||||
return std::string(running ? "Tréning skončil, ventilátor sa vypne o 2 min" : "");
|
||||
|
||||
- id: update_stopwatch
|
||||
then:
|
||||
@@ -814,42 +819,28 @@ lvgl:
|
||||
entity_id: ${light_exercise}
|
||||
color_temp_kelvin: !lambda return (int) x;
|
||||
|
||||
# 3: training start / stop
|
||||
# 3: training start / stop, one toggle showing input_boolean.training
|
||||
- id: training_page
|
||||
pad_all: 10
|
||||
widgets:
|
||||
- button:
|
||||
align: TOP_LEFT
|
||||
id: training_btn
|
||||
align: TOP_MID
|
||||
y: 10
|
||||
width: 222
|
||||
width: 460
|
||||
height: 150
|
||||
bg_color: 0x1E7D32
|
||||
widgets:
|
||||
- label:
|
||||
id: training_btn_label
|
||||
align: CENTER
|
||||
text_font: font_button
|
||||
text: "Štart"
|
||||
on_click:
|
||||
- homeassistant.action:
|
||||
action: automation.trigger
|
||||
action: input_boolean.toggle
|
||||
data:
|
||||
entity_id: automation.zwift_enable_fan
|
||||
- button:
|
||||
align: TOP_RIGHT
|
||||
y: 10
|
||||
width: 222
|
||||
height: 150
|
||||
bg_color: 0xB71C1C
|
||||
widgets:
|
||||
- label:
|
||||
align: CENTER
|
||||
text_font: font_button
|
||||
text: "Stop"
|
||||
on_click:
|
||||
- homeassistant.action:
|
||||
action: automation.trigger
|
||||
data:
|
||||
entity_id: automation.zwift_disable_fan
|
||||
entity_id: ${training}
|
||||
- label:
|
||||
id: training_status_label
|
||||
align: TOP_MID
|
||||
|
||||
@@ -22,3 +22,4 @@ esp32_ble_beacon:
|
||||
uuid: !secret ble_beacon_honda_uuid
|
||||
major: !secret ble_beacon_honda_major
|
||||
minor: !secret ble_beacon_honda_minor
|
||||
tx_power: 9dBm
|
||||
@@ -22,3 +22,4 @@ esp32_ble_beacon:
|
||||
uuid: !secret ble_beacon_suzuki_uuid
|
||||
major: !secret ble_beacon_suzuki_major
|
||||
minor: !secret ble_beacon_suzuki_minor
|
||||
tx_power: 9dBm
|
||||
@@ -12,29 +12,14 @@ esphome:
|
||||
friendly_name: ${name}
|
||||
area: ${area}
|
||||
comment: ${comment}
|
||||
on_boot:
|
||||
then:
|
||||
- if:
|
||||
condition:
|
||||
- binary_sensor.is_off: button
|
||||
then:
|
||||
- wifi.disable:
|
||||
|
||||
packages:
|
||||
base: !include common/vehicle_base.yaml
|
||||
wifi: !include common/wifi.yaml
|
||||
logger: !include common/logger.yaml
|
||||
ota: !include common/ota.yaml
|
||||
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
id: button
|
||||
filters:
|
||||
- invert:
|
||||
pin: 39
|
||||
|
||||
esp32_ble_beacon:
|
||||
type: iBeacon
|
||||
uuid: !secret ble_beacon_toyota_auris_uuid
|
||||
major: !secret ble_beacon_toyota_auris_major
|
||||
minor: !secret ble_beacon_toyota_auris_minor
|
||||
tx_power: 9dBm
|
||||
@@ -22,3 +22,4 @@ esp32_ble_beacon:
|
||||
uuid: !secret ble_beacon_toyota_yaris_uuid
|
||||
major: !secret ble_beacon_toyota_yaris_major
|
||||
minor: !secret ble_beacon_toyota_yaris_minor
|
||||
tx_power: 9dBm
|
||||
@@ -31,8 +31,9 @@ ble_beacon_toyota_auris_uuid: "00000000-0000-0000-0000-000000000000"
|
||||
ble_beacon_toyota_auris_major: 10167
|
||||
ble_beacon_toyota_auris_minor: 61958
|
||||
ble_beacon_toyota_yaris_uuid: "00000000-0000-0000-0000-000000000000"
|
||||
ble_beacon_toyota_yaris_honda_major: 10167
|
||||
ble_beacon_toyota_yaris_honda_minor: 61958
|
||||
ble_beacon_toyota_yaris_major: 10167
|
||||
ble_beacon_toyota_yaris_minor: 61958
|
||||
ble_beacon_gate_uuid: "00000000-0000-0000-0000-000000000000"
|
||||
|
||||
# Thread active dataset (hex TLV) from Home Assistant
|
||||
thread_tlv: "0E080000000000010000"
|
||||
|
||||
Reference in new issue
Block a user