Compare commits

..
90 Commits
Author SHA1 Message Date
randy a3f3d90b2b CAN nodes: rx_queue_len 32 and canbus logs at INFO (SDO block overflowed the 5-frame queue); atoms3: OTA over CANopen from esphome#23831
CI / YAML lint (push) Successful in 6s
CI / ESPHome config validation (push) Failing after 1m1s
2026-12-05 13:59:12 +01:00
randy a909041263 vehicle beacons, gate: drop the esp32_ble override, esphome#23800 is in dev 2026-12-05 13:59:12 +01:00
randy 70d1079ccd CI: skip configs whose included package sets a Zephyr platform (XIAO STM32C5 nodes)
CI / YAML lint (push) Successful in 7s
CI / ESPHome config validation (push) Successful in 1m0s
2026-12-04 11:54:56 +01:00
randy 0f1b32b1ed m5stickc-plus: TJA1050 CAN module on Grove (RX GPIO32, TX GPIO33), listen-only until the node sees the bus 2026-12-04 11:53:27 +01:00
randy feaa161653 can-node-1/2: canopen_entities from mrk-its/esphome-canopen@canopen_entities 2026-12-04 11:53:27 +01:00
randy 8aee65e697 XIAO STM32C5 nodes: IMU levelling (offsets on the node), 200 ms inclinometer; node 0x20 = keypad prototype: ByteButton as PKP 2400SI (node 0x14), 8Encoder entities with remote LED colours, position bar and switch LED 2026-12-04 11:53:27 +01:00
randy 0da0cd1544 Vehicle beacons: LED dark except a boot blink and while the gate's home beacon is seen, Wi-Fi + OTA on a 3 s button hold, 9 dBm, esp32_ble without the empty advertisement; gate: own home beacon, scan window 160/320 ms
CI / YAML lint (push) Successful in 7s
CI / ESPHome config validation (push) Successful in 1m3s
2026-12-04 00:53:07 +01:00
randy 6591b47c01 mcu-trainer: training state in input_boolean.training, one start/stop toggle, status from automation.training 2026-12-03 23:59:10 +01:00
randy 9a158bab19 stackchan: robot_face component, moods and head spin, servo end stops
- face drawn by the robot_face component (moods, gaze, blinks; laugh/confused animations,
  wink, sleep/wake) instead of the display lambda and its globals
- moods from touch, shake and NFC cards; HA actions for moods and spinning the head
- head spin: yaw servo in wheel mode (angle limits 0/0), limits put back afterwards
- pitch end stops written into the servo's angle limits, measured servo positions
- per-task CPU time over 10 s (FreeRTOS run time stats)
2026-12-03 17:22:41 +01:00
randy bba78dbb17 tracker: GNSS with GPS + GLONASS + Galileo, gpsOne XTRA orbits downloaded by the modem 2026-12-03 17:08:58 +01:00
randy 3d5a77bd13 m5core2: CANopen node 5 on a TJA1050 module at Port A (esp32_can GPIO32/33, 500 kbit/s)
CI / YAML lint (push) Successful in 7s
CI / ESPHome config validation (push) Successful in 1m22s
2026-12-03 17:02:28 +01:00
randy 0f6e2350cc ESPHome 2026.12: on_client_synced, CanPayload, cleanups
- LVGL panels (NSPanels, lvgl, lvgl-4848s040, m5core2, tft), m5paper: api on_client_synced
  instead of a 2 s delay and an api.connected check
- car-can: on_frame x is canbus::CanPayload, frames_per_id keeps it without a heap vector
- gateway: drop the commented ethernet (common/ethernet.yaml has it), LLDP (PR draft),
  manual_ip and use_address
- clock-1, echo: drop the commented neopixelbus lights
2026-12-03 17:01:53 +01:00
randy 01fe45ce8d hosted: C6 co-processor firmware moves to the ignored .hosted/, kept out of git 2026-12-03 09:56:15 +01:00
randy 7c704fa55d stackchan: WiFi output power 11 dB, the base right under the Core spoils the link 2026-12-02 19:31:55 +01:00
randy 8234220765 stackchan: NFC scanned from the head touch loop, taps no longer start the assistant
CI / YAML lint (push) Successful in 6s
CI / ESPHome config validation (push) Successful in 1m4s
Every ST25R scan switches its RF field on and the si12t pads report a
50-350 ms phantom touch at any sensitivity; those started the assistant
in a loop. The reader is now scanned between touch episodes every 2 s,
with the pads ignored for 400 ms afterwards, and right when an episode
starts so a card is still seen quickly. The assistant starts from the
wake word only; a stroke shows the hearts.
2026-12-02 13:28:02 +01:00
randy 58a5176ed3 atoms3: CANopen keypad (CardKB, PKP 2600SI emulation); m5stickc-plus: CANopen keypad + Mini JoyC
CI / YAML lint (push) Successful in 6s
CI / ESPHome config validation (push) Successful in 56s
2026-12-01 01:05:01 +01:00
randy aa3e59bb0a mcu-eworkbench: AT6668 (Cap LoRa-1262) on the casic platform in place of the NEO-6M
CI / YAML lint (push) Successful in 7s
CI / ESPHome config validation (push) Failing after 55s
2026-11-30 13:36:24 +01:00
randy 71c31035e5 xiao-stm32c5: CANopen node package (canopen + canopen_entities, MCUboot, OTA over CAN), node 0x20 and the TinyUF2 eraser 2026-11-29 12:24:04 +01:00
randy 0c93059c78 mcu-tracker: drop the modem pin to 200bf69035, fixed in esphome#23238 2026-11-29 12:24:04 +01:00
randy 6be43cb95e stackchan: NFC reader polled from the head touch interval, its RF field caused phantom touches 2026-11-29 12:24:04 +01:00
randy 44b0601bf2 mcu-can-node-2: on-board blue LED on GPIO2 as a locate LED 2026-11-29 12:24:04 +01:00
randy fdb9fd4796 mcu-tbeam: T-Beam v1.1 as a geolocation test receiver (NEO-6M on ubx, OLED, AXP192 battery, NAV-SVINFO test aid)
CI / YAML lint (push) Successful in 5s
CI / ESPHome config validation (push) Successful in 59s
2026-11-28 16:40:34 +01:00
randy dd88807a1b mcu-eworkbench: gnss hub renamed to geolocation in esphome/esphome#23293 and #23301 2026-11-28 14:15:12 +01:00
randy 0ea4aaf685 stackchan: 5 V BUS sequenced at boot, BMI270 shake, ST25R3916 NFC, HA say/pet/shake actions
CI / YAML lint (push) Successful in 7s
CI / ESPHome config validation (push) Successful in 1m16s
The BUS was switched on at once in setup(); from the battery the inrush pulled
a converter under its UVP threshold and the AXP2101 powered off. Now the UVP
power-off is cleared and the BUS ramps up in pulses (as in m5stack/esphome-yaml
discussion #129). NFC UID is shown under a surprised face, head taps around a
tag change are ignored.
2026-11-27 11:42:02 +01:00
randy 64c25f6165 mcu-nrf-ant, mcu-nrf-dk: Garmin Varia vehicles, distance, closing speed, fast vehicle
CI / YAML lint (push) Successful in 5s
CI / ESPHome config validation (push) Successful in 52s
2026-11-27 00:06:02 +01:00
randy 7d27f8a005 mcu-eworkbench: GNSS bench with a u-blox M10 (ubx) and a NEO-6M (nmea) from esphome#23301, IPv6 only, generic flash chip 2026-11-26 18:19:54 +01:00
randy 15242c38ee tracker: modem from before esphome#22817, which leaves the SIM7600's SIM powered down
CI / YAML lint (push) Successful in 6s
CI / ESPHome config validation (push) Successful in 56s
2026-11-24 13:34:58 +01:00
randy ae7035c597 mcu-m5core2: mlx90640 from esphome-components, without the web UI 2026-11-24 12:08:58 +01:00
randy c306d87acf mcu-nrf-ant: NFC tag with a Home Assistant tag URL 2026-11-24 11:52:38 +01:00
randy c6b1cfd00d mcu-air-office-r: IPv6 only 2026-11-24 11:30:39 +01:00
randy 78644969ba ipv6_only: lwip fork rebased on IDF 6.1.1, pr#19750 merged 2026-11-24 11:30:39 +01:00
randy 27cbbbe217 mcu-trainer: rename trainer devices, add mcu-trainer-ant
CI / YAML lint (push) Successful in 6s
CI / ESPHome config validation (push) Successful in 53s
mcu-lvgl-trainer -> mcu-trainer, mcu-dimmer -> mcu-trainer-fan (Trainer Fan).
mcu-trainer-ant: ANT+ receiver on an Ebyte E104-BT5040U dongle (Open DFU),
without USB since the USB stack holds HFCLK and RadiANT can't start the HFXO.
mcu-trainer receives its values over UART (GPIO17/18) with packet_transport.
2026-11-23 23:37:02 +01:00
randy 2acb5c8506 mcu-its-g5: IPv4 only, MQTT never connected on the car hotspot
CI / YAML lint (push) Successful in 5s
CI / ESPHome config validation (push) Successful in 56s
The hotspot (O2 SK) has no IPv6, but with IPv6 enabled MQTT resolves the
broker's AAAA record first even with only a link-local address, and
never falls back to IPv4.
2026-11-23 15:59:35 +01:00
randy 547dea26e3 mcu-its-g5: decoded header as JSON on mcu-its-g5/decoded, 1 Hz per station
CI / YAML lint (push) Successful in 6s
CI / ESPHome config validation (push) Successful in 58s
Message type, station type and id, position, speed and heading from the
GeoNetworking header, so consumers don't need an ASN.1 decoder. Outside
its/<node>/#, so the EMQX bridge keeps it off OpenTrafficMap.
2026-11-19 00:24:44 +01:00
randy 3676c0bbcc mcu-its-g5: MQTT only, to the own broker with an EMQX bridge to OpenTrafficMap
CI / YAML lint (push) Successful in 7s
CI / ESPHome config validation (push) Successful in 58s
HA can't reach the API on the car hotspot, so the device talks MQTT to the own
broker like the tracker; EMQX forwards its/<node_id>/# to cits1.opentrafficmap.org.
API and homeassistant time removed, the OTA key set directly.

MQTT discovery unique ids with the MAC (its-g5 and tracker): the default
ESP<type><object_id> made the common entities of both devices clash in HA.
Uptime in "d": HA MQTT discovery rejects "days" with device class duration.
2026-11-17 21:59:19 +01:00
randy 177bdcb3de hosted/xiao-c6-spi: esp-hosted co-processor firmware for the mcu-its-g5 XIAO ESP32-C6
CI / YAML lint (push) Successful in 6s
CI / ESPHome config validation (push) Successful in 1m15s
2026-11-16 22:07:33 +01:00
randy 523957d30d mcu-its-g5: ITS-G5 receiver on a XIAO ESP32-C5 with Wi-Fi on a XIAO ESP32-C6 2026-11-16 21:56:33 +01:00
randy a0e216fcf1 ipv6_only: back on pr#19750, the IPv4-off build is fixed there 2026-11-16 19:51:53 +01:00
randy 775cf085fe stackchan: m5ioe1 from our components, voice_assistant from dev 2026-11-16 19:51:25 +01:00
randy c913af2814 lvgl: Pip-Boy UI with STAT, DATA, MAP and SYS tabs 2026-11-16 19:51:25 +01:00
randy faa4fe43f3 cnc-pendant: handwheel autolock, Tiny5 Mono font 2026-11-16 19:51:25 +01:00
randy f8142505b7 cec-bedroom: hdmi_cec from dev, IPv6-only, no physical_address option 2026-11-16 19:51:25 +01:00
randy 16fde5016e car-can: plain esp32 variant instead of the m5stamp-pico board 2026-11-16 19:51:01 +01:00
randy 885fc5a016 tracker: restore the OLED status screen dropped in b660638 2026-11-16 19:49:14 +01:00
randy 3cafd749d3 stm32: F4 Discovery and miniSTM32F103ZE-EK, button debounce, ST-LINK serials
CI / YAML lint (push) Successful in 7s
CI / ESPHome config validation (push) Successful in 53s
2026-11-07 11:20:18 +01:00
randy 93f622f430 mcu-m5core2: M5GFX SH1107 init on boot for the Unit OLED
CI / YAML lint (push) Successful in 18s
CI / ESPHome config validation (push) Successful in 1m5s
2026-11-05 13:32:04 +01:00
randy 9c20f605d2 nrf: packet_interface link with reliability and session, add Tacx Neo 2
The DK <-> ANT UART link now runs packet_transport over packet_interface:
HDLC retransmits lost frames and the session layer reports in HA whether
mcu-nrf-ant is reachable (ANT Link). Tacx Neo 2 (FE-C, ANT ID 13888)
publishes power, cadence and in use.
2026-11-05 13:31:29 +01:00
randy 0383ea9871 m5core2: MLX90640 thermal camera, backlight voltage
MLX90640 on Port C through the randybb fork without a web server, a
camera entity and sensors in HA and a thermal page on the LCD (32x24
upscaled bilinear with the iron palette). DC3 is set to 3.3 V on boot:
the AXP192 forgets it when the Faces battery runs flat and the LCD stays
dark.
2026-11-05 11:46:47 +01:00
randy a57b678401 car-can: Auris CAN sniffer on a Stamp Pico, body, engine, climate and trip computer signals
CI / YAML lint (push) Failing after 13s
CI / ESPHome config validation (push) Successful in 58s
2026-11-04 00:01:02 +01:00
randy 0f72e3e9bc m5core2: on_node to Home Assistant as a disabled example
randy_home's Meshtastic integration already gives HA every node.
2026-11-03 16:37:50 +01:00
randy ad2a00f674 m5core2: LoRa868 on Meshtastic LongFast, ESP32 advanced options
CI / YAML lint (push) Failing after 13s
CI / ESPHome config validation (push) Successful in 58s
Modded LoRa868 module (NSS G19, DIO0 G35) with the meshtastic component:
received messages on the LoRa page, typed lines sent to LongFast. Flash
chip, chip revision and SRAM1 as IRAM set as the boot log suggests.
2026-11-03 15:40:21 +01:00
randy bf88390257 nspanel_terminal: update to v0.8.0 with lvgl_iram, fix build warnings 2026-11-03 11:25:46 +01:00
randy a7215bdef9 m5core2: Unit LCD invert and sleep switches 2026-11-03 09:59:03 +01:00
randy 7cef9c674d m5core2: Unit LCD on its own LVGL instance
CI / YAML lint (push) Failing after 15s
CI / ESPHome config validation (push) Successful in 59s
lvgl_unit (rotation 90 in LVGL) shows the clock, the last keyboard line
and a battery bar; page actions name lvgl_main now that there are two
instances.
2026-11-03 01:38:02 +01:00
randy 2d3754bf79 m5core2: Core2 on the Faces Bottom II with the QWERTY face
IPv6-only, LVGL demo with the ESPHome boot/status page, a keyboard page
and AXP192 diagnostics; the three touch buttons below the LCD switch pages.

- Faces QWERTY and CardKB through m5stack_keyboard into a text area
- AXP192: LCD power/reset and the M-Bus 5V boost on boot, charging set
  to 4.1 V / 360 mA for the 600 mAh Faces battery and its ADCs read
  directly (the m5stack axp192 component uses the AXP2101 layout)
- Faces LED strips (G2) as light and status LED; G2 is also the speaker
  DOUT, so no speaker or voice assistant for now
- BM8563 RTC, synced from Home Assistant
- Port C as a second I2C bus: Unit OLED (SH1107, offset_x 32), Unit LCD
  through m5stack_st7789v2, CardKB
2026-11-03 01:32:34 +01:00
randy d60c604967 aixun-h310d: fix path 2026-11-03 00:35:47 +01:00
randy 4e7fca4883 aixun-h310d: switch to ext component repo 2026-11-03 00:15:01 +01:00
randy 5f4a227f27 aixun-h310d: memory wipe of my hot air station 2026-11-03 00:12:21 +01:00
randy ad15557c50 nspanel_terminal: update to v0.7.1, drop the deprecated panel_id
CI / YAML lint (push) Failing after 19s
CI / ESPHome config validation (push) Successful in 4s
2026-11-01 01:56:28 +01:00
randy a5dff6fb15 nspanel_terminal: name the MDI glyphs in the icon fonts
CI / YAML lint (push) Failing after 15s
CI / ESPHome config validation (push) Successful in 1m5s
2026-10-31 23:36:46 +01:00
randy 203fc5e26d nspanel_terminal: heating icons on the home page
A row of state icons above today's weather, filled by packages (the first
one on the right):
- fireplace_icon.yaml: the fireplace burning or out.
- radiator_icon.yaml: per thermostat; disabled while it does not call for
  heat, off while it does but the off-peak tariff has the boiler hard off and
  the fireplace is out, on while it heats.
Both hide outside the heating season (boiler switch off, fireplace out).
2026-10-31 23:33:27 +01:00
randy 697af24f47 nspanel_terminal 0.7.0
Streams LVGL flush areas instead of mirroring the frame; protocol and TFTs
unchanged, so no TFT upload is needed.
2026-10-31 19:21:16 +01:00
randy 17bbf207e4 Move zephyr fork configs to the nrf: and stm32: platform keys
The fork's framework-zephyr rewrite drops the zephyr: key: variant and
board stay on the platform key, the other options move under framework:.
CI skips the Zephyr RTOS platform keys instead of zephyr:.
2026-10-31 16:15:00 +01:00
randy 7b9430c0e5 nspanel_terminal 0.6.0
CI / ESPHome config validation (push) Successful in 6s
CI / YAML lint (push) Failing after 14s
Faster PackBits encoding and DATA framing on the ESP32; protocol and TFTs
unchanged, so no TFT upload is needed.
2026-10-31 13:14:00 +01:00
randy 3759a7b61c nspanel_terminal 0.5.0, even home page margins; pin the IPv6-only wifi PR
nspanel-terminal 0.5.0 (protocol 7, native 93 TFT) is untagged, so it is
pinned to its release commit. The home page uses the 16 px page margin on
every side, measured on the glyph ink; the clock shrinks to 100 px so it
clears the forecast column.

The current head of esphome/esphome#19750 does not build with the IPv4 stack
off (IPV6_ROAM_SETTLE_MS is defined under USE_WIFI_LEASE_CACHE but used under
USE_NETWORK_IPV6), so the PR is pinned to be1f55d until that is fixed.
2026-10-31 10:32:23 +01:00
randy e3687d321d nspanel_terminal: upstream v0.4.0, larger arrow touch areas, '-' in the clock font
CI / YAML lint (push) Failing after 15s
CI / ESPHome config validation (push) Successful in 4s
The fixes of ptaru/nspanel-terminal#1 are released in v0.4.0, so the fork is
no longer needed. The page arrows get an 88x64 touch area; grid pages and the
thermostat move their content below it. The clock font gets '-' for the
placeholder shown while connecting.
2026-10-31 00:25:46 +01:00
randy cafa2da954 nspanel: drop the nspanel_lovelace leftovers
CI / YAML lint (push) Successful in 7s
CI / ESPHome config validation (push) Successful in 1m7s
No panel uses common/nspanel.yaml, nspanel_popup.yaml,
nspanel_sleep_dim.yaml or the lui.tft secret any more.
2026-10-30 18:26:15 +01:00
randy 9b5229323f nspanel: all panels on nspanel-terminal with the LVGL UI
The shared UI (home, light detail, status/boot page, notifications, OTA
progress, display hardware) moves from mcu-nspanel-dev.yaml into
common/nspanel_terminal/panel.yaml. office-r, patio, fireplace, office-j
and bedroom move from nspanel_lovelace to it with the pages, tiles and
buttons of their former cards.

thermostat.yaml carries its page and takes an id prefix, so a panel can
have more than one (fireplace). The thermostat returns to the HA target
5 s after sending, in case HA rejects the change. Idle timeout 15 s.
2026-10-30 18:20:45 +01:00
randy 5976d81d1c nspanel-dev: report the NTC temperature to HA again 2026-10-30 17:38:33 +01:00
randy 071637f589 secrets.yaml.default: tft_url_terminal for nspanel-dev 2026-10-30 17:25:52 +01:00
randy 53f0dec88e nspanel-dev: nspanel-terminal from the GitHub fork instead of a local checkout
randybb/nspanel-terminal@upload-and-redraw-fixes carries the fixes of
ptaru/nspanel-terminal#1; switch to upstream once that is merged.
2026-10-30 17:24:29 +01:00
randy 53c427e99c nspanel-dev: LVGL UI on nspanel-terminal instead of nspanel_lovelace
The display runs the ptaru/nspanel-terminal TFT and ESPHome draws the UI
with LVGL (component from a local checkout for now, see PR
ptaru/nspanel-terminal#1).

Pages: home (clock, weather, forecast, temperatures), lights, outside,
irrigation, thermostat, gate, status/boot screen; light detail with
brightness, colour temperature or hue on long press. Grid tiles come
from packages in common/nspanel_terminal/ that add themselves to a page.
Unavailable entities are greyed out, OTA progress shows on the status
page, sleep dim and the notify/show_info actions match the other panels.
2026-10-30 17:20:44 +01:00
randy 0e7dc6591f stackchan: voice_assistant fix from the fork branch instead of a local path
CI / YAML lint (push) Successful in 7s
CI / ESPHome config validation (push) Successful in 1m14s
2026-10-27 22:10:03 +01:00
randy ab45a776fa stackchan, tracker: github:// shorthand without the components path, dev rejects trailing text now 2026-10-27 22:02:47 +01:00
randy a07bce90f9 stm32-*" initial stm32 (zephyr) devices 2026-10-27 21:17:53 +01:00
randy cf49f238ca stackchan: fix mic issues 2026-10-27 21:16:41 +01:00
randy 6389bbdcef lvgl trainer: add display idle 2026-10-27 21:16:06 +01:00
randy 5e7e4f065e pow washer: move to ipv6 only network 2026-10-27 21:14:46 +01:00
randy b660638999 tracker: plain dev modem, GNSS from the +CGNSSINFO URC
CI / YAML lint (push) Failing after 4s
CI / ESPHome config validation (push) Failing after 4s
pr#14683 brought rssi, ber, network_type and urc to dev, but no GNSS, so the
fork of pr#9802 is gone. GNSS is switched with modem.send_at and the position
is parsed from the URC until the modem gets official GNSS support. The device
tracker also gets the accuracy (DOP * gnss_uere_m), the vertical accuracy and
the battery level.
2026-10-24 23:45:56 +02:00
randy 5025159798 tracker: own MQTT user, so the broker ACL limits it to its own topics
CI / ESPHome config validation (push) Failing after 6s
CI / YAML lint (push) Failing after 52s
2026-10-24 12:48:05 +02:00
randy 342ef79771 tracker: modem sensors, GNSS device tracker, battery, data diet
- modem from dev, sensors from pr#9802 via randybb/esphome@modem-gnss-fix
  (fix for the AT+CGPS=1 resend loop), signal/network/operator, GNSS switch
- position as an MQTT device_tracker (discovery sent on connect), one JSON
  on a ~50 m move or hourly
- GNSS and its antenna off while parked, a short look every 30 min
- AXP192 battery: coulomb counter SoC calibrated on a full charge, voltage
  estimate until then, 10 % steps to HA, USB power, Battery Low, power off
  below 3.3 V without USB
- O2 Telemetria data diet: no MQTT logs, 10 min keepalive, values only on
  change or hourly, text sensors on change, PMU details internal
- SNTP every 6 h, time and position on the OLED
2026-10-24 10:36:26 +02:00
randy a110e0c536 tracker: drop the AT+CFUN=1 workaround, pr#6721 sets the APN after the SIM is ready now 2026-10-23 23:40:19 +02:00
randy 1b003fd167 tracker: modem over PPP with MQTT, OLED status, cleanup
- modem from pr#6721 only, enabled from on_boot after the power-up sequence
- AT+CFUN=1 in init_at: the component sets the APN while the radio is off
- signal and network mode parsed from +CSQ/+CPSI URCs
- MQTT instead of API (no WiFi for now), status/uptime/version/restart/IP entities
- SSD1306 OLED with network, signal, PPP/MQTT state, IP and uptime
- AXP192 from m5stack, pinout and I2C header, drop old commented configs
2026-10-23 18:10:11 +02:00
randy 72afe7c622 all esp32*: back to pr#19750
CI / ESPHome config validation (push) Failing after 5s
CI / YAML lint (push) Failing after 1m2s
2026-10-23 15:08:01 +02:00
randy ff092cbe20 nrf-*: add j-link sn & instructions for flashing
CI / ESPHome config validation (push) Failing after 6s
CI / YAML lint (push) Failing after 22s
2026-10-22 12:12:03 +02:00
randy 1bd695fac0 clock-1: gpio9 is not available, use gpio10 instead 2026-10-22 12:11:04 +02:00
randy b3d4a01f67 ipv6_only: mdns is on 1.14.0 so we can drop it, fix ipv6 only due latest changes 2026-10-22 12:10:18 +02:00
randy 52cc85d62b heater, mains-power: add sub device relation - child 2026-10-22 12:08:50 +02:00
randy 7e0e26c329 ipv6_only: network and co. from the PR merged with dev
CI / YAML lint (push) Failing after 27s
CI / ESPHome config validation (push) Successful in 56s
The head of esphome/esphome#19750 lags behind dev, its const overrides
the one of dev and esp32 fails to load ("Platform missing"). The fork
branch has the PR merged with dev and leaves const alone.
2026-10-20 22:54:35 +02:00
randy 2b9b825d79 rfid-openprintag: lower ext component refresh 2026-10-20 20:04:04 +02:00
84 changed files with 72992 additions and 2890 deletions

No files matched your search

+4 -2
View File
@@ -55,8 +55,10 @@ jobs:
if: steps.changed.outputs.any_changed == 'true' if: steps.changed.outputs.any_changed == 'true'
run: | run: |
for f in ${{ steps.changed.outputs.all_changed_files }}; do for f in ${{ steps.changed.outputs.all_changed_files }}; do
# zephyr: needs the esphomeplatformzephyr fork, upstream doesn't know it yet # Zephyr RTOS platforms need the esphomeplatformzephyr fork, upstream doesn't know them yet
if grep -q '^zephyr:' "$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..." echo "Validating $f..."
esphome config "$f" esphome config "$f"
done done
+1
View File
@@ -7,3 +7,4 @@
/archive/ /archive/
/trash/ /trash/
.device-builder.json .device-builder.json
/.hosted/
File diff suppressed because it is too large. Load diff
+40
View File
@@ -0,0 +1,40 @@
# Render a Pip-Boy green map (inverted OSM tiles) centred on home.
# Map data (c) OpenStreetMap contributors, ODbL.
# usage: make_map.py LAT LON ZOOM W H OUT
import io, math, sys, urllib.request
from PIL import Image, ImageDraw, ImageOps
GRID_STEP = 48
lat, lon, z, w, h, out = float(sys.argv[1]), float(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4]), int(sys.argv[5]), sys.argv[6]
def world_px(lat, lon):
n = 256 * 2**z
x = (lon + 180) / 360 * n
y = (1 - math.asinh(math.tan(math.radians(lat))) / math.pi) / 2 * n
return x, y
cx, cy = world_px(lat, lon)
x0, y0 = int(cx - w / 2), int(cy - h / 2)
canvas = Image.new("RGB", (w, h))
for ty in range(y0 // 256, (y0 + h) // 256 + 1):
for tx in range(x0 // 256, (x0 + w) // 256 + 1):
url = f"https://tile.openstreetmap.org/{z}/{tx}/{ty}.png"
req = urllib.request.Request(url, headers={"User-Agent": "esphome-map-render/1.0"})
tile = Image.open(io.BytesIO(urllib.request.urlopen(req).read())).convert("RGB")
canvas.paste(tile, (tx * 256 - x0, ty * 256 - y0))
g = ImageOps.autocontrast(ImageOps.invert(canvas.convert("L")), cutoff=1)
g = g.point(lambda v: int(255 * (v / 255) ** 1.8)) # darker background, roads/edges stay bright
# black -> Pip-Boy background, white -> a muted green so the markers stand out
img = ImageOps.colorize(g, black=(10, 15, 11), white=(80, 170, 105))
# grid and frame like the Pip-Boy local map
draw = ImageDraw.Draw(img)
GRID = (36, 67, 46)
for x in range(GRID_STEP, w, GRID_STEP):
draw.line([(x, 0), (x, h - 1)], fill=GRID)
for y in range(GRID_STEP, h, GRID_STEP):
draw.line([(0, y), (w - 1, y)], fill=GRID)
draw.rectangle([0, 0, w - 1, h - 1], outline=GRID)
img.save(out)
print(f"saved {out}, centre world px {cx:.1f},{cy:.1f}")
Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

+2 -12
View File
@@ -4,23 +4,13 @@
# common_eth: !include common/common_eth.yaml # common_eth: !include common/common_eth.yaml
# ipv6_only: !include common/ipv6_only_eth.yaml # ipv6_only: !include common/ipv6_only_eth.yaml
# WiFi devices use common/ipv6_only.yaml (this + the IPv6 SSID) # WiFi devices use common/ipv6_only.yaml (this + the IPv6 SSID)
external_components:
# network enable_ipv4 + audio HTTP reader over IPv6 (esphome/esphome#19750), drop once merged
- source: github://pr#19750
components: [const, network, wifi, ethernet, audio]
refresh: 1h
esp32: esp32:
framework: framework:
components: components:
# mdns 1.14.0: no "A 0.0.0.0" without IPv4 + IPv6 on ETH-only builds (espressif/esp-protocols#1156, #1161), # IDF v6.1.1 lwip + .local resolution over IPv6 (espressif/esp-lwip#94), drop once in IDF
# drop once on ESPHome 2026.10.0 (esphome/esphome#20383 bumps the pin from 1.12.0)
- name: espressif/mdns
ref: 1.14.0
# IDF v5.5.5 lwip + .local resolution over IPv6 (espressif/esp-lwip#94), drop once in IDF
- name: lwip - name: lwip
source: https://github.com/randybb/esp-lwip.git source: https://github.com/randybb/esp-lwip.git
ref: idf-v5.5.5-lwip-component ref: idf-v6.1.1-lwip-component
path: lwip path: lwip
network: network:
+179
View File
@@ -0,0 +1,179 @@
#pragma once
// Header-level decoding of captured ITS-G5 frames: 802.11 + LLC/SNAP, GeoNetworking (EN 302 636-4-1)
// and BTP (EN 302 636-5-1). Gives the message type (from the BTP port) and the sender's position
// vector, which GeoNetworking carries in every packet. The message bodies (CAM, DENM, SPATEM, ...)
// are ASN.1 UPER and are not decoded here.
#include <cstddef>
#include <cstdint>
#include <vector>
namespace its_g5_decode {
struct Info {
uint16_t port{0}; // BTP destination port, 0 = none
uint8_t station_type{0}; // ETSI station type from the GN address
uint64_t addr{0}; // GN address (M bit, station type, MID), identifies the station
bool secured{false}; // carried in an ETSI TS 103 097 signed packet (signature not verified)
double lat{0}, lon{0}; // degrees
float speed_kmh{0};
float heading{0}; // degrees
};
inline const char *port_name(uint16_t port) {
switch (port) {
case 2001: return "CAM";
case 2002: return "DENM";
case 2003: return "MAPEM";
case 2004: return "SPATEM";
case 2005: return "SAEM";
case 2006: return "IVIM";
case 2007: return "SREM";
case 2008: return "SSEM";
case 2009: return "CPM";
case 2010: return "EVCSN";
case 2011: return "TRM";
case 2013: return "RTCMEM";
case 2018: return "VAM";
default: return "other";
}
}
inline const char *station_name(uint8_t type) {
static const char *const NAMES[] = {"unknown", "pedestrian", "cyclist", "moped",
"motorcycle", "passengerCar", "bus", "lightTruck",
"heavyTruck", "trailer", "specialVehicle", "tram"};
if (type < sizeof(NAMES) / sizeof(NAMES[0]))
return NAMES[type];
return type == 15 ? "roadSideUnit" : "other";
}
inline uint16_t be16(const uint8_t *p) { return (p[0] << 8) | p[1]; }
inline int32_t be32(const uint8_t *p) {
return static_cast<int32_t>((uint32_t(p[0]) << 24) | (uint32_t(p[1]) << 16) | (uint32_t(p[2]) << 8) | p[3]);
}
// Returns false for anything that is not a GeoNetworking packet it understands.
inline bool parse(const std::vector<uint8_t> &frame, Info &out) {
const uint8_t *f = frame.data();
const size_t n = frame.size();
if (n < 24 || ((f[0] >> 2) & 3) != 2) // data frames only
return false;
size_t i = 24;
const bool qos = f[0] & 0x80;
if (qos)
i += 2;
if ((f[1] & 3) == 3) // ToDS + FromDS: fourth address
i += 6;
if (qos && (f[1] & 0x80)) // +HTC
i += 4;
static const uint8_t SNAP_GN[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x47};
if (i + 8 + 4 > n)
return false;
for (size_t k = 0; k < 8; k++) {
if (f[i + k] != SNAP_GN[k])
return false;
}
i += 8;
// GN basic header: version | next header, reserved, lifetime, remaining hop limit
const uint8_t basic_nh = f[i] & 0x0F;
i += 4;
if (basic_nh == 2) {
// ponytail: walks only the usual 1609.2 shape (signedData with an unsecuredData payload, no
// external hash); anything else is skipped. A real OER decoder is needed for the rest.
if (i + 7 > n || f[i] != 0x03 || f[i + 1] != 0x81 || !(f[i + 3] & 0x40) || f[i + 4] != 0x03 ||
f[i + 5] != 0x80)
return false;
i += 6;
if (f[i] & 0x80) {
i += 1 + (f[i] & 0x7F);
} else {
i += 1;
}
out.secured = true;
} else if (basic_nh != 1) {
return false;
}
// GN common header (8 bytes): next header | reserved, header type | subtype, ...
if (i + 8 > n)
return false;
const uint8_t common_nh = f[i] >> 4;
const uint8_t ht = f[i + 1] >> 4, hst = f[i + 1] & 0x0F;
i += 8;
size_t pv, ext; // offset of the source position vector, length of the extended header
switch (ht) {
case 1: pv = i; ext = 24; break; // beacon
case 2: pv = i + 4; ext = 48; break; // GUC
case 3: case 4: pv = i + 4; ext = 44; break; // GAC, GBC
case 5: pv = hst == 0 ? i : i + 4; ext = 28; break; // SHB, TSB
default: return false; // location service, unknown
}
if (pv + 24 > n)
return false;
// Long position vector: GN address (8), timestamp (4), lat, lon (1/10 µdeg), PAI | speed, heading
out.station_type = (f[pv] >> 2) & 0x1F;
for (size_t k = 0; k < 8; k++)
out.addr = (out.addr << 8) | f[pv + k];
out.lat = be32(f + pv + 12) / 1e7;
out.lon = be32(f + pv + 16) / 1e7;
int16_t speed = be16(f + pv + 20) & 0x7FFF;
if (speed & 0x4000)
speed -= 0x8000; // 15-bit signed, 0.01 m/s
out.speed_kmh = speed * 0.036f;
out.heading = be16(f + pv + 22) / 10.0f;
if ((common_nh == 1 || common_nh == 2) && i + ext + 2 <= n) // BTP-A / BTP-B
out.port = be16(f + i + ext);
return true;
}
struct Stats {
uint32_t cam{0}, denm{0}, spatem{0}, mapem{0}, other{0};
Info last;
};
inline Stats stats;
// Parse, count and log one frame; returns false if it was not decoded.
inline bool handle(const std::vector<uint8_t> &frame) {
Info info;
if (!parse(frame, info))
return false;
switch (info.port) {
case 2001: stats.cam++; break;
case 2002: stats.denm++; break;
case 2004: stats.spatem++; break;
case 2003: stats.mapem++; break;
default: stats.other++; break;
}
stats.last = info;
return true;
}
// Rate limit per station: true if addr was not let through in the last period_ms.
// ponytail: 32 slots, the oldest is evicted; with more stations in range some publish more often.
inline bool due(uint64_t addr, uint32_t now, uint32_t period_ms) {
static struct {
uint64_t addr;
uint32_t ms;
} slots[32]{};
auto *slot = &slots[0];
for (auto &s : slots) {
if (s.addr == addr) {
slot = &s;
break;
}
if (now - s.ms > now - slot->ms)
slot = &s;
}
if (slot->addr == addr && now - slot->ms < period_ms)
return false;
*slot = {addr, now};
return true;
}
} // namespace its_g5_decode
+33
View File
@@ -0,0 +1,33 @@
// Self-check for decode.h: one signed SHB CAM frame from a passenger car.
// Build: g++ -std=c++20 decode_test.cpp -o /tmp/t && /tmp/t
#include "decode.h"
#include <cassert>
#include <cmath>
#include <cstdio>
using namespace its_g5_decode;
int main() {
std::vector<uint8_t> f = {0x88, 0x00, 0, 0, 0xff,0xff,0xff,0xff,0xff,0xff, 1,2,3,4,5,6, 0xff,0xff,0xff,0xff,0xff,0xff, 0,0, // QoS data hdr
0x00, 0x00, // QoS ctrl
0xAA,0xAA,0x03,0,0,0,0x89,0x47, // SNAP GN
0x12, 0x00, 0x1a, 0x01, // basic, NH=2 secured
0x03, 0x81, 0x00, 0x40, 0x03, 0x80, 0x30, // 1609.2 signedData/unsecuredData len
0x20, 0x50, 0x02, 0x80, 0x00, 0x30, 0x01, 0x00}; // common: NH=BTP-B, HT=5 HST=0
uint8_t pv[24] = {5 << 2, 0, 1,2,3,4,5,6, 0,0,0,0,
0x1C,0xB3,0x8A,0x40, // lat 481528384 -> 48.1528384
0x0A,0x34,0x5A,0x60, // lon 171203168 -> 17.1203168
0x05,0x6E, // 1390 * 0.01 m/s = 50.04 km/h
0x04,0xD2}; // 123.4 deg
f.insert(f.end(), pv, pv + 24);
uint8_t media[4] = {0}; f.insert(f.end(), media, media + 4);
uint8_t btp[4] = {0x07, 0xD1, 0, 0}; f.insert(f.end(), btp, btp + 4); // port 2001
Info i;
assert(parse(f, i));
assert(i.secured && i.port == 2001 && i.station_type == 5);
assert(std::fabs(i.lat - 48.1528384) < 1e-7 && std::fabs(i.lon - 17.1203168) < 1e-7);
assert(std::fabs(i.speed_kmh - 50.04f) < 0.01f && std::fabs(i.heading - 123.4f) < 0.01f);
assert(i.addr == 0x1400010203040506ULL);
assert(handle(f) && stats.cam == 1);
assert(due(i.addr, 1000, 1000) && !due(i.addr, 1999, 1000) && due(2, 1999, 1000) && due(i.addr, 2000, 1000));
f[30] = 0x48; assert(!parse(f, i)); // not GeoNetworking
std::puts("ok");
}
-166
View File
@@ -1,166 +0,0 @@
---
# Sonoff NSPanel with the native Lovelace UI (randybb/esphome-nspanel-lovelace-native).
# The device file adds the cards, buttons and relays:
# packages:
# common: !include common/common.yaml
# nspanel: !include
# file: common/nspanel.yaml
# vars:
# temperature_entity: sensor.zigbee_bedroom_temperature
# nspanel_lovelace:
# cards: [...]
defaults:
temperature_name: Temperature
ntc_reference_temperature: 25°C
esphome:
on_boot:
then:
- switch.turn_off: screen_power
- delay: 1s
- switch.turn_on: screen_power
- delay: 2s
- lambda: 'id(nspanel_id).set_display_dim(5, 80);'
esp32:
variant: esp32
toolchain: esp-idf
framework:
type: esp-idf
advanced:
flash_chip: generic
minimum_chip_revision: 3.0
sram1_as_iram: true
packages:
popup: !include nspanel_popup.yaml
external_components:
- source:
type: git
url: https://github.com/randybb/esphome-nspanel-lovelace-native
ref: devices
refresh: 0s
components: [nspanel_lovelace]
api:
homeassistant_services: true
homeassistant_states: true
actions:
- action: play_rtttl
variables:
song: string
then:
- rtttl.play:
rtttl: !lambda 'return song;'
- action: notify
variables:
heading: string
message: string
song: string
then:
- lambda: 'id(nspanel_id).notify_on_screensaver(heading, message, 10000);'
- rtttl.play:
rtttl: !lambda 'return song;'
- action: notify_fullscreen
variables:
title: string
description: string
button1: string
button2: string
timeout: int
icon: string
then:
- lambda: 'id(nspanel_id).notify_on_screensaver(title, description, timeout);'
- rtttl.play: "scale_up:d=32,o=5,b=100:c,c#,d#,e,f#,g#,a#,b"
uart:
id: display_uart
tx_pin: 16
rx_pin: 17
baud_rate: 115200
nspanel_lovelace:
id: nspanel_id
sleep_timeout: 10
experimental_vertical_ui: true
locale:
language: sk
temperature_unit: celcius
screensaver:
time_id: ha_time
time_format: '%H:%M'
date_format: '%A, %d. %b. %Y'
weather:
entity_id: sensor.weather_forecast_daily
icon_color: [255, 255, 255]
entities:
- entity_id: ${temperature_entity}
icon:
value: home-thermometer-outline
color: [255, 255, 255]
precision: 1
output:
- platform: ledc
id: buzzer_out
pin:
number: 21
switch:
- platform: gpio
name: Screen Power
id: screen_power
entity_category: config
pin:
number: 4
inverted: true
restore_mode: ALWAYS_ON
rtttl:
id: buzzer
output: buzzer_out
sensor:
- platform: adc
id: ntc_source
pin: 38
update_interval: 5min
attenuation: 12db
- platform: resistance
id: resistance_sensor
sensor: ntc_source
configuration: DOWNSTREAM
resistor: 11.2kOhm
- platform: ntc
name: ${temperature_name}
id: temperature
sensor: resistance_sensor
calibration:
b_constant: 3950
reference_temperature: ${ntc_reference_temperature}
reference_resistance: 10kOhm
text_sensor:
- platform: homeassistant
id: name_day
entity_id: sensor.nameday_sk
on_value:
- lambda: |-
id(nspanel_id).set_time_format("%H:%M~" + x);
id(nspanel_id).update_time();
# HMI protocol version reported by the TFT on startup (52/53 for this UI)
- platform: template
name: TFT Version
entity_category: diagnostic
update_interval: 60s
lambda: |-
using esphome::nspanel_lovelace::Configuration;
const auto ver = Configuration::get_version();
if (ver == 0) return {"unknown"};
return {std::to_string(ver) + " (" + Configuration::get_model_str() + ")"};
-98
View File
@@ -1,98 +0,0 @@
---
# NSPanel popups (popupNotify page), without changes to nspanel_lovelace:
# - OTA progress
# - device info (version, IPs) via the show_info API action
# Needs nspanel_lovelace (id nspanel_id), its uart (id display_uart) and the
# ota id ota_esphome (common/ota_esp32.yaml).
# The component doesn't track these popups; the panel either reboots (OTA)
# or goes back to the default page afterwards.
api:
actions:
- action: show_info
then:
- script.execute: info_popup
script:
- id: info_popup
mode: restart
then:
- lambda: |-
char build[Application::BUILD_TIME_STR_SIZE];
App.get_build_time_string(build);
std::string msg = "ESPHome " ESPHOME_VERSION "\r\n";
msg += build;
// global/ULA first, link-local last
std::vector<std::string> ips;
for (int pass = 0; pass < 2; pass++) {
for (auto &ip : wifi::global_wifi_component->wifi_sta_ip_addresses()) {
if (!ip.is_set()) continue;
char buf[network::IP_ADDRESS_BUFFER_SIZE];
ip.str_to(buf);
bool ll = strncmp(buf, "fe80", 4) == 0;
if (ll == (pass == 1)) ips.emplace_back(buf);
}
}
for (auto &ip : ips) msg += "\r\n" + ip;
id(nspanel_id).send_display_command("pageType~popupNotify");
id(nspanel_id).send_display_command(
"entityUpdateDetail~info~" + App.get_friendly_name() + "~65535~~65535~~65535~" + msg + "~65535~15");
- delay: 15s
- lambda: 'id(nspanel_id).render_default_page();'
# OTA blocks the main loop, and nspanel_lovelace only sends its queued
# commands from loop(), so these frames go straight to the uart in the
# component's format: 55 BB, length (LE), command, CRC16 (LE).
- id: ota_popup
parameters:
message: string
then:
- lambda: |-
auto send = [](const std::string &cmd) {
uint8_t hdr[4] = {0x55, 0xBB, uint8_t(cmd.size() & 0xFF), uint8_t(cmd.size() >> 8)};
uint16_t crc = crc16(hdr, 4);
crc = crc16(reinterpret_cast<const uint8_t *>(cmd.data()), cmd.size(), crc);
uint8_t tail[2] = {uint8_t(crc & 0xFF), uint8_t(crc >> 8)};
id(display_uart).write_array(hdr, 4);
id(display_uart).write_array(reinterpret_cast<const uint8_t *>(cmd.data()), cmd.size());
id(display_uart).write_array(tail, 2);
id(display_uart).flush();
};
send("dimmode~100~100");
send("pageType~popupNotify");
send("entityUpdateDetail~ota~Aktualizácia firmvéru~65535~~65535~~65535~" + message + "~65535~0");
ota:
- id: !extend ota_esphome
on_begin:
- script.execute:
id: ota_popup
message: Nahrávam…
on_progress:
- lambda: |-
static int last = -1;
int pct = (int) x / 10 * 10;
if (pct != last) {
last = pct;
id(ota_popup)->execute("Nahrávam… " + std::to_string(pct) + " %");
}
on_end:
- script.execute:
id: ota_popup
message: Hotovo, reštartujem
on_error:
- script.execute:
id: ota_popup
message: Aktualizácia zlyhala
- delay: 5s
- lambda: |-
id(nspanel_id).set_display_dim(5, 80);
id(nspanel_id).render_default_page();
button:
# put button.<device>_info on a card: the panel presses it through HA
- platform: template
name: Info
id: info_button
entity_category: diagnostic
on_press:
- script.execute: info_popup
-42
View File
@@ -1,42 +0,0 @@
---
# NSPanel screensaver dims to 0 at night (sun below -6°), unless the room lights are on.
# packages:
# sleep_dim: !include
# file: common/nspanel_sleep_dim.yaml
# vars:
# sleep_override_entity: light.bedroom_lights
script:
- id: apply_sleep_dim
then:
- lambda: |-
uint8_t dim;
if (id(sleep_override).state) dim = 5; // sleepOverride
else if (id(sun_id).is_above_horizon(-6)) dim = 5; // day
else dim = 0; // night
id(nspanel_id).set_display_inactive_dim(dim);
time:
- id: !extend ha_time
on_time_sync:
- script.execute: apply_sleep_dim
binary_sensor:
- platform: homeassistant # sleepOverride
id: sleep_override
entity_id: ${sleep_override_entity}
on_state:
- script.execute: apply_sleep_dim
sun:
id: sun_id
time_id: ha_time
latitude: 48.15°
longitude: 17.11°
on_sunrise:
- elevation: -6°
then:
- script.execute: apply_sleep_dim
on_sunset:
- elevation: -6°
then:
- script.execute: apply_sleep_dim
+14
View File
@@ -0,0 +1,14 @@
# Package: tile on a grid page that calls a Home Assistant action on an entity (e.g. button.press).
# Its checked/disabled states are up to the owner (e.g. gate.yaml). Tiles fill the page in package order.
# vars: page, id, name, icon (MDI glyph, must be in icon_s), action, entity
lvgl:
pages:
- id: !extend ${page}
widgets:
- button:
<<: !include {file: tile.yaml, vars: {id: "${id}", name: "${name}", icon: "${icon}"}}
on_click:
- homeassistant.action:
action: ${action}
data:
entity_id: ${entity}
@@ -0,0 +1,44 @@
# Package: fireplace icon in the home page icon row (white while it burns, grey while not, dark grey unavailable).
# Hidden outside the heating season: fire out and the boiler switch off.
# defaults: entity (fire binary_sensor), boiler (switch that lets the boiler fire)
defaults:
entity: binary_sensor.heating_fireplace_fire
boiler: switch.heating_enabled
lvgl:
pages:
- id: !extend page_home
widgets:
- obj:
id: !extend home_icons
widgets:
- label:
id: fireplace_icon
text: "\U000F0E2F"
text_font: icon_s
text_color: 0x48484A
script:
- id: fireplace_icon_update
then:
- lambda: |-
const std::string &fire = id(fireplace_fire).state;
const bool on = fire == "on";
lv_label_set_text(id(fireplace_icon), on ? "\U000F0E2E" : "\U000F0E2F");
lv_obj_set_style_text_color(id(fireplace_icon), lv_color_hex(on ? 0xFFFFFF : ha_unavailable(fire) ? 0x48484A : 0x8E8E93), 0);
lv_obj_set_hidden(id(fireplace_icon), fire == "off" && id(fireplace_boiler).state == "off");
text_sensor:
# text, not binary: a binary sensor drops "unavailable"
- platform: homeassistant
id: fireplace_fire
entity_id: ${entity}
internal: true
on_value:
- script.execute: fireplace_icon_update
- platform: homeassistant
id: fireplace_boiler
entity_id: ${boiler}
internal: true
on_value:
- script.execute: fireplace_icon_update
+49
View File
@@ -0,0 +1,49 @@
# One forecast row: day, icon, day/night temperature on two lines, all centred vertically.
# Not clickable, so a tap falls through to the home page.
obj:
clickable: false
width: SIZE_CONTENT
height: SIZE_CONTENT
bg_opa: TRANSP
border_width: 0
pad_all: 0
layout:
type: FLEX
flex_flow: ROW
flex_align_cross: CENTER
pad_column: 8
widgets:
- label:
id: forecast_day_${i}
text: ""
text_font: font_s
text_color: 0xB4B4BA
width: 26
text_align: RIGHT
- label:
id: forecast_icon_${i}
text: ""
text_font: icon_s
text_color: 0xFFFFFF
- obj:
clickable: false
width: SIZE_CONTENT
height: SIZE_CONTENT
bg_opa: TRANSP
border_width: 0
pad_all: 0
layout:
type: FLEX
flex_flow: COLUMN
pad_row: 0
widgets:
- label:
id: forecast_high_${i}
text: ""
text_font: font_s
text_color: 0xFFFFFF
- label:
id: forecast_low_${i}
text: ""
text_font: font_s
text_color: 0x8E8E93
+55
View File
@@ -0,0 +1,55 @@
# Package: gate state tile (two slots) on a grid page, and the state of the gate_open/gate_close action tiles
# vars: page, state (select with Open/Closed/Opening/Closing)
lvgl:
pages:
- id: !extend ${page}
widgets:
# highlighted while not closed
- obj:
id: gate_state_tile
clickable: false
width: 272
height: 112
styles: tile_style
checked:
bg_color: 0xF5B342
text_color: 0x000000
disabled:
bg_color: 0x161618
text_color: 0x48484A
widgets:
- label:
id: gate_state_icon
text: ""
text_font: icon_l
align: LEFT_MID
- label:
id: gate_state_label
text: ""
align: LEFT_MID
x: 64
text_sensor:
- platform: homeassistant
id: gate_state
entity_id: ${state}
internal: true
on_value:
- lambda: |-
static const char *const STATES[][3] = {{"Open", "Otvorená", "\U000F116A"},
{"Closed", "Zatvorená", "\U000F0299"},
{"Opening", "Otvára sa", "\U000F1169"},
{"Closing", "Zatvára sa", "\U000F17F7"}};
const char *text = x.c_str(), *icon = "\U000F17F8";
for (auto &s : STATES)
if (x == s[0]) text = s[1], icon = s[2];
lv_label_set_text(id(gate_state_label), text);
lv_label_set_text(id(gate_state_icon), icon);
// highlighted unless closed
lv_obj_set_state(id(gate_state_tile), LV_STATE_CHECKED, x != "Closed");
// the button of the running movement
lv_obj_set_state(id(gate_open), LV_STATE_CHECKED, x == "Opening");
lv_obj_set_state(id(gate_close), LV_STATE_CHECKED, x == "Closing");
// gate controller offline: grey out the whole gate page
for (lv_obj_t *o : {(lv_obj_t *) id(gate_open), (lv_obj_t *) id(gate_close), id(gate_state_tile)})
lv_obj_set_state(o, LV_STATE_DISABLED, ha_unavailable(x));
+21
View File
@@ -0,0 +1,21 @@
# Grid page (list item of lvgl pages): title and arrows; the 2x3 tiles come from the *_tile.yaml packages
# vars: id, title, prev, next (page ids for the arrows), skip (hidden page: out of the page cycle, no next arrow)
id: ${id}
skip: ${skip}
styles: page_style
# header 64 px high (arrow touch area), 2x112 tiles + gap below, 8 px left at the bottom
pad_bottom: 8
layout:
type: FLEX
flex_flow: ROW_WRAP
widgets:
- label:
text: "${title}"
text_font: font_s
text_color: 0xB4B4BA
width: 100%
height: 48
pad_top: 14
text_align: CENTER
- <<: !include {file: page_arrow.yaml, vars: {icon: "\U000F0141", align: TOP_LEFT, x: -16, to: "${prev}", hidden: false}}
- <<: !include {file: page_arrow.yaml, vars: {icon: "\U000F0142", align: TOP_RIGHT, x: 16, to: "${next}", hidden: "${skip}"}}
+5
View File
@@ -0,0 +1,5 @@
#pragma once
#include <string>
// Home Assistant entity state that means "no usable value": the tile is shown greyed out and disabled
inline bool ha_unavailable(const std::string &s) { return s.empty() || s == "unavailable" || s == "unknown"; }
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
// HA brightness 0..255 -> slider percent; NaN (light off) -> 0
inline int brightness_pct(float b) { return std::isnan(b) ? 0 : int(std::lround(b * 100 / 255)); }
// Hue from the hs_color attribute, "(30.0, 80.0)" or "[30.0, 80.0]"; -1 if missing
inline int parse_hue(const std::string &s) {
size_t p = s.find_first_of("([");
if (p == std::string::npos) return -1;
char *end;
float h = std::strtof(s.c_str() + p + 1, &end);
return end == s.c_str() + p + 1 ? -1 : int(std::lround(h));
}
+63
View File
@@ -0,0 +1,63 @@
# Package: Home Assistant light as a tile on a grid page, with its state. Tap toggles, long press opens page_light.
# Tiles fill the page in package order.
# vars: page, id, name, entity, icon (MDI glyph, must be in icon_s),
# dim (brightness), kmin (lowest colour temperature in K, 0 = none), hs (hue)
lvgl:
pages:
- id: !extend ${page}
widgets:
- button:
<<: !include {file: tile.yaml, vars: {id: "${id}", name: "${name}", icon: "${icon}"}}
# not checkable: the checked state comes only from Home Assistant
on_short_click:
- homeassistant.action:
action: light.toggle
data:
entity_id: ${entity}
on_long_press:
- script.execute:
id: open_light
entity: ${entity}
name: "${name}"
dim: ${dim}
kmin: ${kmin}
hs: ${hs}
is_on: !lambda return id(${id}_state).state == "on";
bri: !lambda return id(${id}_bri).state;
ct: !lambda return id(${id}_ct).state;
hue: !lambda return id(${id}_hs).state;
sensor:
- platform: homeassistant
id: ${id}_bri
entity_id: ${entity}
attribute: brightness
internal: true
on_value:
- lambda: 'if (id(cur_light) == "${entity}") lv_slider_set_value(id(detail_bri), brightness_pct(x), LV_ANIM_OFF);'
- platform: homeassistant
id: ${id}_ct
entity_id: ${entity}
attribute: color_temp_kelvin
internal: true
on_value:
- lambda: 'if (id(cur_light) == "${entity}") lv_slider_set_value(id(detail_ct), x, LV_ANIM_OFF);'
text_sensor:
# text, not binary: a binary sensor drops "unavailable"
- platform: homeassistant
id: ${id}_state
entity_id: ${entity}
internal: true
on_value:
- lambda: |-
lv_obj_set_state(id(${id}), LV_STATE_CHECKED, x == "on");
lv_obj_set_state(id(${id}), LV_STATE_DISABLED, ha_unavailable(x));
if (id(cur_light) == "${entity}") lv_obj_set_state(id(detail_power), LV_STATE_CHECKED, x == "on");
- platform: homeassistant
id: ${id}_hs
entity_id: ${entity}
attribute: hs_color
internal: true
on_value:
- lambda: 'if (id(cur_light) == "${entity}") lv_slider_set_value(id(detail_hue), parse_hue(x), LV_ANIM_OFF);'
+19
View File
@@ -0,0 +1,19 @@
# Package: tile on a grid page that opens another page, a big icon only (e.g. the robot for automations)
# vars: page, to (page id), icon (MDI glyph, must be in icon_l)
lvgl:
pages:
- id: !extend ${page}
widgets:
- button:
width: 130
height: 112
styles: tile_style
pressed:
bg_color: 0x48484A
on_click:
- lvgl.page.show: ${to}
widgets:
- label:
text: "${icon}"
text_font: icon_l
align: CENTER
+21
View File
@@ -0,0 +1,21 @@
# Page switch arrow in a top corner; floats over the page's flex layout
# vars: icon, align, x, to (page id), hidden
obj:
floating: true
hidden: ${hidden}
align: ${align}
x: ${x}
y: -16
width: 88
height: 64
bg_opa: TRANSP
border_width: 0
pad_all: 0
on_click:
- lvgl.page.show: ${to}
widgets:
- label:
text: "${icon}"
text_font: icon_s
text_color: 0xB4B4BA
align: CENTER
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,70 @@
# Package: radiator icon in the home page icon row:
# disabled (grey) while the thermostat does not call for heat, off (grey) while it does but the off-peak tariff
# is off (the boiler is then hard off) and the fireplace is out, on (white) while it heats.
# Hidden outside the heating season: boiler switch off and the fireplace out.
# vars: id (prefix of its ids, unique per icon), entity (climate);
# defaults: boiler (switch that lets the boiler fire), fire (fireplace binary_sensor), off_peak (tariff binary_sensor)
defaults:
boiler: switch.heating_enabled
fire: binary_sensor.heating_fireplace_fire
off_peak: binary_sensor.heater_off_peak
lvgl:
pages:
- id: !extend page_home
widgets:
- obj:
id: !extend home_icons
widgets:
- label:
id: ${id}_icon
text: "\U000F0AD8"
text_font: icon_s
text_color: 0x48484A
script:
- id: ${id}_update
then:
- lambda: |-
const std::string &boiler = id(${id}_boiler).state, &fire = id(${id}_fire).state;
const bool demand = id(${id}_action).state == "heating";
// the burning fireplace heats the water without the boiler
const bool heating = demand && (id(${id}_off_peak).state != "off" || fire == "on");
lv_label_set_text(id(${id}_icon), !demand ? "\U000F0AD7" : heating ? "\U000F0438" : "\U000F0AD8");
const bool unavailable = ha_unavailable(id(${id}_mode).state);
lv_obj_set_style_text_color(id(${id}_icon), lv_color_hex(heating ? 0xFFFFFF : unavailable ? 0x48484A : 0x8E8E93), 0);
lv_obj_set_hidden(id(${id}_icon), boiler == "off" && fire == "off");
text_sensor:
- platform: homeassistant
id: ${id}_boiler
entity_id: ${boiler}
internal: true
on_value:
- script.execute: ${id}_update
- platform: homeassistant
id: ${id}_fire
entity_id: ${fire}
internal: true
on_value:
- script.execute: ${id}_update
- platform: homeassistant
id: ${id}_off_peak
entity_id: ${off_peak}
internal: true
on_value:
- script.execute: ${id}_update
# the climate state only tells whether the thermostat is reachable
- platform: homeassistant
id: ${id}_mode
entity_id: ${entity}
internal: true
on_value:
- script.execute: ${id}_update
- platform: homeassistant
id: ${id}_action
entity_id: ${entity}
attribute: hvac_action
internal: true
on_value:
- script.execute: ${id}_update
+44
View File
@@ -0,0 +1,44 @@
---
# NSPanel sleep dim: the idle (dimmed) brightness drops to 0 at night
# (sun below -6°), unless the room light is on. Sets the idle_brightness global of panel.yaml (${dim_brightness} or 0).
# packages:
# sleep_dim: !include
# file: common/nspanel_terminal/sleep_dim.yaml
# vars:
# sleep_override_entity: light.bedroom_lights
script:
- id: apply_sleep_dim
then:
- lambda: |-
bool day = id(sun_id).is_above_horizon(-6);
id(idle_brightness) = id(sleep_override).state == "on" || day ? ${dim_brightness} : 0;
if (id(dimmed))
id(panel).request_brightness(id(idle_brightness));
time:
- id: !extend ha_time
on_time_sync:
- script.execute: apply_sleep_dim
text_sensor:
# sleepOverride; text, not binary: a binary sensor drops "unavailable"
- platform: homeassistant
id: sleep_override
entity_id: ${sleep_override_entity}
internal: true
on_value:
- script.execute: apply_sleep_dim
sun:
id: sun_id
time_id: ha_time
latitude: 48.15°
longitude: 17.11°
on_sunrise:
- elevation: -6°
then:
- script.execute: apply_sleep_dim
on_sunset:
- elevation: -6°
then:
- script.execute: apply_sleep_dim
+12
View File
@@ -0,0 +1,12 @@
# Package: empty slot on a grid page (e.g. to start the next row)
# vars: page
lvgl:
pages:
- id: !extend ${page}
widgets:
- obj:
clickable: false
width: 130
height: 112
bg_opa: TRANSP
border_width: 0
+25
View File
@@ -0,0 +1,25 @@
# Package: on/off Home Assistant entity (switch, automation, ...) as a tile on a grid page, with its state.
# Tiles fill the page in package order.
# vars: page, id, name, entity, icon (MDI glyph, must be in icon_s), domain (tap calls <domain>.toggle)
lvgl:
pages:
- id: !extend ${page}
widgets:
- button:
<<: !include {file: tile.yaml, vars: {id: "${id}", name: "${name}", icon: "${icon}"}}
on_click:
- homeassistant.action:
action: ${domain}.toggle
data:
entity_id: ${entity}
text_sensor:
# text, not binary: a binary sensor drops "unavailable"
- platform: homeassistant
id: ${id}_state
entity_id: ${entity}
internal: true
on_value:
- lambda: |-
lv_obj_set_state(id(${id}), LV_STATE_CHECKED, x == "on");
lv_obj_set_state(id(${id}), LV_STATE_DISABLED, ha_unavailable(x));
+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include <string>
#include <vector>
// HA list attribute as sent to ESPHome, "['none', 'away']" or '["none", "away"]' -> items
inline std::vector<std::string> parse_list(const std::string &s) {
std::vector<std::string> out;
for (size_t p = 0; (p = s.find_first_of("'\"", p)) != std::string::npos;) {
size_t end = s.find(s[p], p + 1);
if (end == std::string::npos) break;
out.push_back(s.substr(p + 1, end - p - 1));
p = end + 1;
}
return out;
}
// Display name for a climate preset; unknown presets are shown as they come
inline std::string preset_name(const std::string &p) {
static const char *const NAMES[][2] = {{"none", "Žiadny"}, {"home", "Doma"}, {"away", "Preč"},
{"eco", "Eco"}, {"comfort", "Komfort"}, {"sleep", "Spánok"},
{"activity", "Aktivita"}, {"boost", "Boost"}};
for (auto &n : NAMES)
if (p == n[0]) return n[1];
return p;
}
+328
View File
@@ -0,0 +1,328 @@
# Package: thermostat page (arc with target temperature, -/+, heat/off, boiler switch, presets) and its HA state.
# vars: id (prefix of its ids, unique per thermostat page), page, title, prev, next (page ids for the arrows),
# entity (climate with heat/off and presets),
# boiler (switch that lets the boiler fire, the same in every room)
defaults:
boiler: switch.heating_enabled
globals:
# preset_modes of the thermostat, in dropdown order
- id: ${id}_preset_list
type: std::vector<std::string>
lvgl:
pages:
- id: ${page}
styles: page_style
widgets:
- label:
text: "${title}"
text_font: font_s
text_color: 0xB4B4BA
width: 100%
text_align: CENTER
- <<: !include
file: page_arrow.yaml
vars: {icon: "\U000F0141", align: TOP_LEFT, x: -16, to: "${prev}", hidden: false}
- <<: !include
file: page_arrow.yaml
vars: {icon: "\U000F0142", align: TOP_RIGHT, x: 16, to: "${next}", hidden: false}
# target temperature in half degrees, 10..30 °C
- arc:
id: ${id}_arc
disabled:
arc_color: 0x161618
align: BOTTOM_LEFT
y: -20
width: 220
height: 220
min_value: 20
max_value: 60
arc_width: 16
arc_color: 0x2C2C2E
indicator:
arc_width: 16
arc_color: 0x8E8E93
knob:
bg_color: 0xFFFFFF
pad_all: 2
on_value:
- lambda: 'lv_label_set_text_fmt(id(${id}_target_label), "%.1f", x / 2.0f);'
on_release:
- script.execute: ${id}_send_target
widgets:
- obj:
clickable: false
align: CENTER
y: -8
width: SIZE_CONTENT
height: SIZE_CONTENT
bg_opa: TRANSP
border_width: 0
pad_all: 0
text_color: 0xFFFFFF
layout:
type: FLEX
flex_flow: ROW
flex_align_cross: START
pad_column: 2
widgets:
- label:
id: ${id}_target_label
text: "-"
text_font: font_big
text_color: 0xFFFFFF
- label:
text: "°C"
y: 6
text_color: 0xB4B4BA
- label:
id: ${id}_current_label
text: ""
text_font: font_s
text_color: 0xB4B4BA
align: CENTER
y: 34
- label:
id: ${id}_action_label
text: ""
text_font: font_s
text_color: 0x8E8E93
align: CENTER
y: -50
- button:
id: ${id}_minus
align: BOTTOM_LEFT
x: 46
width: 56
height: 44
styles: tile_style
disabled:
bg_color: 0x161618
text_color: 0x48484A
pad_all: 0
on_click:
- lambda: |-
lv_arc_set_value(id(${id}_arc), lv_arc_get_value(id(${id}_arc)) - 1);
lv_label_set_text_fmt(id(${id}_target_label), "%.1f", lv_arc_get_value(id(${id}_arc)) / 2.0f);
- script.execute: ${id}_send_target
widgets:
- label:
text: "\U000F0374"
text_font: icon_s
align: CENTER
- button:
id: ${id}_plus
align: BOTTOM_LEFT
x: 118
width: 56
height: 44
styles: tile_style
disabled:
bg_color: 0x161618
text_color: 0x48484A
pad_all: 0
on_click:
- lambda: |-
lv_arc_set_value(id(${id}_arc), lv_arc_get_value(id(${id}_arc)) + 1);
lv_label_set_text_fmt(id(${id}_target_label), "%.1f", lv_arc_get_value(id(${id}_arc)) / 2.0f);
- script.execute: ${id}_send_target
widgets:
- label:
text: "\U000F0415"
text_font: icon_s
align: CENTER
- button:
id: ${id}_power
align: TOP_RIGHT
x: -90
y: 56
width: 82
height: 44
styles: tile_style
disabled:
bg_color: 0x161618
text_color: 0x48484A
pad_all: 0
checked:
bg_color: 0xF5B342
text_color: 0x000000
on_click:
- homeassistant.action:
action: climate.set_hvac_mode
data:
entity_id: ${entity}
hvac_mode: !lambda 'return id(${id}_mode).state == "heat" ? "off" : "heat";'
widgets:
- label:
text: "\U000F0438"
text_font: icon_s
align: LEFT_MID
x: 6
- label:
text: "Izba"
text_font: font_s
align: RIGHT_MID
x: -8
# the boiler only fires with this switch on
- button:
id: ${id}_boiler_button
align: TOP_RIGHT
x: 0
y: 56
width: 82
height: 44
styles: tile_style
disabled:
bg_color: 0x161618
text_color: 0x48484A
pad_all: 0
checked:
bg_color: 0xF5B342
text_color: 0x000000
on_click:
- homeassistant.action:
action: switch.toggle
data:
entity_id: ${boiler}
widgets:
- label:
text: "\U000F0238"
text_font: icon_s
align: LEFT_MID
x: 6
- label:
text: "Kotol"
text_font: font_s
align: RIGHT_MID
x: -8
# options come from the preset_modes attribute (thermostat.yaml)
- dropdown:
id: ${id}_preset_dropdown
disabled:
text_color: 0x48484A
align: TOP_RIGHT
y: 112
width: 172
options: ["-"]
styles: tile_style
pad_all: 10
symbol: "\U000F0140"
indicator:
text_font: icon_s
dropdown_list:
bg_color: 0x2C2C2E
text_color: 0xFFFFFF
text_font: font_m
border_width: 0
radius: 14
selected:
checked:
bg_color: 0xF5B342
text_color: 0x000000
on_value:
- homeassistant.action:
action: climate.set_preset_mode
data:
entity_id: ${entity}
preset_mode: !lambda 'return x < id(${id}_preset_list).size() ? id(${id}_preset_list)[x] : std::string();'
sensor:
- platform: homeassistant
id: ${id}_target
entity_id: ${entity}
attribute: temperature
internal: true
on_value:
- lambda: |-
if (std::isnan(x)) return;
lv_arc_set_value(id(${id}_arc), std::lround(x * 2));
lv_label_set_text_fmt(id(${id}_target_label), "%.1f", x);
- platform: homeassistant
id: ${id}_current
entity_id: ${entity}
attribute: current_temperature
internal: true
on_value:
- lambda: 'lv_label_set_text_fmt(id(${id}_current_label), "teraz %.1f°C", x);'
text_sensor:
# text, not binary: a binary sensor drops "unavailable"
- platform: homeassistant
id: ${id}_boiler
entity_id: ${boiler}
internal: true
on_value:
- lambda: |-
lv_obj_set_state(id(${id}_boiler_button), LV_STATE_CHECKED, x == "on");
lv_obj_set_state(id(${id}_boiler_button), LV_STATE_DISABLED, ha_unavailable(x));
- platform: homeassistant
id: ${id}_mode
entity_id: ${entity}
internal: true
on_value:
- lambda: |-
lv_obj_set_state(id(${id}_power), LV_STATE_CHECKED, x == "heat");
// thermostat unavailable: grey out its controls
for (lv_obj_t *o : {(lv_obj_t *) id(${id}_power), (lv_obj_t *) id(${id}_arc), id(${id}_minus), id(${id}_plus),
id(${id}_preset_dropdown)->obj})
lv_obj_set_state(o, LV_STATE_DISABLED, ha_unavailable(x));
- script.execute: ${id}_update_action
- platform: homeassistant
id: ${id}_action
entity_id: ${entity}
attribute: hvac_action
internal: true
on_value:
- script.execute: ${id}_update_action
- platform: homeassistant
id: ${id}_presets
entity_id: ${entity}
attribute: preset_modes
internal: true
on_value:
- lambda: |-
id(${id}_preset_list) = parse_list(x);
std::string options;
for (auto &p : id(${id}_preset_list)) options += (options.empty() ? "" : "\n") + preset_name(p);
lv_dropdown_set_options(id(${id}_preset_dropdown)->obj, options.c_str());
- script.execute: ${id}_select_preset
- platform: homeassistant
id: ${id}_preset
entity_id: ${entity}
attribute: preset_mode
internal: true
on_value:
- script.execute: ${id}_select_preset
script:
# Arc and -/+ change the target locally; send once the user stops for a moment
- id: ${id}_send_target
mode: restart
then:
- delay: 800ms
- homeassistant.action:
action: climate.set_temperature
data:
entity_id: ${entity}
temperature: !lambda return lv_arc_get_value(id(${id}_arc)) / 2.0f;
# back to what HA has, in case it did not take the change (e.g. actions not allowed for this device)
- delay: 5s
- lambda: |-
float target = id(${id}_target).state;
if (std::isnan(target)) return;
lv_arc_set_value(id(${id}_arc), std::lround(target * 2));
lv_label_set_text_fmt(id(${id}_target_label), "%.1f", target);
- id: ${id}_update_action
then:
- lambda: |-
bool off = id(${id}_mode).state == "off";
bool heating = id(${id}_action).state == "heating";
lv_label_set_text(id(${id}_action_label), off ? "vypnuté" : heating ? "kúri" : "nekúri");
lv_obj_set_style_arc_color(id(${id}_arc), lv_color_hex(heating ? 0xF5B342 : 0x8E8E93), LV_PART_INDICATOR);
- id: ${id}_select_preset
then:
- lambda: |-
auto &list = id(${id}_preset_list);
auto it = std::find(list.begin(), list.end(), id(${id}_preset).state);
if (it != list.end()) lv_dropdown_set_selected(id(${id}_preset_dropdown)->obj, it - list.begin());
+25
View File
@@ -0,0 +1,25 @@
# Look of a 2x3 grid tile (button body): icon top left, name bottom left; merge it into a button with <<:
# checked = on (orange), disabled = entity unavailable (grey), pressed = touch feedback
# vars: id, name, icon (MDI glyph, must be in icon_s)
id: ${id}
width: 130
height: 112
styles: tile_style
pressed:
bg_color: 0x48484A
checked:
bg_color: 0xF5B342
text_color: 0x000000
disabled:
bg_color: 0x161618
text_color: 0x48484A
widgets:
- label:
text: "${icon}"
text_font: icon_s
align: TOP_LEFT
- label:
text: "${name}"
align: BOTTOM_LEFT
long_mode: WRAP
width: 100%
+57
View File
@@ -0,0 +1,57 @@
#pragma once
#include <cstdlib>
#include <cstring>
#include <string>
// Home Assistant weather condition -> MDI icon (glyphs listed in the font: config)
inline const char *weather_icon(const std::string &c) {
static const char *const MAP[][2] = {
{"clear-night", "\U000F0594"}, {"sunny", "\U000F0599"}, {"partlycloudy", "\U000F0595"},
{"cloudy", "\U000F0590"}, {"fog", "\U000F0591"}, {"rainy", "\U000F0597"},
{"pouring", "\U000F0596"}, {"snowy", "\U000F0598"}, {"snowy-rainy", "\U000F067F"},
{"hail", "\U000F0592"}, {"lightning", "\U000F0593"}, {"lightning-rainy", "\U000F067E"},
{"windy", "\U000F059D"}, {"windy-variant", "\U000F059E"}, {"exceptional", "\U000F05D6"}};
for (auto &m : MAP)
if (c == m[0]) return m[1];
return "";
}
// One day of the HA `forecast` attribute as sent to ESPHome (Python repr or JSON of a list of dicts).
struct ForecastDay {
std::string condition;
float high, low;
};
// Value after `key` in s, starting at pos; works for 'key': and "key":
static inline const char *forecast_value_(const std::string &s, size_t pos, const char *key, size_t end) {
size_t k = s.find(key, pos);
if (k == std::string::npos || k >= end) return nullptr;
k = s.find(':', k + std::strlen(key));
if (k == std::string::npos || k >= end) return nullptr;
while (++k < end && (s[k] == ' ' || s[k] == '\'' || s[k] == '"')) {
}
return s.c_str() + k;
}
// Fills up to n days starting at index `first`; returns how many were parsed.
inline int parse_forecast(const std::string &s, int first, ForecastDay *out, int n) {
int index = 0, got = 0;
size_t pos = 0;
while (got < n && (pos = s.find('{', pos)) != std::string::npos) {
size_t end = s.find('}', pos);
if (end == std::string::npos) break;
if (index++ >= first) {
const char *cond = forecast_value_(s, pos, "condition", end);
const char *high = forecast_value_(s, pos, "temperature", end);
const char *low = forecast_value_(s, pos, "templow", end);
if (cond && high && low) {
out[got].condition.assign(cond, std::strcspn(cond, "'\","));
out[got].high = std::strtof(high, nullptr);
out[got].low = std::strtof(low, nullptr);
++got;
}
}
pos = end;
}
return got;
}
+36
View File
@@ -0,0 +1,36 @@
---
# Pip-Boy list row for mcu-lvgl's DATA tab: name left, value (id ${row}_val) right, select by touch
# vars: row (widget id), name (left text), idx (row index for select_row)
obj:
id: ${row}
width: 100%
height: 44
pad_left: 10
pad_right: 10
border_side: [BOTTOM]
border_width: 1
border_color: ${pip_line}
bg_color: ${pip_panel}
layout:
type: flex
flex_flow: row
flex_align_cross: center
pad_column: 12
on_press:
- script.execute:
id: select_row
row: ${idx}
widgets:
- obj:
id: ${row}_mark
width: 10
height: 10
bg_color: ${pip_green}
bg_opa: COVER
hidden: true
- label:
flex_grow: 1
text: "${name}"
- label:
id: ${row}_val
text: "--"
+1 -1
View File
@@ -2,7 +2,7 @@
platform: uptime platform: uptime
name: Uptime name: Uptime
id: uptime_sensor id: uptime_sensor
unit_of_measurement: "days" unit_of_measurement: d # HA unit for duration; MQTT discovery rejects "days"
accuracy_decimals: 2 accuracy_decimals: 2
update_interval: 60s update_interval: 60s
filters: filters:
+86 -83
View File
@@ -1,14 +1,7 @@
esp32: # Vehicle iBeacon on an M5Stack ATOM Lite: BLE only, Wi-Fi + OTA by holding the button.
variant: esp32 # LED: short blue blink at boot, then dark; blue while the home beacon (mcu-gate) is seen;
toolchain: esp-idf # green while Wi-Fi is on.
framework: #
advanced:
flash_chip: gd # ESP32-PICO-D4, like every other ATOM Lite
type: esp-idf
external_components:
- source: components
# PINOUTS: M5ATOM # PINOUTS: M5ATOM
# IR G12 # IR G12
# NEO G27 # NEO G27
@@ -24,85 +17,95 @@ external_components:
# 1-WIRE G22 # 1-WIRE G22
# NC G19 # 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: esphome:
on_loop: on_boot:
then: then:
lambda: |- - light.turn_on:
static uint32_t last_state = 0; id: led
auto state = App.get_app_state(); red: 0%
if (state != last_state) { green: 0%
if (state & STATUS_LED_ERROR) { blue: 50%
auto call = id(led).turn_on(); transition_length: 0s
call.set_effect("ERROR"); - delay: 300ms
call.perform(); - light.turn_off:
} else if (state & STATUS_LED_WARNING) { id: led
auto call = id(led).turn_on(); transition_length: 0s
call.set_effect("BOOT");
call.perform(); wifi:
} else { enable_on_boot: false
auto call = id(led).turn_on();
call.set_effect("BEACON"); # flashed over USB straight to encrypted OTA, no password migration needed
call.perform(); ota:
} - platform: esphome
last_state = state; 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: light:
- platform: esp32_rmt_led_strip - platform: esp32_rmt_led_strip
name: LED
id: led id: led
rgb_order: GRB channel_colors: GRB
pin: 27 pin: 27
num_leds: 1 num_leds: 1
chipset: ws2812 chipset: ws2812
restore_mode: ALWAYS_OFF 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;
+183
View File
@@ -0,0 +1,183 @@
---
# Seeed XIAO STM32C5 as a CANopen node (mrk's canopen hub + canopen_entities), MCUboot, OTA over CAN from can2mqtt
# (upload .esphome/build/<node>/.west_build/zephyr/zephyr/zephyr.signed.bin).
# Needs: substitutions node_id; the esphomeplatformzephyr fork (esphome-zephyr).
# Pinout:
# PB12 user LED (active low) -> LED (light binary)
# PH2 BOOT0, left alone (a pull-up there sends software resets to ROM DFU)
# PB5/PB13 FDCAN2 RX/TX, PB14 CAN_STB -> on-board transceiver (board DTS)
# PB3/PB4 I2C2 SCL/SDA, LSM6DS3TR-C @0x6A -> on-board IMU (motion lsm6ds)
# First flash (TinyUF2 erased with mcu-stm32-xiao-c5-eraser.yaml), hold BOOT + press RESET for ROM DFU:
# dfu-util -a 0 -s 0x08000000 -D .esphome/build/<node>/.west_build/mcuboot/zephyr/zephyr.bin
# dfu-util -a 0 -s 0x08008000:leave -D .esphome/build/<node>/.west_build/zephyr/zephyr/zephyr.signed.bin
external_components:
- source: github://mrk-its/esphome-canopen@dc6efff43e0076a5c2820800e6ff5ce28ee4c678 # canopen_entities; newer needs consts the zephyr fork lacks
components: [canopen, canopen_entities]
stm32:
variant: STM32C5
board: xiao_stm32c5
framework:
advanced:
bootloader: mcuboot
# required by the fork for MCUboot on the XIAO; the first flash is dfu-util by hand (see above)
runner: stm32cubeprogrammer
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:
- id: i2c_imu
dts_node_override: i2c2
motion:
- platform: lsm6ds
id: imu
i2c_id: i2c_imu
address: 0x6A
# 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
id: led_out
pin:
number: PB12
inverted: true
light:
- platform: binary
name: LED
id: led
output: led_out
# no button on PH2: it is BOOT0, and with BOOT_SEL on the pin (after tinyuf2_eraser) an internal pull-up there makes
# every software reset (OTA, reboot) start the ROM DFU bootloader instead of MCUboot
canbus:
- platform: zephyr_can
id: can_bus
can_id: 0
bit_rate: 500kbps
# 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
canopen_entities:
canopen_id: can_gate
entities:
- id: led
index: 1
tpdo: 0
# 2-byte encoding over min..max, so the three fit one TPDO
- id: pitch
index: 3
tpdo: 1
size: 2
min_value: -180
max_value: 180
- id: roll
index: 4
tpdo: 1
size: 2
min_value: -180
max_value: 180
- id: imu_temp
index: 5
tpdo: 1
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
# confirms the new MCUboot image after a good boot; without it MCUboot rolls back at the next reset
safe_mode:
+1
View File
@@ -30,6 +30,7 @@ esp32:
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml
status_led: !include status_led: !include
file: common/status_led.yaml file: common/status_led.yaml
vars: vars:
+91
View File
@@ -0,0 +1,91 @@
---
# Hardware: Aixun H310D hot air station WiFi/BLE module = bare ESP32-C3 (QFN32), 4MB flash.
# Flashed via header P2 (native USB): GND, D+(GPIO19), D-(GPIO18), 5V. Stock fw backup in ~/aixun-h310d-backup/.
# UART0 GPIO20(RX)/GPIO21(TX) <-> GD32 main MCU, 115200. Logger on USB-Serial/JTAG.
# The aixun component (model H310D) pairs as a BS08 remote: status, temperature/fan/presets, panel WiFi icon.
substitutions:
device: aixun-h310d
name: Aixun H310D
name_short: H310D
area: Lab
comment: Hot air station
esphome:
name: mcu-${device}
friendly_name: ${name}
area: ${area}
comment: ${comment}
esp32:
variant: esp32c3
board: esp32-c3-devkitm-1
framework:
type: esp-idf
logger:
hardware_uart: USB_SERIAL_JTAG
packages:
common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml
external_components:
- source: github://randybb/esphome-components
components: [aixun]
uart:
id: mcu_uart
rx_pin: GPIO20
tx_pin: GPIO21
baud_rate: 115200
rx_buffer_size: 1024
aixun:
id: h310d
model: H310D
uart_id: mcu_uart
update_interval: 1s
text_sensor:
- platform: aixun
device_model:
name: MCU Model
firmware_version:
name: MCU Firmware
serial_number:
name: MCU Serial
heater_status:
name: Status
sensor:
- platform: aixun
current_temperature:
name: Temperature
current_fan_speed:
name: Fan
heating_power:
name: Heating Power
number:
- platform: aixun
target_temperature:
name: Target Temperature
fan_speed:
name: Fan Speed
button:
- platform: aixun
preset_m1:
name: Preset M1
preset_m2:
name: Preset M2
preset_m3:
name: Preset M3
# The panel's WiFi STA / AP menu toggles, repurposed as feature switches.
binary_sensor:
- platform: aixun
sta_mode:
name: STA Toggle
ap_mode:
name: AP Toggle
+192 -457
View File
@@ -1,41 +1,67 @@
--- ---
# Hardware: M5Stack AtomS3 # Hardware: M5Stack AtomS3 + ATOMIC CAN base + CardKB on the Atom's Grove port
# CANopen keypad prototype (node 3): CardKB key code + press counter in TPDO 0 (canopen from ESPHome dev + canopen_entities)
# plus a Blink Marine PKP 2600SI (2x6) emulation as a second local node 0x15: keys 1-6 / q-y, LED RPDOs drawn on the display
# Pinout: # Pinout:
# GPIO1 Grove SCL -> motor_in1 (output gpio) # GPIO1 Grove SCL -> i2c_grove (i2c scl)
# GPIO2 Grove SDA -> motor_in2 (output gpio) # GPIO2 Grove SDA -> i2c_grove (i2c sda)
# GPIO5 -> canbus/esp32_can (canbus esp32_can tx_pin) # GPIO5 -> can_bus (canbus esp32_can tx_pin)
# GPIO6 -> canbus/esp32_can (canbus esp32_can rx_pin) # GPIO6 -> can_bus (canbus esp32_can rx_pin)
# GPIO15 -> display_tft (display mipi_spi cs_pin) # GPIO15 -> display_tft (display mipi_spi cs_pin)
# GPIO16 -> gpio_tft_backlight (output ledc) # GPIO16 -> gpio_tft_backlight (output ledc)
# GPIO17 -> spi (spi clk_pin) # GPIO17 -> spi (spi clk_pin)
# GPIO21 -> spi (spi mosi_pin) # GPIO21 -> spi (spi mosi_pin)
# GPIO33 -> display_tft (display mipi_spi dc_pin) # GPIO33 -> display_tft (display mipi_spi dc_pin)
# GPIO34 -> display_tft (display mipi_spi reset_pin) # GPIO34 -> display_tft (display mipi_spi reset_pin)
# GPIO38 -> i2c_main (i2c sda)
# GPIO39 -> i2c_main (i2c scl)
# GPIO41 -> Button (binary_sensor gpio) (inverted) # GPIO41 -> Button (binary_sensor gpio) (inverted)
# I2C: # I2C:
# 0x21 pcf8574_hub (pcf8574) # 0x5F cardkb (m5stack_keyboard), CardKB
# 0x26 m5stack_relay_1 (m5stack_4relay)
# 0x3C lcd (display ssd1306_i2c)
substitutions: substitutions:
device: atoms3 device: atoms3
name: AtomS3 name: AtomS3
area: DEV area: DEV
comment: -- comment: CANopen keypad
esphome: esphome:
name: mcu-${device} name: mcu-${device}
friendly_name: ${name} friendly_name: ${name}
area: ${area} area: ${area}
comment: ${comment} comment: ${comment}
# on_boot: on_boot:
# - priority: 800 - lambda: |-
# then: id(cardkb).add_on_key_callback([](uint8_t key) {
# - lambda: |- id(key_code).publish_state(key);
# id(display_tft).enable(); float n = id(key_count).state; // NaN before the first key
# id(display_tft).transfer_byte(0x11); uint32_t count = std::isnan(n) ? 1 : ((uint32_t) n + 1) % 65535;
# id(display_tft).disable(); id(key_count).publish_state(count);
id(key_event).publish_state((count % 255) * 256 + key); // one field: count (high byte) + key (low byte)
// PKP: keys 1-6 = top row, q w e r t y = bottom row (keys 7-12); CardKB has no release -> 200 ms press
static const char *const PKP_KEYS = "123456qwerty";
const char *p = key ? strchr(PKP_KEYS, key) : nullptr;
if (p != nullptr) {
id(pkp_keys) = 1u << (p - PKP_KEYS);
id(pkp_send_keys).execute();
}
id(display_tft).update();
});
// PKP RPDOs: 0x200 LED on, 0x300 LED blink (40 bits: R1-12, G1-12, B1-12), 0x400 brightness 0x00-0x3F
static canopen::FrameListener pkp_rx{0x015, 0x0FF, [](void *, uint32_t can_id, const uint8_t *d, uint8_t len) {
if (id(pkp).get_nmt_state() != canopen::NMTState::NMT_STATE_OPERATIONAL)
return;
uint64_t bits = 0;
for (uint8_t i = 0; i < len && i < 5; i++)
bits |= (uint64_t) d[i] << (8 * i);
if (can_id == 0x215)
id(pkp_led_on) = bits;
else if (can_id == 0x315)
id(pkp_led_blink) = bits;
else if (can_id == 0x415 && len > 0)
id(pkp_brightness) = d[0] > 0x3F ? 0x3F : d[0];
else
return;
id(display_tft).update();
}, nullptr};
id(pkp).add_frame_listener(pkp_rx);
esp32: esp32:
variant: esp32s3 variant: esp32s3
@@ -46,88 +72,17 @@ esp32:
flash_chip: gd flash_chip: gd
type: esp-idf type: esp-idf
ota:
- platform: web_server
pcf8574:
- id: 'pcf8574_hub'
address: 0x21
pcf8575: true
image:
- platform: animation
file: "assets/images/blinky.gif"
id: blinky
resize: 128x128
type: RGB565
- platform: animation
file: "assets/images/vault_boy_walking.gif"
id: vaultboy
resize: 168x121
type: RGB565
logger:
logs:
component: ERROR
web_server:
port: 80
version: 3
# light:
# - platform: esp32_rmt_led_strip
# name: LED
# id: neo
# rgb_order: GRB
# pin: 2
# num_leds: 1
# # rmt_channel: 0
# chipset: ws2812
# restore_mode: ALWAYS_OFF
text:
- platform: template
name: Test Text
# id: "it_2"
icon: "mdi:text"
optimistic: true
internal: false
initial_value: "Welcome ESPHOME - #{name}"
restore_value: true
mode: text
# max_restore_data_length: 24
# logger:
# hardware_uart: USB_SERIAL_JTAG
external_components: external_components:
- source: github://pr#7234 - source: github://mrk-its/esphome-canopen@canopen_entities
components: m5stack_4relay components: [canopen_entities]
refresh: 0s refresh: 1h
# - source: github://pr#5586 - source: github://randybb/esphome-components
# components: [ http_request ] components: [m5stack_keyboard]
# - source: github://mknjc/esphome@ds248x refresh: 1h
# components: ds248x # TEMP: esphome#23831 (OTA over CANopen, CiA 302-3); drop once merged
# - source: github://bekriebel/esphome@sh1107_fix - source: github://pr#23831
# components: components: [canopen]
# - ssd1306_base refresh: 1h
# - ssd1306_i2c
# - ssd1306_spi
# - source: github://pr#5096
# refresh: 0s
# - source: github://pr#3500
# refresh: 0s
# components:
# - web_server
# - web_server_idf
# - web_server_base
# - captive_portal
# ota:
# - platform: http_request
# web_server:
# captive_portal:
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
@@ -136,106 +91,116 @@ packages:
file: common/status_led.yaml file: common/status_led.yaml
vars: vars:
light_id: status_frame light_id: status_frame
# common: !include common/common_wo_debug.yaml
# common: !include common/common_dev.yaml logger:
logs:
# canbus logs every frame at DEBUG, which slows the loop during SDO block transfers
canbus: INFO
i2c:
- id: i2c_grove
sda: 2
scl: 1
m5stack_keyboard:
- id: cardkb
i2c_id: i2c_grove
address: 0x5F
canbus: canbus:
- platform: esp32_can - platform: esp32_can
id: can_bus
rx_pin: 6 rx_pin: 6
tx_pin: 5 tx_pin: 5
can_id: 4 can_id: 3
# bit_rate: 500kbps bit_rate: 500kbps
bit_rate: 1000KBPS # IDF default is 5 frames; an SDO block (16 segments in ~8 ms) overflowed it (EMCY 0x8110, partial block acks)
use_extended_id: true rx_queue_len: 32
on_frame:
- can_id: 0x123 canopen:
use_extended_id: true - id: can_open
canbus_id: can_bus
node_id: 3
# Blink Marine PKP 2600SI emulation (docs: home-gitops canopen-nodes.adoc): like the real one, not active until NMT Start
- id: pkp
canbus_id: can_bus
node_id: 0x15
nmt_startup: pre_operational
device_name: PKP2600SI
globals:
- id: pkp_keys
type: uint16_t
initial_value: '0'
- id: pkp_led_on
type: uint64_t
initial_value: '0'
- id: pkp_led_blink
type: uint64_t
initial_value: '0'
- id: pkp_brightness
type: uint8_t
initial_value: '0x3F'
script:
# keys state TPDO 0x195: bytes 0-1 keys 1-12, byte 4 tick (+1 per 100 ms); pressed now, released 200 ms later
- id: pkp_send_keys
mode: restart
then: then:
- lambda: |- - lambda: |-
std::string b(x.begin(), x.end()); if (id(pkp).get_nmt_state() != canopen::NMTState::NMT_STATE_OPERATIONAL)
ESP_LOGD("can extended id 0x123", "%s", &b[0] ); return;
- can_id: 0x123 uint8_t d[5] = {(uint8_t) id(pkp_keys), (uint8_t) (id(pkp_keys) >> 8), 0, 0, (uint8_t) (millis() / 100)};
then: id(pkp).send_frame(0x195, d, sizeof(d));
- delay: 200ms
- lambda: |- - lambda: |-
std::string b(x.begin(), x.end()); id(pkp_keys) = 0;
ESP_LOGD("can standard id 0x123", "%s", &b[0] ); if (id(pkp).get_nmt_state() != canopen::NMTState::NMT_STATE_OPERATIONAL)
- can_id: 0x3f1 return;
can_id_mask: 0x7ff uint8_t d[5] = {0, 0, 0, 0, (uint8_t) (millis() / 100)};
use_extended_id: false id(pkp).send_frame(0x195, d, sizeof(d));
then:
- lambda: |-
std::string b(x.begin(), x.end());
ESP_LOGD("can id 0x03f1", "%s", &b[0] );
- can_id: 0x108
use_extended_id: false
then:
- lambda: |-
std::string b(x.begin(), x.end());
ESP_LOGD("can id 0x108", "%s", &b[0] );
- can_id: 0x109
use_extended_id: false
then:
- lambda: |-
std::string b(x.begin(), x.end());
ESP_LOGD("can id 0x109", "%s", &b[0] );
i2c: ota:
# - id: i2c_groove - platform: canopen
# sda: 2 canopen_id: can_open
# scl: 1
# scan: true
- id: i2c_main
sda: 38
scl: 39
scan: true
frequency: 800kHz
# mcp23017: # CardKB sends only the press (Shift/Sym/Fn resolved in the CardKB): a consumer reacts to a change of key_count
# - id: mcp23017_hub # and reads the key from key_code (both in the same frame), or watches key_event alone (count % 255 << 8 | key)
# i2c_id: i2c_main canopen_entities:
# address: 0x20 canopen_id: can_open
entities:
- {id: key_code, index: 1, tpdo: 0, size: 1}
- {id: key_count, index: 2, tpdo: 0, size: 2}
- {id: side_button, index: 3, tpdo: 0}
- {id: key_event, index: 4, tpdo: 0, size: 2}
# ds248x: sensor:
# i2c_id: i2c_main - platform: template
# address: 0x18 # should be the default id: key_code
# # sleep_pin: 32 # remove if not needed, if set the ds248x sleeps when no transaction is in progress name: Key Code
# active_pullup: true # adds a active pullup which should improve signal integrity accuracy_decimals: 0
# strong_pullup: false # enables a strong pullup used to provide the needed current for temperature reading without vcc connected update_interval: never
# bus_sleep: true # power down the bus when no transaction is in progres - platform: template
id: key_count
name: Key Count
accuracy_decimals: 0
update_interval: never
- platform: template
id: key_event
name: Key Event
accuracy_decimals: 0
update_interval: never
# one_wire: binary_sensor:
# - platform: gpio - platform: gpio
# pin: 1 id: side_button
# id: hub_1 name: Button
# - platform: gpio pin:
# pin: 2 number: 41
# id: hub_2 inverted: true
m5stack_4relay:
id: m5stack_relay_1
i2c_id: i2c_main
# mqtt:
# id: mqtt_client
# broker: !secret mqtt_ip
# # broker: 10.10.10.10
# username: !secret mqtt_username
# password: !secret mqtt_password
# discovery: true
# mdns:
# disabled: false
# wifi:
# use_address: 10.17.240.52
output: output:
- platform: gpio
id: motor_in1
pin: 1
- platform: gpio
id: motor_in2
pin: 2
- platform: ledc - platform: ledc
pin: 16 pin: 16
id: gpio_tft_backlight id: gpio_tft_backlight
@@ -266,155 +231,14 @@ light:
blue: status_frame_b blue: status_frame_b
restore_mode: ALWAYS_OFF restore_mode: ALWAYS_OFF
switch:
- platform: template
name: "Motor Forward"
optimistic: true
turn_on_action:
- output.turn_on: motor_in1
- output.turn_off: motor_in2
turn_off_action:
- output.turn_off: motor_in1
- output.turn_off: motor_in2
- platform: template
name: "Motor Back"
optimistic: true
turn_on_action:
- output.turn_off: motor_in1
- output.turn_on: motor_in2
turn_off_action:
- output.turn_off: motor_in1
- output.turn_off: motor_in2
# switch:
- platform: m5stack_4relay
name: Relay 1
id: relay_1
channel: 1
# interlock: &interlock_group_1 [relay_1, relay_2]
# interlock_wait_time: 1s
m5stack_4relay_id: m5stack_relay_1
- platform: m5stack_4relay
name: Relay 2
id: relay_2
channel: 2
# interlock: *interlock_group_1
# interlock_wait_time: 1s
m5stack_4relay_id: m5stack_relay_1
- platform: m5stack_4relay
name: Relay 3
id: relay_3
channel: 3
# interlock: &interlock_group_2 [relay_3, relay_4]
m5stack_4relay_id: m5stack_relay_1
- platform: m5stack_4relay
name: Relay 4
id: relay_4
channel: 4
# interlock: *interlock_group_2
m5stack_4relay_id: m5stack_relay_1
- platform: gpio
name: "PCF8574 Pin #8"
pin:
pcf8574: pcf8574_hub
number: 9
# One of INPUT or OUTPUT
mode:
output: true
inverted: false
spi: spi:
clk_pin: 17 clk_pin: 17
mosi_pin: 21 mosi_pin: 21
binary_sensor:
- platform: gpio
name: Button
pin:
number: 41
inverted: true
- platform: status
id: system_status
# - platform: gpio
# id: test_sensor_1
# pin:
# mcp23xxx: mcp23017_hub
# number: 4
# mode:
# input: true
# pullup: true
# inverted: false
# filters:
# - delayed_on_off: 50ms #Debounce
# - platform: gpio
# id: test_sensor_2
# pin:
# mcp23xxx: mcp23017_hub
# number: 5
# mode:
# input: true
# pullup: true
# inverted: false
# filters:
# - delayed_on_off: 50ms #Debounce
# - platform: gpio
# id: test_sensor_3
# pin:
# mcp23xxx: mcp23017_hub
# number: 6
# mode:
# input: true
# pullup: true
# inverted: false
# filters:
# - delayed_on_off: 50ms #Debounce
# - platform: gpio
# id: test_sensor_4
# pin:
# mcp23xxx: mcp23017_hub
# number: 7
# mode:
# input: true
# pullup: true
# inverted: false
# filters:
# - delayed_on_off: 50ms #Debounce
color:
- id: my_red
red: 100%
green: 0%
blue: 0%
- id: my_yellow
red: 100%
green: 100%
blue: 0%
- id: my_green
red: 0%
green: 100%
blue: 0%
- id: my_blue
red: 0%
green: 0%
blue: 100%
- id: my_gray
red: 50%
green: 50%
blue: 50%
font: font:
- file: "gfonts://Roboto" - file: "gfonts://Roboto"
id: font_default id: font_key
size: 20 size: 48
- file: "gfonts://Roboto"
id: roboto_32
size: 32
- file: "gfonts://Roboto"
id: roboto_24
size: 24
- file: "gfonts://Roboto"
id: roboto_12
size: 12
display: display:
- platform: mipi_spi - platform: mipi_spi
@@ -426,12 +250,10 @@ display:
width: 128 width: 128
offset_height: 2 offset_height: 2
offset_width: 1 offset_width: 1
# backlight_pin: 16
cs_pin: 15 cs_pin: 15
dc_pin: 33 dc_pin: 33
reset_pin: 34 reset_pin: 34
# eightbitcolor: true update_interval: 250ms # PKP LED blink
update_interval: 1s
lambda: |- lambda: |-
// status screen (common/status_led.yaml): the whole display in the status colour // status screen (common/status_led.yaml): the whole display in the status colour
auto &sv = id(status_frame)->current_values; auto &sv = id(status_frame)->current_values;
@@ -439,129 +261,42 @@ display:
it.fill(Color(sv.get_red() * 255, sv.get_green() * 255, sv.get_blue() * 255)); it.fill(Color(sv.get_red() * 255, sv.get_green() * 255, sv.get_blue() * 255));
return; return;
} }
//Ingress shown animation Frame. // PKP LEDs, 2x6 like the keypad: on colour; with blink, alternating with the blink colour (off if not on)
id(blinky).next_frame(); bool phase = (millis() / 500) & 1;
// Draw the animation my_animation at position [x=0,y=0] uint8_t lvl = 255 * id(pkp_brightness) / 0x3F;
it.image(0, 0, id(blinky), COLOR_ON, COLOR_OFF); for (int i = 0; i < 12; i++) {
auto rgb = [i](uint64_t b) { return (b >> i & 1) | (b >> (i + 12) & 1) << 1 | (b >> (i + 24) & 1) << 2; };
int on = rgb(id(pkp_led_on)), bl = rgb(id(pkp_led_blink));
// // it.print(0, 0, id(font_default), "Hello World!"); int c = phase && bl ? bl : (bl && !on ? 0 : on);
// // it.strftime(0, 0, id(font_default), TextAlign::TOP_LEFT, "%H:%M", id(ha_time).now()); int x = (i % 6) * 21 + 1, y = (i / 6) * 32;
// it.rectangle(0, 0, it.get_width(), it.get_height(), id(my_blue)); it.filled_rectangle(x, y + 1, 19, 30, Color(c & 1 ? lvl : 0, c & 2 ? lvl : 0, c & 4 ? lvl : 0));
// it.rectangle(0, 20, it.get_width(), it.get_height(), id(my_blue)); // header bar it.rectangle(x, y + 1, 19, 30, Color(64, 64, 64));
}
// it.strftime((128 / 2), (128 / 3) * 1 + 5, id(roboto_24), id(my_gray), TextAlign::CENTER, "%Y-%m-%d", id(ha_time).now()); // last key
// it.strftime((128 / 2), (128 / 3) * 2 + 5, id(roboto_32), id(my_gray), TextAlign::CENTER, "%H:%M:%S", id(ha_time).now()); if (std::isnan(id(key_code).state))
// it.print(5, 5, id(roboto_12), id(my_yellow), TextAlign::TOP_LEFT, "ESPHome"); return;
uint8_t k = id(key_code).state;
// // Comment out the above lines to see the image without text overlaid // CardKB: Shift/Sym come as plain characters, Fn and the specials as codes; unknown ones as hex
// // it.image(0, 0, id(my_image)); const char *s = nullptr;
char c[5];
// if (id(system_status).state) { switch (k) {
// it.print(115, 5, id(roboto_12), id(my_green), TextAlign::TOP_RIGHT, "Online"); case 0x08: s = "BS"; break;
// } case 0x09: s = "Tab"; break;
// else { case 0x0D: s = "Ent"; break;
// it.print(115, 5, id(roboto_12), id(my_red), TextAlign::TOP_RIGHT, "Offline"); case 0x1B: s = "Esc"; break;
// } case 0x20: s = "Spc"; break;
case 0x7F: s = "Del"; break;
- platform: ssd1306_i2c case 0xB4: s = "Lt"; break;
model: "SH1107 128x64" case 0xB5: s = "Up"; break;
# model: "SSD1306 128x64" case 0xB6: s = "Dn"; break;
id: "lcd" case 0xB7: s = "Rt"; break;
address: 0x3C default:
i2c_id: i2c_main if (k > 0x20 && k < 0x7F) {
rotation: 90 c[0] = (char) k;
flip_x: false c[1] = 0;
flip_y: false } else {
offset_y: 0 snprintf(c, sizeof(c), "%02X", k);
offset_x: 0 }
# lambda: |- s = c;
# it.line(0, 0, 128, 64); }
# it.rectangle(5, 5, 10, 10); it.print(64, 96, id(font_key), TextAlign::CENTER, s);
# it.circle(118, 54, 5);
# it.rectangle(0, 0, 128, 64);
sensor:
# - platform: sht3xd
# i2c_id: i2c_main
# address: 0x44
# temperature:
# name: TEST Temperature
# humidity:
# name: TEST Humidity
# update_interval: 10s
# - platform: mpu6886
# address: 0x68
# i2c_id: i2c_main
# # accel_x:
# # name: "${name} MPU6886 Accel X"
# # accel_y:
# # name: "${name} MPU6886 Accel Y"
# # accel_z:
# # name: "${name} MPU6886 Accel z"
# # gyro_x:
# # name: "${name} MPU6886 Gyro X"
# # gyro_y:
# # name: "${name} MPU6886 Gyro Y"
# # gyro_z:
# # name: "${name} MPU6886 Gyro z"
# temperature:
# name: Temperature
# id: blabla
- platform: homeassistant
id: test_humidity_ha
entity_id: sensor.humidity_158d0001c2a1d1
# - platform: ds248x
# address: 0x8b0516b39804ff28
# name: "${name} Dallas Temp 1"
# resolution: 12
# - platform: ds248x
# address: 0xa50516b3d32aff28
# name: "${name} Dallas Temp 2"
# resolution: 12
# - platform: ds248x
# address: 0x8f0516b39d87ff28
# name: "${name} Dallas Temp 3"
# resolution: 12
# - platform: ds248x
# address: 0x810516b3c69fff28
# name: "${name} Dallas Temp 4"
# resolution: 12
# - platform: dallas_temp
# address: 0xdb041750eae2ff28
# name: Dallas Temp 1
# one_wire_id: hub_1
# update_interval: 10s
# - platform: dallas_temp
# address: 0xb2041750cf1aff28
# name: Dallas Temp 2
# one_wire_id: hub_1
# update_interval: 30s
# - platform: dallas_temp
# address: 0xcd01191eb8b07128
# name: Dallas Temp 3
# one_wire_id: hub_1
# update_interval: 45s
# - platform: dallas_temp
# address: 0x5a01191ef3375b28
# name: Dallas Temp 4
# one_wire_id: hub_1
# time:
# - platform: sntp
# id: sntp_time
# timezone: Europe/Bratislava
# servers:
# - 0.pool.ntp.org
# - 1.pool.ntp.org
# - 2.pool.ntp.org
# esp32_ble_tracker:
# scan_parameters:
# active: true
# bluetooth_proxy:
# active: true
# esp32_improv:
# authorizer: none
+36 -53
View File
@@ -24,14 +24,18 @@ esp32:
type: esp-idf type: esp-idf
external_components: external_components:
- source: github://mrk-its/esphome-canopen@dev - source: github://mrk-its/esphome-canopen@canopen_entities
refresh: 1h components: [canopen_entities]
- source: github://mrk-its/esphome-canbus-udp-multicast@dev
refresh: 1h refresh: 1h
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
logger:
logs:
# canbus logs every frame at DEBUG, which slows the loop during SDO block transfers
canbus: INFO
canbus: canbus:
- platform: esp32_can - platform: esp32_can
id: can_bus id: can_bus
@@ -39,57 +43,29 @@ canbus:
tx_pin: 23 tx_pin: 23
can_id: 1 can_id: 1
bit_rate: 500kbps 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: canopen:
id: can_open id: can_open
canbus_id: can_bus canbus_id: can_bus
node_id: 1 node_id: 1
entities:
- index: 1
id: light1_state
rpdo:
- node_id: 2
tpdo: 0
offset: 0
cmd: 0
- index: 2 canopen_entities:
id: light1_brightness remote_nodes:
size: 1 node2: mcu-can-node-2.yaml
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
binary_sensor: binary_sensor:
- platform: template - platform: canopen_entities
id: light1_state id: light1_state
name: Light 1 State name: Light 1 State
- platform: template node: node2
entity: light1
- platform: canopen_entities
id: light2_state id: light2_state
name: Light 2 State name: Light 2 State
node: node2
entity: light2
- platform: template - platform: template
id: light1_state_cmd id: light1_state_cmd
@@ -105,26 +81,33 @@ binary_sensor:
pullup: true pullup: true
on_press: on_press:
then: then:
- lambda: |- # both lights on node 2 off if either is on, otherwise both on
bool state = id(light1_state).state || id(light2_state).state; - if:
condition:
// send command to entity #1 (light) on node #2 lambda: return id(light1_state).state || id(light2_state).state;
id(can_open).send_entity_cmd(2, 1, !state); then:
- canopen_entities.light.turn_off: {node: node2, entity: light1}
// send command to entity #2 (light2) on node #2 - canopen_entities.light.turn_off: {node: node2, entity: light2}
id(can_open).send_entity_cmd(2, 2, !state); else:
- canopen_entities.light.turn_on: {node: node2, entity: light1}
- canopen_entities.light.turn_on: {node: node2, entity: light2}
sensor: sensor:
- platform: template - platform: canopen_entities
id: light1_brightness id: light1_brightness
name: Light 1 Brightness name: Light 1 Brightness
- platform: template node: node2
entity: light1
state: brightness
- platform: canopen_entities
id: light2_brightness id: light2_brightness
name: Light 2 Brightness name: Light 2 Brightness
node: node2
entity: light2
state: brightness
switch: switch:
- platform: gpio - platform: gpio
name: LED name: LED
id: blue_led id: blue_led
internal: true
pin: 2 pin: 2
+18 -3
View File
@@ -1,6 +1,7 @@
--- ---
# Hardware: ESP32 DevKit # Hardware: ESP32 DevKit
# Pinout: # Pinout:
# GPIO2 -> LED (switch gpio, on-board blue LED)
# GPIO17 -> i2c (i2c sda) # GPIO17 -> i2c (i2c sda)
# GPIO18 -> i2c (i2c scl) # GPIO18 -> i2c (i2c scl)
# GPIO19 -> as3935_i2c (as3935_i2c irq_pin) # GPIO19 -> as3935_i2c (as3935_i2c irq_pin)
@@ -27,14 +28,18 @@ esp32:
type: esp-idf type: esp-idf
external_components: external_components:
- source: github://mrk-its/esphome-canopen@dev - source: github://mrk-its/esphome-canopen@canopen_entities
refresh: 1h components: [canopen_entities]
- source: github://mrk-its/esphome-canbus-udp-multicast@dev
refresh: 1h refresh: 1h
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
logger:
logs:
# canbus logs every frame at DEBUG, which slows the loop during SDO block transfers
canbus: INFO
canbus: canbus:
- platform: esp32_can - platform: esp32_can
id: can_bus id: can_bus
@@ -42,11 +47,15 @@ canbus:
tx_pin: 23 tx_pin: 23
can_id: 2 can_id: 2
bit_rate: 500kbps 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: canopen:
id: can_open id: can_open
canbus_id: can_bus canbus_id: can_bus
node_id: 2 node_id: 2
canopen_entities:
entities: entities:
- index: 1 - index: 1
id: light1 id: light1
@@ -145,3 +154,9 @@ sensor:
# canopen: DEBUG # canopen: DEBUG
# can_driver: DEBUG # can_driver: DEBUG
# timer_driver: DEBUG # timer_driver: DEBUG
switch:
- platform: gpio
name: LED
id: blue_led
pin: 2
+395
View File
@@ -0,0 +1,395 @@
---
# Hardware: M5Stamp Pico + CAN transceiver on the OBD-II port
# Pinout:
# GPIO33 -> car_can (canbus esp32_can tx_pin)
# GPIO32 -> car_can (canbus esp32_can rx_pin)
# OBD-II: pin 6 CAN-H, pin 14 CAN-L, pin 5 signal ground; 5 V supply into the Stamp 5V pin
# (3V3 from the USB-serial programmer browns out when WiFi starts)
substitutions:
device: car-can
name: Car CAN
area: DEV
comment: Auris CAN sniffer and OBD requests
# LISTENONLY to sniff first, NORMAL for the OBD requests
can_mode: LISTENONLY
esphome:
name: mcu-${device}
friendly_name: ${name}
area: ${area}
comment: ${comment}
on_boot:
# after setup, else can_tools starts its poller again
priority: -100
then:
- component.suspend: car
esp32:
variant: esp32
framework:
type: esp-idf
advanced:
flash_chip: gd
sram1_as_iram: true
packages:
common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml
external_components:
- source: github://randybb/esphome-components
components: [can_tools]
logger:
logs:
# a DEBUG line per frame drops most of the traffic
canbus: INFO
globals:
# CAN ID -> frames seen and the last data
- id: frames_per_id
type: std::map<uint32_t, std::pair<uint32_t, canbus::CanPayload>>
- id: ecm_last_seen
type: uint32_t
initial_value: '0'
canbus:
- platform: esp32_can
id: car_can
tx_pin: GPIO33
rx_pin: GPIO32
can_id: 0x7DF
use_extended_id: false
bit_rate: 500KBPS
mode: ${can_mode}
# ~1000 frames/s on the Auris bus
rx_queue_len: 64
max_frames_per_loop: 200
on_frame:
# every frame: count per ID, dumped by the interval below
- can_id: 0
can_id_mask: 0
then:
- lambda: |-
auto &seen = id(frames_per_id);
auto &e = seen[can_id];
e.first++;
// body frames: log every change to match it with lock/doors
// all but the frames whose data changes all the time
static const uint16_t noisy[] = {0x020, 0x024, 0x025, 0x0AA, 0x0B4, 0x1C4, 0x224, 0x260,
0x262, 0x263, 0x266, 0x2C1, 0x2C3, 0x3A0, 0x3D3, 0x4AC,
0x440, 0x442, 0x443, 0x44D, 0x640};
bool watch = std::find(std::begin(noisy), std::end(noisy), can_id) == std::end(noisy);
bool changed = !std::equal(x.begin(), x.end(), e.second.begin(), e.second.end());
// 0x224 (brake): byte 5 counts, compare the rest
if (can_id == 0x224 && x.size() > 5 && e.second.size() == x.size()) {
watch = true;
changed = !std::equal(x.begin(), x.begin() + 5, e.second.begin()) ||
!std::equal(x.begin() + 6, x.end(), e.second.begin() + 6);
}
if (watch && e.first > 1 && changed) {
char hex[format_hex_pretty_size(8)];
ESP_LOGI("chg", "0x%03" PRIX32 " %s", can_id, format_hex_pretty_to(hex, x));
}
e.second = x;
# ECM frame, gone right after the engine stops (sniffed 2026-11-03)
- can_id: 0x2C1
then:
- lambda: id(ecm_last_seen) = millis();
# signals from opendbc toyota_2017.dbc, checked against this car where noted
# DOOR_LOCKS: byte 2 = unlocked doors bitmask (0x1F all, 0x10 driver, 0x08 passenger, 0x00 locked)
- can_id: 0x638
then:
- lambda: if (x.size() > 2) id(locked).publish_state(x[2] == 0);
# BODY_CONTROL_STATE: byte 5 doors open (0x20 FL checked), byte 7 0x10 parking brake, 0x40 belt unlatched
- can_id: 0x620
then:
- lambda: |-
if (x.size() < 8) return;
id(driver_door).publish_state(x[5] & 0x20);
id(passenger_door).publish_state(x[5] & 0x10);
id(rear_left_door).publish_state(x[5] & 0x04);
id(rear_right_door).publish_state(x[5] & 0x08);
id(parking_brake).publish_state(x[7] & 0x10);
id(driver_belt).publish_state(!(x[7] & 0x40));
# ENGINE_RPM: bytes 0-1 signed x 0.78125 (741 at idle), byte 3 0x08 engine running
- can_id: 0x1C4
then:
- lambda: |-
if (x.size() < 4) return;
id(engine_rpm).publish_state(int16_t(x[0] << 8 | x[1]) * 0.78125f);
id(engine_running).publish_state(x[3] & 0x08);
# SPEED: bytes 5-6 x 0.01 km/h
- can_id: 0x0B4
then:
- lambda: if (x.size() > 6) id(speed).publish_state((x[5] << 8 | x[6]) * 0.01f);
# LIGHT_STALK: byte 2 0x08 tail, byte 3 0x08 fog, 0x10 parking, 0x20 low, 0x40 high, 0x80 DRL
- can_id: 0x622
then:
- lambda: |-
if (x.size() < 4) return;
id(tail_light).publish_state(x[2] & 0x08);
id(front_fog).publish_state(x[3] & 0x08);
id(low_beam).publish_state(x[3] & 0x20);
id(high_beam).publish_state(x[3] & 0x40);
# BLINKERS_STATE: byte 3 bits 5-4 = 1 left, 2 right, 3 none; 0x08 hazard; bytes 6-7 trip A x 0.1 km
- can_id: 0x614
then:
- lambda: |-
if (x.size() < 8) return;
id(trip_a).publish_state((x[6] << 8 | x[7]) / 10.0f);
uint8_t t = (x[3] >> 4) & 3;
id(blinker_left).publish_state(t == 1);
id(blinker_right).publish_state(t == 2);
id(hazard).publish_state(x[3] & 0x08);
# BRAKE_MODULE (older opendbc): byte 0 0x20 = brake pressed (checked), bytes 4-5 pressure?
- can_id: 0x224
then:
- lambda: if (x.size() > 0) id(brake).publish_state(x[0] & 0x20);
# climate, sniffed: 0x380 byte 2 0x20 = A/C on
- can_id: 0x380
then:
- lambda: if (x.size() > 2) id(ac_on).publish_state(x[2] & 0x20);
# 0x381 byte 1 0x80 = fan auto, byte 2 = fan level
- can_id: 0x381
then:
- lambda: |-
if (x.size() < 3) return;
id(fan_auto).publish_state(x[1] & 0x80);
id(fan_level).publish_state(x[2]);
# 0x382 byte 0 = set temperature in 0.5 °C steps, 0x11 = 24 °C
- can_id: 0x382
then:
- lambda: if (x.size() > 0) id(climate_temp).publish_state(15.5f + x[0] / 2.0f);
# trip computer, sniffed: 0x615 bytes 6-7 trip B x 0.1 km
- can_id: 0x615
then:
- lambda: if (x.size() > 7) id(trip_b).publish_state((x[6] << 8 | x[7]) / 10.0f);
# 0x619 byte 4 outside temp x 0.5 °C (guess), bytes 5-6 range km
- can_id: 0x619
then:
- lambda: |-
if (x.size() < 7) return;
id(outside_temp).publish_state(x[4] / 2.0f);
id(fuel_range).publish_state(x[5] << 8 | x[6]);
# 0x61A byte 6 average consumption x 0.1 l/100 km
- can_id: 0x61A
then:
- lambda: if (x.size() > 6) id(avg_consumption).publish_state(x[6] / 10.0f);
# 0x61C byte 6 hours (guess), byte 7 minutes of drive time since start; FF:FE with the engine off
- can_id: 0x61C
then:
- lambda: if (x.size() > 7 && x[6] != 0xFF) id(drive_time).publish_state(x[6] * 60 + x[7]);
# 0x396 byte 0 0x02 = reverse gear (sniffed 3x), bytes 2-3 maybe parking sensors
- can_id: 0x396
then:
- lambda: if (x.size() > 0) id(reverse).publish_state(x[0] & 0x02);
# UI_SETTING: bytes 4-7 odometer
- can_id: 0x611
then:
- lambda: |-
if (x.size() < 8) return;
id(odometer).publish_state(uint32_t(x[4]) << 24 | x[5] << 16 | x[6] << 8 | x[7]);
interval:
- interval: 5s
then:
- lambda: |-
auto &seen = id(frames_per_id);
auto st = id(car_can).get_status();
ESP_LOGI("sniff", "%u IDs in 5 s, rx_err %u, bus_err %" PRIu32 ", missed %" PRIu32, (unsigned) seen.size(),
st.rx_error_counter, st.bus_error_count, st.rx_missed_count);
for (auto &[can_id, e] : seen) {
char hex[format_hex_pretty_size(8)];
ESP_LOGI("sniff", " 0x%03" PRIX32 " %4" PRIu32 "x %s", can_id, e.first,
format_hex_pretty_to(hex, e.second));
}
seen.clear();
can_tools:
id: car
canbus_id: car_can
requests:
- id: engine_coolant
can_id: 0x7DF
data: [0x01, 0x05]
interval: 30s
sensor:
- platform: template
id: engine_rpm
name: Engine RPM
unit_of_measurement: rpm
accuracy_decimals: 0
state_class: measurement
filters:
- throttle: 1s
- platform: template
id: speed
name: Speed
unit_of_measurement: km/h
accuracy_decimals: 0
state_class: measurement
filters:
- throttle: 1s
- platform: template
id: fan_level
name: Fan level
accuracy_decimals: 0
filters:
- delta: 1
- platform: template
id: climate_temp
name: Climate set temperature
unit_of_measurement: °C
device_class: temperature
accuracy_decimals: 1
filters:
- delta: 0.4
- platform: template
id: trip_a
name: Trip A
unit_of_measurement: km
device_class: distance
accuracy_decimals: 1
filters:
- delta: 0.1
- platform: template
id: trip_b
name: Trip B
unit_of_measurement: km
device_class: distance
accuracy_decimals: 1
filters:
- delta: 0.1
- platform: template
id: outside_temp
name: Outside temperature
unit_of_measurement: °C
device_class: temperature
state_class: measurement
accuracy_decimals: 1
filters:
- delta: 0.4
- platform: template
id: fuel_range
name: Range
unit_of_measurement: km
device_class: distance
accuracy_decimals: 0
filters:
- delta: 1
- platform: template
id: avg_consumption
name: Average consumption
unit_of_measurement: l/100km
state_class: measurement
accuracy_decimals: 1
filters:
- delta: 0.05
- platform: template
id: drive_time
name: Drive time
unit_of_measurement: min
device_class: duration
accuracy_decimals: 0
filters:
- delta: 1
- platform: template
id: odometer
name: Odometer
unit_of_measurement: km
accuracy_decimals: 0
device_class: distance
state_class: total_increasing
filters:
- delta: 1
- platform: can_tools
request_id: engine_coolant
name: Coolant
unit_of_measurement: °C
device_class: temperature
lambda: return data[2] - 40.0f;
binary_sensor:
- platform: template
id: locked
name: Locked
device_class: lock
# HA lock class: on = unlocked
filters:
- invert:
- platform: template
id: driver_door
name: Driver door
device_class: door
- platform: template
id: passenger_door
name: Passenger door
device_class: door
- platform: template
id: rear_left_door
name: Rear left door
device_class: door
- platform: template
id: rear_right_door
name: Rear right door
device_class: door
- platform: template
id: parking_brake
name: Parking brake
- platform: template
id: driver_belt
name: Driver seatbelt
- platform: template
id: tail_light
name: Tail lights
- platform: template
id: front_fog
name: Front fog lights
- platform: template
id: low_beam
name: Low beam
- platform: template
id: high_beam
name: High beam
- platform: template
id: blinker_left
name: Blinker left
- platform: template
id: blinker_right
name: Blinker right
- platform: template
id: hazard
name: Hazard lights
- platform: template
id: brake
name: Brake pressed
- platform: template
id: ac_on
name: AC
- platform: template
id: fan_auto
name: Fan auto
- platform: template
id: reverse
name: Reverse
- platform: template
id: engine_running
name: Engine running
device_class: running
- platform: template
id: ignition
name: Ignition
lambda: return id(ecm_last_seen) != 0 && millis() - id(ecm_last_seen) < 2000;
switch:
# OBD requests on demand while testing (needs can_mode: NORMAL); later driven by ignition
- platform: template
name: OBD requests
optimistic: true
restore_mode: ALWAYS_OFF
turn_on_action:
- component.resume: car
turn_off_action:
- component.suspend: car
+4 -16
View File
@@ -22,23 +22,15 @@ esphome:
esp32: esp32:
variant: esp32 variant: esp32
toolchain: esp-idf
framework: framework:
advanced:
flash_chip: gd # ESP32-PICO-D4, like the other M5Stamp Pico (not read from the device)
type: esp-idf type: esp-idf
advanced:
flash_chip: gd
sram1_as_iram: true
external_components:
# - source: github://pr#3017
# components: [hdmi_cec]
# refresh: 1h
# - source: github://Palakis/esphome-hdmi-cec
# refresh: 1h
- source: github://pr#9189
components: [hdmi_cec]
refresh: 0min
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml
debug: debug:
@@ -133,10 +125,6 @@ hdmi_cec:
address: 0x05 # Audio system address: 0x05 # Audio system
# Promiscuous mode can be enabled to allow receiving messages not intended for us # Promiscuous mode can be enabled to allow receiving messages not intended for us
promiscuous_mode: false promiscuous_mode: false
# Typically the physical address is discovered based on the point-to-point
# topology of the HDMI connections using the DDC line. We don't have access
# to that so we just hardcode a physical address.
physical_address: 0x4000
pin: 26 pin: 26
on_message: on_message:
- opcode: 0x36 # opcode for "Standby" - opcode: 0x36 # opcode for "Standby"
+3 -57
View File
@@ -9,8 +9,8 @@
# GPIO6 GPIO # GPIO6 GPIO
# GPIO7 GPIO # GPIO7 GPIO
# GPIO8 GPIO # GPIO8 GPIO
# GPIO9 GPIO (BUZZER?) -> rtttl_out (output ledc) # GPIO9 GPIO
# GPIO10 GPIO # GPIO10 GPIO (BUZZER?) -> rtttl_out (output ledc)
# GPIO20 UART RX # GPIO20 UART RX
# GPIO21 UART TX # GPIO21 UART TX
substitutions: substitutions:
@@ -51,60 +51,6 @@ api:
- rtttl.play: - rtttl.play:
rtttl: !lambda 'return song;' rtttl: !lambda 'return song;'
# light:
# - platform: neopixelbus
# type: GRB
# pin: 2
# variant: WS2812
# method: ESP8266_UART1
# num_leds: 1
# name: "${name} Light"
# id: neo
# effects:
# # Use default parameters:
# - random:
# # Customize parameters
# - random:
# name: "My Slow Random Effect"
# transition_length: 30s
# update_interval: 30s
# - random:
# name: "My Fast Random Effect"
# transition_length: 4s
# update_interval: 5s
# - strobe:
# - strobe:
# name: Strobe Effect With Custom Values
# colors:
# - state: True
# brightness: 100%
# red: 100%
# green: 90%
# blue: 0%
# duration: 500ms
# - state: False
# duration: 250ms
# - state: True
# brightness: 100%
# red: 0%
# green: 100%
# blue: 0%
# duration: 500ms
# - flicker:
# - flicker:
# name: Flicker Effect With Custom Values
# alpha: 95%
# intensity: 1.5%
# - addressable_rainbow:
# - addressable_rainbow:
# name: Rainbow Effect With Custom Values
# speed: 10
# width: 50
# - addressable_scan:
# - addressable_scan:
# name: Scan Effect With Custom Values
# move_interval: 100ms
globals: globals:
- id: alarm_id - id: alarm_id
type: bool type: bool
@@ -141,7 +87,7 @@ display:
output: output:
- platform: ledc - platform: ledc
pin: 9 pin: 10
id: rtttl_out id: rtttl_out
rtttl: rtttl:
+31 -19
View File
@@ -27,6 +27,7 @@ substitutions:
comment: Klipper CNC pendant comment: Klipper CNC pendant
moonraker: http://klipper.local:7125 moonraker: http://klipper.local:7125
max_feed: "3000" # mm/min, handwheel jog feed cap max_feed: "3000" # mm/min, handwheel jog feed cap
autolock: "60" # s without jogging or selecting until the handwheel locks
esphome: esphome:
name: mcu-${device} name: mcu-${device}
@@ -69,13 +70,16 @@ http_request:
globals: globals:
- id: axis - id: axis
type: int type: int
initial_value: "0" # 0 X, 1 Y, 2 Z initial_value: "-1" # -1 locked, 0 X, 1 Y, 2 Z
- id: step - id: step
type: int type: int
initial_value: "1" # index into steps[] in the jog interval initial_value: "1" # index into steps[] in the jog interval
- id: wheel_sent - id: wheel_sent
type: float type: float
initial_value: "0" initial_value: "0"
- id: last_active
type: uint32_t
initial_value: "0" # millis() of the last jog or selection, drives the autolock
interval: interval:
# handwheel: send the counts since the last jog as one relative move # handwheel: send the counts since the last jog as one relative move
@@ -83,9 +87,12 @@ interval:
then: then:
- lambda: |- - lambda: |-
static const float steps[] = {0.01f, 0.1f, 1.0f}; static const float steps[] = {0.01f, 0.1f, 1.0f};
if (id(axis) >= 0 && millis() - id(last_active) > ${autolock} * 1000) id(axis) = -1;
float delta = id(handwheel).state - id(wheel_sent); float delta = id(handwheel).state - id(wheel_sent);
if (delta == 0 || std::isnan(delta)) return; if (delta == 0 || std::isnan(delta)) return;
id(wheel_sent) = id(handwheel).state; id(wheel_sent) = id(handwheel).state;
if (id(axis) < 0) return; // locked: drop the counts
id(last_active) = millis();
float dist = delta * steps[id(step)]; float dist = delta * steps[id(step)];
// feed so the move takes ~100 ms, i.e. about one interval // feed so the move takes ~100 ms, i.e. about one interval
// ponytail: capped feed lets fast spins queue moves that keep running after the wheel stops; drop excess counts if that bites // ponytail: capped feed lets fast spins queue moves that keep running after the wheel stops; drop excess counts if that bites
@@ -111,9 +118,9 @@ sensor:
number: 5 number: 5
mode: INPUT_PULLUP mode: INPUT_PULLUP
on_clockwise: on_clockwise:
- lambda: 'id(axis) = std::min(id(axis) + 1, 2);' - lambda: 'id(axis) = std::min(id(axis) + 1, 2); id(last_active) = millis();'
on_anticlockwise: on_anticlockwise:
- lambda: 'id(axis) = std::max(id(axis) - 1, 0);' - lambda: 'id(axis) = std::max(id(axis) - 1, -1); id(last_active) = millis();'
- platform: rotary_encoder - platform: rotary_encoder
id: step_encoder id: step_encoder
pin_a: pin_a:
@@ -123,9 +130,9 @@ sensor:
number: 8 number: 8
mode: INPUT_PULLUP mode: INPUT_PULLUP
on_clockwise: on_clockwise:
- lambda: 'id(step) = std::min(id(step) + 1, 2);' - lambda: 'id(step) = std::min(id(step) + 1, 2); id(last_active) = millis();'
on_anticlockwise: on_anticlockwise:
- lambda: 'id(step) = std::max(id(step) - 1, 0);' - lambda: 'id(step) = std::max(id(step) - 1, 0); id(last_active) = millis();'
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
@@ -134,7 +141,7 @@ binary_sensor:
pin: pin:
number: 0 number: 0
inverted: true inverted: true
# axis push: zero the selected axis in work coordinates # axis push: zero the selected axis in work coordinates (nothing while locked)
- platform: gpio - platform: gpio
id: axis_button id: axis_button
name: Axis Button name: Axis Button
@@ -145,7 +152,7 @@ binary_sensor:
filters: filters:
- delayed_on_off: 20ms - delayed_on_off: 20ms
on_press: on_press:
- lambda: 'moonraker::client.gcode(str_sprintf("G92 %c0", "XYZ"[id(axis)]));' - lambda: 'if (id(axis) >= 0) moonraker::client.gcode(str_sprintf("G92 %c0", "XYZ"[id(axis)]));'
- platform: gpio - platform: gpio
id: step_button id: step_button
name: Step Button name: Step Button
@@ -196,11 +203,9 @@ binary_sensor:
- lambda: 'moonraker::client.post("/printer/emergency_stop", "", true);' - lambda: 'moonraker::client.post("/printer/emergency_stop", "", true);'
font: font:
# X11 misc-fixed bitmap fonts (as in u8g2 / Marlin), 6 px wide: axis letter + "-123.456" fits 64 px # Tiny5 Mono bitmap, 6x9 cell: axis letter + "-123.456" fits 64 px
- file: assets/fonts/6x13.bdf - file: assets/fonts/Tiny5Mono.bdf
id: font_big id: font_mono
- file: assets/fonts/6x10.bdf
id: font_small
spi: spi:
clk_pin: 13 clk_pin: 13
@@ -220,16 +225,23 @@ display:
lambda: |- lambda: |-
static const char *steps[] = {"0.01", "0.1", "1"}; static const char *steps[] = {"0.01", "0.1", "1"};
auto s = moonraker::client.status(); auto s = moonraker::client.status();
it.printf(0, 0, id(font_small), "%s", s.state.c_str()); it.printf(0, 0, id(font_mono), "%s", s.state.c_str());
it.printf(0, 10, id(font_small), "H:%s", s.homed.empty() ? "-" : s.homed.c_str()); it.printf(0, 10, id(font_mono), "H:%s", s.homed.empty() ? "-" : s.homed.c_str());
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
int y = 22 + i * 14; int y = 21 + i * 11;
Color c = COLOR_ON; Color c = COLOR_ON;
if (i == id(axis)) { if (i == id(axis)) {
it.filled_rectangle(0, y, 64, 13); it.filled_rectangle(0, y, 64, 10);
c = COLOR_OFF; c = COLOR_OFF;
} }
it.printf(1, y + 1, id(font_big), c, "%c", "XYZ"[i]); it.printf(1, y + 1, id(font_mono), c, "%c", "XYZ"[i]);
it.printf(63, y + 1, id(font_big), c, TextAlign::TOP_RIGHT, "%.3f", s.pos[i]); it.printf(63, y + 1, id(font_mono), c, TextAlign::TOP_RIGHT, "%.3f", s.pos[i]);
}
it.printf(0, 118, id(font_mono), "%s mm", steps[id(step)]);
// corner: seconds until the handwheel locks, LCK once it has
if (id(axis) < 0) {
it.print(63, 118, id(font_mono), TextAlign::TOP_RIGHT, "LCK");
} else {
int left = ${autolock} - (int) ((millis() - id(last_active)) / 1000);
it.printf(63, 118, id(font_mono), TextAlign::TOP_RIGHT, "%d", std::max(left, 0));
} }
it.printf(0, 118, id(font_small), "%s mm", steps[id(step)]);
-7
View File
@@ -77,13 +77,6 @@ binary_sensor:
id: media_out id: media_out
light: light:
# - platform: neopixelbus
# type: GRB
# pin: 27
# variant: WS2812
# num_leds: 1
# name: On-Board LED"
# id: neo_buildin
- platform: rgb - platform: rgb
name: Light name: Light
id: led_light id: led_light
+173 -240
View File
@@ -1,22 +1,16 @@
--- ---
# Hardware: M5Stack M5Stamp C3 # Hardware: M5Stack M5Stamp C3, GNSS test bench with two receivers
# Pinout: # Pinout:
# GPIO0 I2C SCL -> i2c_grove (i2c scl) # GPIO0 Grove A pin 4, UART TX -> uart_m10 (uart tx_pin)
# GPIO1 I2C SDA, BUTTON -> i2c_grove (i2c sda) # GPIO1 Grove A pin 3, UART RX -> uart_m10 (uart rx_pin)
# GPIO2 RGB # GPIO18 Grove B pin 4 (USB D-), UART TX -> uart_at6668 (uart tx_pin)
# GPIO4 GPIO # GPIO19 Grove B pin 3 (USB D+), UART RX -> uart_at6668 (uart rx_pin)
# GPIO5 GPIO # GPIO20 UART0 RX (on-board USB to UART), unused: logger is API only
# GPIO6 GPIO # GPIO21 UART0 TX (on-board USB to UART), unused: logger is API only
# GPIO7 GPIO # Grove pin order: GND, 5V, signal, signal
# GPIO8 GPIO # Receivers:
# GPIO9 GPIO # Grove A XYZ GNSS YM-250, u-blox M10 (ROM SPG 5.10, PROTVER 34.10), 38400 baud -> gnss_m10 (ubx)
# GPIO10 GPIO # Grove B M5Stack Cap LoRa-1262 GNSS, AT6668 (CASIC), 115200 baud -> gnss_at6668 (casic)
# GPIO18 UART RX -> uart_hdmi_switch (uart rx_pin)
# GPIO19 UART TX -> uart_hdmi_switch (uart tx_pin)
# GPIO20 UART RX, LOGGER -> uart_log (uart rx_pin)
# GPIO21 UART TX, LOGGER -> uart_log (uart tx_pin)
# I2C:
# 0x20 pcf8574_hub (pcf8574)
substitutions: substitutions:
device: eworkbench device: eworkbench
name: Electronics Workbench name: Electronics Workbench
@@ -36,237 +30,176 @@ esp32:
toolchain: esp-idf toolchain: esp-idf
framework: framework:
type: esp-idf type: esp-idf
advanced:
flash_chip: generic
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml
i2c: external_components:
- id: i2c_grove # geolocation hub + nmea, ubx and casic platforms: esphome/esphome#23301 (stacked on #23293) + casic, not upstream yet
sda: 1 - source: github://randybb/esphome@geolocation-casic
scl: 0 components: [geolocation, nmea, ubx, casic]
scan: true
# - id: i2c_grove_2 logger:
# sda: 19 # The C3 has two UARTs and both receivers need one; logs go over the API only
# scl: 18 baud_rate: 0
# scan: true
uart: uart:
- id: uart_log - id: uart_m10
rx_pin: 20 rx_pin: 1
tx_pin: 21 tx_pin: 0
baud_rate: 38400
# Test aid: decode the answers to the polls in interval below
debug:
direction: RX
after:
bytes: 1024
timeout: 50ms
sequence:
- lambda: |-
for (size_t i = 0; i + 8 <= bytes.size(); i++) {
if (bytes[i] != 0xB5 || bytes[i + 1] != 0x62)
continue;
const uint8_t cls = bytes[i + 2], id = bytes[i + 3];
const size_t len = bytes[i + 4] | (bytes[i + 5] << 8);
if (i + 6 + len > bytes.size())
break;
const uint8_t *p = bytes.data() + i + 6;
if (cls == 0x0A && id == 0x28 && len >= 8) {
ESP_LOGI("ubxdbg", "MON-GNSS supported 0x%02X default 0x%02X enabled 0x%02X (bit0 GPS 1 GLO 2 BDS 3 GAL), max %u at once",
p[1], p[2], p[3], p[4]);
} else if (cls == 0x01 && id == 0x35 && len >= 8) {
static const char *const NAMES[] = {"GPS", "SBAS", "GAL", "BDS", "IMES", "QZSS", "GLO", "NAVIC"};
int tracked[8] = {0}, used[8] = {0}, sbas_corr = 0;
std::string sbas;
const uint8_t num = p[5];
for (uint8_t k = 0; k < num && 8 + 12 * (k + 1) <= len; k++) {
const uint8_t *b = p + 8 + 12 * k;
const uint32_t flags = b[8] | (b[9] << 8) | (b[10] << 16) | ((uint32_t) b[11] << 24);
const uint8_t g = b[0] & 7;
if (b[2] > 0)
tracked[g]++;
if (flags & (1u << 3))
used[g]++;
if (flags & (1u << 16))
sbas_corr++;
if (b[0] == 1 && b[2] > 0) {
char buf[16];
snprintf(buf, sizeof(buf), " %u:%u", b[1], b[2]);
sbas += buf;
}
}
std::string summary;
for (int g = 0; g < 8; g++) {
if (tracked[g] == 0)
continue;
char buf[24];
snprintf(buf, sizeof(buf), " %s %d/%d", NAMES[g], used[g], tracked[g]);
summary += buf;
}
ESP_LOGI("ubxdbg", "NAV-SAT used/tracked:%s; SBAS-corrected %d; SBAS PRN:cno%s", summary.c_str(), sbas_corr,
sbas.c_str());
}
i += 5 + len;
}
- id: uart_at6668
rx_pin: 19
tx_pin: 18
baud_rate: 115200 baud_rate: 115200
- id: uart_hdmi_switch
rx_pin: 18
tx_pin: 19
baud_rate: 9600
pcf8574: geolocation:
- id: 'pcf8574_hub' - platform: ubx
address: 0x20 id: gnss_m10
pcf8575: true uart_id: uart_m10
update_interval: 10s
- platform: casic
id: gnss_at6668
uart_id: uart_at6668
update_interval: 10s
switch: sensor:
- platform: gpio - platform: geolocation
name: "PCF8574 Pin #0" geolocation_id: gnss_m10
pin: type: latitude
pcf8574: pcf8574_hub name: M10 Latitude
number: 0 - platform: geolocation
# One of INPUT or OUTPUT geolocation_id: gnss_m10
mode: type: longitude
output: true name: M10 Longitude
inverted: false - platform: geolocation
- platform: gpio geolocation_id: gnss_m10
name: "PCF8574 Pin #1" type: altitude
pin: name: M10 Altitude
pcf8574: pcf8574_hub - platform: geolocation
number: 1 geolocation_id: gnss_m10
# One of INPUT or OUTPUT type: speed
mode: name: M10 Speed
output: true - platform: geolocation
inverted: false geolocation_id: gnss_m10
- platform: gpio type: course
name: "PCF8574 Pin #7" name: M10 Course
pin: - platform: geolocation
pcf8574: pcf8574_hub geolocation_id: gnss_m10
number: 7 type: satellites
# One of INPUT or OUTPUT name: M10 Satellites
mode: - platform: geolocation
output: true geolocation_id: gnss_m10
inverted: false type: hdop
name: M10 HDOP
- platform: geolocation
geolocation_id: gnss_m10
type: horizontal_accuracy
name: M10 Horizontal Accuracy
- platform: geolocation
geolocation_id: gnss_m10
type: vertical_accuracy
name: M10 Vertical Accuracy
- platform: geolocation
geolocation_id: gnss_at6668
type: latitude
name: AT6668 Latitude
- platform: geolocation
geolocation_id: gnss_at6668
type: longitude
name: AT6668 Longitude
- platform: geolocation
geolocation_id: gnss_at6668
type: altitude
name: AT6668 Altitude
- platform: geolocation
geolocation_id: gnss_at6668
type: speed
name: AT6668 Speed
- platform: geolocation
geolocation_id: gnss_at6668
type: course
name: AT6668 Course
- platform: geolocation
geolocation_id: gnss_at6668
type: satellites
name: AT6668 Satellites
- platform: geolocation
geolocation_id: gnss_at6668
type: hdop
name: AT6668 HDOP
binary_sensor: time:
- platform: gpio - platform: geolocation
name: "PCF8574 Pin #10" id: gnss_time
pin: geolocation_id: gnss_m10
pcf8574: pcf8574_hub on_time_sync:
number: 8 - logger.log: GNSS time synced
# One of INPUT or OUTPUT
mode: INPUT
inverted: false
- platform: gpio
name: "PCF8574 Pin #11"
pin:
pcf8574: pcf8574_hub
number: 9
# One of INPUT or OUTPUT
mode: INPUT
inverted: false
- platform: gpio
name: "PCF8574 Pin #12"
pin:
pcf8574: pcf8574_hub
number: 10
# One of INPUT or OUTPUT
mode: INPUT
inverted: false
- platform: gpio
name: "PCF8574 Pin #13"
pin:
pcf8574: pcf8574_hub
number: 11
# One of INPUT or OUTPUT
mode: INPUT
inverted: false
- platform: gpio
name: "PCF8574 Pin #14"
pin:
pcf8574: pcf8574_hub
number: 12
# One of INPUT or OUTPUT
mode: INPUT
inverted: false
- platform: gpio
name: "PCF8574 Pin #15"
pin:
pcf8574: pcf8574_hub
number: 13
# One of INPUT or OUTPUT
mode: INPUT
inverted: false
- platform: gpio
name: "PCF8574 Pin #16"
pin:
pcf8574: pcf8574_hub
number: 14
# One of INPUT or OUTPUT
mode: INPUT
inverted: false
- platform: gpio
name: "PCF8574 Pin #17"
pin:
pcf8574: pcf8574_hub
number: 15
# One of INPUT or OUTPUT
mode: INPUT
inverted: false
# binary_sensor: interval:
# - platform: gpio # Test aid: constellations and satellites of the M10
# id: rotary_encoder_button - interval: 60s
# pin: then:
# number: 6 - uart.write:
# # mode: INPUT_PULLUP id: uart_m10
# inverted: true data: [0xB5, 0x62, 0x0A, 0x28, 0x00, 0x00, 0x32, 0xA0]
# filters: - delay: 2s
# - delayed_on: 30ms - uart.write:
# - delayed_off: 30ms id: uart_m10
# on_press: data: [0xB5, 0x62, 0x01, 0x35, 0x00, 0x00, 0x36, 0xA3]
# - display_menu.enter:
# display:
# - platform: lcd_pcf8574
# id: my_lcd
# i2c_id: i2c_grove
# dimensions: 20x4
# address: 0x27
# user_characters:
# - position: 0
# data: # mark_back symbol
# - 0b00100
# - 0b01000
# - 0b11110
# - 0b01001
# - 0b00101
# - 0b00001
# - 0b11110
# - 0b00000
# lambda: |-
# id(my_lcd_menu).draw();
# if (!id(my_lcd_menu).is_active())
# it.print("Menu is not active");
# lcd_menu:
# id: my_lcd_menu
# display_id: my_lcd
# active: true
# mode: rotary
# mark_back: 0x08
# mark_selected: 0x3e
# mark_editing: 0x2a
# mark_submenu: 0x7e
# items:
# - type: back
# text: 'Back'
# - type: label
# text: 'Label 1'
# - type: label
# text: !lambda |-
# return "Templated label";
# select:
# - platform: template
# id: hdmi_switch
# optimistic: true
# options:
# - PC1
# - PC2
# - PC3
# - PC4
# initial_option: PC1
# # set_action:
# # - logger.log:
# # format: "Chosen option: %s (index %d)"
# # args: ["x.c_str()", "i"]
# # - uart.write:
# # id: uart_hdmi_switch
# # data: [0x47, 0x30, 0x31, 0x67, 0x41, 0x00]
# sensor:
# - platform: rotary_encoder
# id: rotary_encoder_sensor
# pin_a: 4
# pin_b: 5
# filters:
# debounce: 30ms
# on_anticlockwise:
# - display_menu.up:
# on_clockwise:
# - display_menu.down:
# display:
# - platform: tm1637
# id: tm1637_display
# clk_pin: 4
# dio_pin: 5
# update_interval: 500ms
# # intensity: 0
# lambda: |-
# static int i = 0;
# i++;
# if (id(alarm_id)) {
# if ((i % 2) == 0)
# it.print("8 8 ");
# else
# it.print(" 8 8");
# } else {
# if (((i / 10) % 2) == 0) {
# //it.set_intensity(7);
# if ((i % 2) == 0)
# it.strftime("%H.%M", id(ha_time).now());
# else
# it.strftime("%H%M", id(ha_time).now());
# } else {
# //it.set_intensity(1);
# it.printf("%.0f~C", id(temperature).state);
# }
# }
+13
View File
@@ -34,6 +34,7 @@ esp32:
flash_chip: gd flash_chip: gd
type: esp-idf type: esp-idf
# iBeacon on air from boot without the empty standard advertisement every 10 s
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml ipv6_only: !include common/ipv6_only.yaml
@@ -107,8 +108,20 @@ globals:
esp32_ble_tracker: esp32_ble_tracker:
id: ${device}_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: scan_parameters:
duration: 1min 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: binary_sensor:
- platform: ble_presence - platform: ble_presence
-42
View File
@@ -49,10 +49,6 @@ esp32:
sram1_as_iram: true sram1_as_iram: true
external_components: external_components:
# Ethernet LLDP 802.1AB transmitter
# - source: github://pr#11760
# components: [ethernet]
# refresh: 1h
- source: github://pr#2112 - source: github://pr#2112
components: ["m5stack_4relay"] components: ["m5stack_4relay"]
refresh: 1h refresh: 1h
@@ -67,44 +63,6 @@ i2c:
scl: 16 scl: 16
scan: true scan: true
# ethernet:
# lldp:
# # Enable LLDP transmission
# #enabled: true
# # Optional: override default port
# port: eth
# # Optional: override default system name
# system_name: mcu-${device}
# # Optional: override default system description
# system_description: ${comment}
# # Optional: override default "fast mode" burst packet count
# tx_fast_count: 4
# # Optional: override default LLDP frame transmission interval
# tx_interval: 30
# # Optional: override default hold count, used in conjuction with tx_interval to calculate overall TTL
# tx_hold: 4
# ethernet:
# type: LAN8720
# mdc_pin: 23
# mdio_pin: 18
# clk_mode: GPIO17_OUT
# phy_addr: 0
# power_pin: 12
# use_address: 10.17.240.245
# # Optional manual IP
# manual_ip:
# static_ip: 10.17.240.254
# gateway: 10.17.240.1
# subnet: 255.255.255.0
# ethernet:
# use_address: 10.17.241.254
# use_address: 10.17.241.98
# use_address: mcu-gateway.local
uart: uart:
id: uart_modbus id: uart_modbus
tx_pin: 4 tx_pin: 4
+2
View File
@@ -35,9 +35,11 @@ esphome:
- id: heating - id: heating
name: Heating name: Heating
area_id: local_area area_id: local_area
relation: child
- id: hot_water - id: hot_water
name: Hot Water name: Hot Water
area_id: local_area area_id: local_area
relation: child
esp32: esp32:
variant: esp32 variant: esp32
+206
View File
@@ -0,0 +1,206 @@
---
# Hardware: Seeed Studio XIAO ESP32-C5 (host, its own radio in 802.11p for ITS-G5)
# + Seeed Studio XIAO ESP32-C6 (esp32_hosted co-processor, Wi-Fi uplink over SPI)
# Wi-Fi on the C6 needs esphome/esphome#22819 and hn/esphome-its-g5#3 (external components below)
# and the co-processor firmware from hosted/xiao-c6-spi on the C6.
# Pinout:
# GPIO8 D8 -> esp32_hosted clk -> C6 D8 GPIO19
# GPIO9 D9 <- esp32_hosted miso <- C6 D9 GPIO20
# GPIO10 D10 -> esp32_hosted mosi -> C6 D10 GPIO18
# GPIO7 D3 -> esp32_hosted cs -> C6 D3 GPIO21
# GPIO1 D0 <- esp32_hosted handshake <- C6 D0 GPIO0
# GPIO0 D1 <- esp32_hosted data_ready <- C6 D1 GPIO1
# GPIO25 D2 -> esp32_hosted reset -> C6 D2 GPIO2 (CP firmware restarts itself on LOW)
# GND, 3V3 shared
substitutions:
device: its-g5
name: ITS-G5
area: DEV
comment: ITS-G5 receiver
# OpenTrafficMap node ID (MQTT topics its/<node_id>/...): the reference firmware uses the MAC as
# lowercase hex; replace it if opentrafficmap assigned a name (e.g. "node789")
node_id: "3844bebe8638"
esphome:
name: mcu-${device}
friendly_name: ${name}
area: ${area}
comment: ${comment}
includes:
- common/its_g5/decode.h # its_g5_decode:: header decoding for the lambdas below
esp32:
board: seeed_xiao_esp32c5
framework:
type: esp-idf
packages:
common: !include common/common.yaml
# ipv6_only off: eppp_link (pulled in by esp_wifi_remote) needs IPv4, fix belongs in esp-protocols
# ipv6_only: !include common/ipv6_only.yaml
# IPv4 only: the car hotspot (O2 SK) has no IPv6, but MQTT prefers the broker's AAAA record whenever
# IPv6 is enabled, even with only a link-local address, and never falls back to IPv4
network:
enable_ipv6: false
# MQTT only: HA can't reach the API on the car hotspot, and both would duplicate the entities
api: !remove
time: !remove # homeassistant time needs the API
ota:
- id: !extend ota_esphome
encryption:
key: !secret api_key # was inherited from api
external_components:
# Wi-Fi on the esp32_hosted co-processor of a host with its own radio
- source: github://pr#22819
components: [wifi]
# its_g5_receiver allowing wifi on the co-processor
- source: github://hn/esphome-its-g5@pull/3/head
components: [its_g5_receiver]
refresh: 1d
esp32_hosted:
type: spi
variant: ESP32C6
clk_pin: GPIO8
miso_pin: GPIO9
mosi_pin: GPIO10
cs_pin: GPIO7
handshake_pin: GPIO1
data_ready_pin: GPIO0
reset_pin: GPIO25
wifi:
use_coprocessor: true # Wi-Fi on the C6, the C5 radio is for 802.11p
# car: ESP joins the tablet's hotspot as a client
min_auth_mode: WPA2
networks:
- id: !remove wifi_iot
- ssid: !secret wifi_ssid_0
password: !secret wifi_password_0
# Raw 802.11 frames as UDP broadcasts; in Wireshark use the "UDP Listener"
# (udpdump) interface on port 18511 with payload "wlan".
udp:
id: its_udp
# Own broker as on the tracker: HA sees the entities (API is unreachable on the car hotspot), and an
# EMQX bridge forwards its/${node_id}/# to cits1.opentrafficmap.org:8883 (as hn's its-g5-opentrafficmap.yaml)
mqtt:
id: mqtt_client
broker: !secret mqtt_ext
# Own user, so the broker ACL can limit it to its own topics
username: !secret mqtt_its_g5_username
password: !secret mqtt_its_g5_password
discovery: true
# MAC in the unique_id: the default ESP<type><object_id> clashes with the tracker's common entities
discovery_unique_id_generator: mac
log_topic: null
birth_message:
topic: its/${node_id}/status
payload: online
retain: true
will_message:
topic: its/${node_id}/status
payload: offline
retain: true
on_connect:
- delay: 3s
- lambda: |-
uint8_t mac[6];
get_mac_address_raw(mac);
char info[160];
int n = snprintf(info, sizeof(info),
"{\"emac\":\"%02x:%02x:%02x:%02x:%02x:%02x\",\"ver\":\"%s\",\"hwv\":\"esphome\"}",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], ESPHOME_VERSION);
id(mqtt_client).publish("its/${node_id}/info", info, n, 0, false);
interval:
- interval: 60s
then:
- lambda: |-
char stats[48];
int n = snprintf(stats, sizeof(stats), "{\"rbt\":%llu}", millis_64() / 1000ULL);
id(mqtt_client).publish("its/${node_id}/stats", stats, n, 0, false);
its_g5_receiver:
id: g5
channel: 5900 # G5CC
broadcast_only: true
on_packet:
- lambda: |-
id(mqtt_client).publish("its/${node_id}/packet", (const char *) x.data(), x.size(), 0, false);
- udp.write:
id: its_udp
data: !lambda return x;
- lambda: |-
if (!its_g5_decode::handle(x))
return;
const auto &i = its_g5_decode::stats.last;
ESP_LOGD("its_g5", "%s from %s %.6f,%.6f %.0f km/h %.0f deg%s, rssi %.0f dBm",
its_g5_decode::port_name(i.port), its_g5_decode::station_name(i.station_type),
i.lat, i.lon, i.speed_kmh, i.heading, i.secured ? ", signed" : "", rssi);
// Decoded header for HA/maptool, 1 Hz per station (CAMs come up to 10 Hz per vehicle)
if (!its_g5_decode::due(i.addr, millis(), 1000))
return;
char json[192];
int n = snprintf(json, sizeof(json),
"{\"msg\":\"%s\",\"station\":\"%s\",\"id\":\"%016llx\",\"lat\":%.7f,\"lon\":%.7f,"
"\"speed\":%.1f,\"heading\":%.1f,\"secured\":%s,\"rssi\":%.0f}",
its_g5_decode::port_name(i.port), its_g5_decode::station_name(i.station_type),
(unsigned long long) i.addr, i.lat, i.lon, i.speed_kmh, i.heading,
i.secured ? "true" : "false", rssi);
// outside its/${node_id}/#, so the EMQX bridge keeps it off OpenTrafficMap
id(mqtt_client).publish("mcu-${device}/decoded", json, n, 0, false);
sensor:
- platform: its_g5_receiver
its_g5_receiver_id: g5
bytes_received:
name: Bytes Received
packets_received:
name: Packets Received
packets_dropped:
name: Packets Dropped
- platform: template
name: CAM Received
state_class: total_increasing
accuracy_decimals: 0
lambda: return its_g5_decode::stats.cam;
- platform: template
name: DENM Received
state_class: total_increasing
accuracy_decimals: 0
lambda: return its_g5_decode::stats.denm;
- platform: template
name: SPATEM Received
state_class: total_increasing
accuracy_decimals: 0
lambda: return its_g5_decode::stats.spatem;
- platform: template
name: MAPEM Received
state_class: total_increasing
accuracy_decimals: 0
lambda: return its_g5_decode::stats.mapem;
binary_sensor:
- platform: template
name: MQTT Connected
device_class: connectivity
entity_category: diagnostic
lambda: return id(mqtt_client).is_connected();
text_sensor:
- platform: template
name: Last Station
update_interval: 10s
lambda: |-
const auto &i = its_g5_decode::stats.last;
if (i.lat == 0 && i.lon == 0)
return {};
char buf[96];
snprintf(buf, sizeof(buf), "%s %s %.6f,%.6f %.0f km/h %.0f°", its_g5_decode::port_name(i.port),
its_g5_decode::station_name(i.station_type), i.lat, i.lon, i.speed_kmh, i.heading);
return std::string(buf);
+3 -8
View File
@@ -86,13 +86,8 @@ packages:
api: api:
# status page until Home Assistant connects (log viewers don't subscribe to states) # status page until Home Assistant connects (log viewers don't subscribe to states)
on_client_connected: # Home Assistant has subscribed and received every state
- delay: 2s on_client_synced:
- if:
condition:
api.connected:
state_subscription_only: true
then:
- lvgl.page.show: main_page - lvgl.page.show: main_page
on_client_disconnected: on_client_disconnected:
- if: - if:
@@ -249,7 +244,7 @@ lvgl:
bg_color: 0xE08A00 bg_color: 0xE08A00
top_layer: top_layer:
widgets: widgets:
# same navigation bar as on mcu-lvgl-trainer # same navigation bar as on mcu-trainer
- buttonmatrix: - buttonmatrix:
id: nav_bar id: nav_bar
align: bottom_mid align: bottom_mid
+1 -1
View File
@@ -30,7 +30,7 @@ esp32:
toolchain: esp-idf toolchain: esp-idf
framework: framework:
advanced: advanced:
flash_chip: generic # same board as lvgl-trainer (not read from the device) flash_chip: generic # same board as mcu-trainer (not read from the device)
type: esp-idf type: esp-idf
packages: packages:
+632 -61
View File
@@ -88,12 +88,36 @@ substitutions:
name: LVGL name: LVGL
area: DEV area: DEV
comment: LVGL comment: LVGL
# Pip-Boy palette
pip_green: "0x7DF59A"
pip_dim: "0x3B7A4E"
pip_line: "0x24432E"
pip_panel: "0x12261A"
pip_bg: "0x0A0F0B"
# tab bar: 4 tabs, bracket follows the active one
tab_w: "150"
tab_step: "190"
tab_x0: "44"
tab_x1: "234"
tab_x2: "424"
tab_x3: "614"
# MAP tab: centre and zoom of assets/images/pipboy_map.png, re-render it when changing:
# python3 assets/images/make_map.py ${map_lat} ${map_lon} ${map_zoom} ${map_w} ${map_h} assets/images/pipboy_map.png
map_lat: "48.0538401"
map_lon: "17.3656273"
map_zoom: "14"
map_w: "768"
map_h: "316"
map_y: "104"
map_name: "KVETOSLAVOV"
esphome: esphome:
name: mcu-${device} name: mcu-${device}
friendly_name: ${name} friendly_name: ${name}
area: ${area} area: ${area}
comment: ${comment} comment: ${comment}
includes:
- common/nspanel_terminal/weather.h # weather_icon()
on_boot: on_boot:
- priority: -100 - priority: -100
then: then:
@@ -124,13 +148,8 @@ packages:
api: api:
# status page until Home Assistant connects (log viewers don't subscribe to states) # status page until Home Assistant connects (log viewers don't subscribe to states)
on_client_connected: # Home Assistant has subscribed and received every state
- delay: 2s on_client_synced:
- if:
condition:
api.connected:
state_subscription_only: true
then:
- lvgl.page.show: main_page - lvgl.page.show: main_page
on_client_disconnected: on_client_disconnected:
- if: - if:
@@ -141,6 +160,10 @@ api:
then: then:
- lvgl.page.show: status_page - lvgl.page.show: status_page
# the USB port on this board is a CH340 on UART0, not the S3 USB-JTAG
logger:
hardware_uart: UART0
i2c: i2c:
- id: i2c_main - id: i2c_main
sda: 19 sda: 19
@@ -178,7 +201,182 @@ light:
output: gpio_backlight_pwm output: gpio_backlight_pwm
restore_mode: ALWAYS_ON restore_mode: ALWAYS_ON
# Pip-Boy look (after the Fallout 4 Pip-Boy: tab bar with a bracket on the active tab, status bar at the bottom)
# STAT weekday, date, weather, name day, clock
# DATA weather from Home Assistant as a list
# MAP map around home with Home Assistant persons
# SYS status page (shown until Home Assistant connects)
# bottom bar: HP = WiFi signal, LEVEL = uptime days (bar: time of day), AP = free internal RAM
sensor:
- platform: homeassistant
id: outside_temperature
entity_id: sensor.zigbee_outside_temperature
internal: true
on_value:
- script.execute: update_data
- platform: homeassistant
id: outside_humidity
entity_id: weather.outside
attribute: humidity
internal: true
on_value:
- script.execute: update_data
- platform: homeassistant
id: outside_pressure
entity_id: weather.outside
attribute: pressure
internal: true
on_value:
- script.execute: update_data
- platform: homeassistant
id: outside_wind
entity_id: weather.outside
attribute: wind_speed
internal: true
on_value:
- script.execute: update_data
# persons on the MAP tab
- platform: homeassistant
id: romanko_lat
entity_id: person.romanko
attribute: latitude
internal: true
on_value:
- script.execute: update_map
- platform: homeassistant
id: romanko_lon
entity_id: person.romanko
attribute: longitude
internal: true
on_value:
- script.execute: update_map
- platform: homeassistant
id: janko_lat
entity_id: person.janko
attribute: latitude
internal: true
on_value:
- script.execute: update_map
- platform: homeassistant
id: janko_lon
entity_id: person.janko
attribute: longitude
internal: true
on_value:
- script.execute: update_map
text_sensor:
- platform: homeassistant
id: weather_state
entity_id: weather.outside
internal: true
on_value:
- script.execute: update_data
- platform: homeassistant
id: nameday
entity_id: sensor.nameday_sk
internal: true
on_value:
- lvgl.label.update:
id: nameday_label
text: !lambda 'return "MENINY: " + x;'
script: script:
- id: update_data
then:
- lambda: |-
auto num = [](sensor::Sensor *s, const char *fmt) {
return s->has_state() && !std::isnan(s->state) ? str_sprintf(fmt, s->state) : std::string("--");
};
const std::string cond = id(weather_state).has_state() ? id(weather_state).state : "";
std::string cond_up = cond.empty() ? "--" : cond;
for (auto &c : cond_up)
c = c == '-' ? ' ' : toupper(c);
const std::string temp = num(id(outside_temperature), "%.1f°C");
// STAT
lv_label_set_text(id(stat_icon), weather_icon(cond));
lv_label_set_text(id(stat_temp), temp.c_str());
// DATA
lv_label_set_text(id(row_temp_val), temp.c_str());
lv_label_set_text(id(row_cond_val), cond_up.c_str());
lv_label_set_text(id(row_hum_val), num(id(outside_humidity), "%.0f %%").c_str());
lv_label_set_text(id(row_press_val), num(id(outside_pressure), "%.0f hPa").c_str());
lv_label_set_text(id(row_wind_val), num(id(outside_wind), "%.0f km/h").c_str());
# DATA: highlight the touched row like the Pip-Boy cursor
- id: select_row
parameters:
row: int
then:
- lambda: |-
lv_obj_t *const rows[] = {id(row_temp), id(row_cond), id(row_hum), id(row_press), id(row_wind)};
lv_obj_t *const marks[] = {id(row_temp_mark), id(row_cond_mark), id(row_hum_mark), id(row_press_mark),
id(row_wind_mark)};
for (int i = 0; i < 5; i++) {
lv_obj_set_style_bg_opa(rows[i], i == row ? LV_OPA_COVER : LV_OPA_TRANSP, LV_PART_MAIN);
if (i == row)
lv_obj_remove_flag(marks[i], LV_OBJ_FLAG_HIDDEN);
else
lv_obj_add_flag(marks[i], LV_OBJ_FLAG_HIDDEN);
}
- id: update_map
then:
- lambda: |-
// Web Mercator, same projection as the map tiles
static const double N = 256.0 * (1 << ${map_zoom});
auto wx = [](double lon) { return (lon + 180) / 360 * N; };
auto wy = [](double lat) { return (1 - std::asinh(std::tan(lat * M_PI / 180)) / M_PI) / 2 * N; };
auto place = [&](lv_obj_t *marker, sensor::Sensor *lat, sensor::Sensor *lon) {
if (lat->has_state() && lon->has_state() && !std::isnan(lat->state) && !std::isnan(lon->state)) {
// map image is ${map_w}x${map_h} at 16,${map_y}; the marker ring (14x14) is at the container's edge
const int x = ${map_w} / 2 + (int) (wx(lon->state) - wx(${map_lon}));
const int y = ${map_h} / 2 + (int) (wy(lat->state) - wy(${map_lat}));
if (x >= 0 && x < ${map_w} && y >= 0 && y < ${map_h}) {
lv_obj_update_layout(marker);
const bool right = lv_obj_get_style_flex_flow(marker, LV_PART_MAIN) == LV_FLEX_FLOW_ROW_REVERSE;
lv_obj_set_pos(marker, 16 + (right ? x + 7 - lv_obj_get_width(marker) : x - 7),
${map_y} + y - lv_obj_get_height(marker) / 2);
lv_obj_remove_flag(marker, LV_OBJ_FLAG_HIDDEN);
return;
}
}
lv_obj_add_flag(marker, LV_OBJ_FLAG_HIDDEN); // unknown or off the map
};
place(id(marker_romanko), id(romanko_lat), id(romanko_lon));
place(id(marker_janko), id(janko_lat), id(janko_lon));
- id: update_stat
then:
- lambda: |-
const bool wifi_ok = wifi::global_wifi_component->is_connected();
const int rssi = wifi_ok ? wifi::global_wifi_component->wifi_rssi() : -100;
const int hp = std::clamp(2 * (rssi + 100), 0, 100);
lv_label_set_text(id(hp_label), str_sprintf("HP %d/100", hp).c_str());
const uint32_t up = millis() / 1000;
lv_label_set_text(id(level_label), str_sprintf("LEVEL %u", up / 86400 + 1).c_str());
lv_bar_set_value(id(xp_bar), (up % 86400) * 100 / 86400, LV_ANIM_OFF);
const size_t total = heap_caps_get_total_size(MALLOC_CAP_INTERNAL);
const int ap = total ? heap_caps_get_free_size(MALLOC_CAP_INTERNAL) * 100 / total : 0;
lv_label_set_text(id(ap_label), str_sprintf("AP %d/100", ap).c_str());
- id: update_clock
then:
- lambda: |-
auto now = id(ha_time).now();
if (!now.is_valid())
return;
auto upper = [](std::string s) {
for (auto &c : s)
c = toupper(c);
return s;
};
lv_label_set_text(id(clock_label), now.strftime("%H\n%M").c_str());
lv_label_set_text(id(weekday_label), upper(now.strftime("%A")).c_str());
lv_label_set_text(id(date_label), upper(now.strftime("%b %d %Y")).c_str());
- id: update_status - id: update_status
then: then:
- lambda: |- - lambda: |-
@@ -226,35 +424,98 @@ script:
lv_label_set_text(id(status_footer), lv_label_set_text(id(status_footer),
str_sprintf("ESPHome %s · up %ud %02u:%02u:%02u", ESPHOME_VERSION, up / 86400, str_sprintf("ESPHome %s · up %ud %02u:%02u:%02u", ESPHOME_VERSION, up / 86400,
(up / 3600) % 24, (up / 60) % 60, up % 60).c_str()); (up / 3600) % 24, (up / 60) % 60, up % 60).c_str());
# move the bracket to the active tab, dim the others; called from each page's on_load, so it also
# follows pages shown from code (API connect/disconnect)
- id: select_tab
parameters:
tab: int
then:
- lambda: |-
lv_obj_t *const labels[] = {id(tab_stat_label), id(tab_data_label), id(tab_map_label), id(tab_sys_label)};
for (int i = 0; i < 4; i++)
lv_obj_set_style_text_color(labels[i], lv_color_hex(i == tab ? ${pip_green} : ${pip_dim}), LV_PART_MAIN);
lv_obj_set_x(id(tab_bracket), ${tab_x0} + tab * ${tab_step});
// no status bar on SYS, its page needs the room
if (tab == 3)
lv_obj_add_flag(id(bottom_bar), LV_OBJ_FLAG_HIDDEN);
else
lv_obj_remove_flag(id(bottom_bar), LV_OBJ_FLAG_HIDDEN);
interval: interval:
- interval: 1s - interval: 1s
then: then:
- lvgl.label.update: - if:
id: clock_label condition:
text: !lambda |- lvgl.page.is_showing: main_page
auto now = id(ha_time).now(); then:
if (!now.is_valid()) - script.execute: update_clock
return std::string("--:--");
return now.strftime("%H:%M");
- if: - if:
condition: condition:
lvgl.page.is_showing: status_page lvgl.page.is_showing: status_page
then: then:
- script.execute: update_status - script.execute: update_status
else:
- script.execute: update_stat
image: image:
- platform: file - platform: file
file: assets/images/made-for-esphome-white-on-black.svg file: assets/images/made-for-esphome-white-on-black.svg
id: esphome_logo id: esphome_logo
resize: 400x118 resize: 300x88
type: RGB565 type: RGB565
transparency: alpha_channel transparency: alpha_channel
- platform: file
file: assets/images/pipboy_map.png
id: pipboy_map
type: RGB565
font: font:
- file: "gfonts://Roboto@500" - file: "gfonts://Roboto Mono@500"
id: font_clock id: font_clock
size: 200 size: 124
glyphs: "0123456789:-" glyphs: "0123456789-"
- file: "gfonts://Roboto Mono@500"
id: font_tab
size: 30
glyphs: "ADMPSTY"
- file: "gfonts://Roboto Mono"
id: font_big
size: 40
glyphs: "°-"
glyphsets: [GF_Latin_Kernel]
- file: "gfonts://Roboto Mono"
id: font_pip
size: 24
glyphs: "°·"
glyphsets: [GF_Latin_Core]
ignore_missing_glyphs: true # only combining marks (U+0302…), Slovak uses precomposed letters
- file: "gfonts://Roboto Mono"
id: font_small
size: 18
glyphs: "©"
glyphsets: [GF_Latin_Kernel]
- file:
type: web
url: https://github.com/Templarian/MaterialDesign-Webfont/raw/v7.4.47/fonts/materialdesignicons-webfont.ttf
id: font_weather
size: 72
glyphs:
- "\U000F0594" # mdi:weather-night
- "\U000F0599" # mdi:weather-sunny
- "\U000F0595" # mdi:weather-partly-cloudy
- "\U000F0590" # mdi:weather-cloudy
- "\U000F0591" # mdi:weather-fog
- "\U000F0597" # mdi:weather-rainy
- "\U000F0596" # mdi:weather-pouring
- "\U000F0598" # mdi:weather-snowy
- "\U000F067F" # mdi:weather-snowy-rainy
- "\U000F0592" # mdi:weather-hail
- "\U000F0593" # mdi:weather-lightning
- "\U000F067E" # mdi:weather-lightning-rainy
- "\U000F059D" # mdi:weather-windy
- "\U000F059E" # mdi:weather-windy-variant
- "\U000F05D6" # mdi:alert-circle-outline
- file: "gfonts://Roboto" - file: "gfonts://Roboto"
id: font_title id: font_title
size: 40 size: 40
@@ -267,81 +528,391 @@ font:
lvgl: lvgl:
log_level: WARN log_level: WARN
color_depth: 16 color_depth: 16
bg_color: 0x000000 bg_color: ${pip_bg}
text_color: 0xFFFFFF text_color: ${pip_green}
text_font: font_pip
theme: theme:
buttonmatrix: # plain boxes: layout containers, markers and bars set only what they need
obj:
bg_opa: TRANSP bg_opa: TRANSP
border_width: 0 border_width: 0
items: radius: 0
bg_color: 0x2B2F36 pad_all: 0
text_color: 0xFFFFFF text_color: ${pip_green} # the default theme sets a dark text color that labels inherit
radius: 12 button:
checked: bg_opa: TRANSP
bg_color: 0xE08A00 border_width: 0
shadow_width: 0
radius: 0
pressed:
bg_opa: TRANSP
top_layer: top_layer:
widgets: widgets:
# same navigation bar as on mcu-lvgl-trainer # tab bar: rule with end ticks, the bracket covers the rule under the active tab
- buttonmatrix: - obj:
id: nav_bar x: 16
align: bottom_mid y: 56
width: 100% width: 768
height: 64 height: 2
pad_all: 4 bg_color: ${pip_green}
pad_column: 6 bg_opa: COVER
items: - obj:
text_font: montserrat_28 x: 16
rows: y: 56
- buttons: width: 2
- id: page_prev height: 10
text: "\uF053" bg_color: ${pip_green}
bg_opa: COVER
- obj:
x: 782
y: 56
width: 2
height: 10
bg_color: ${pip_green}
bg_opa: COVER
- obj:
id: tab_bracket
x: ${tab_x0}
y: 12
width: ${tab_w}
height: 46
border_side: [LEFT, RIGHT]
border_width: 2
border_color: ${pip_green}
bg_color: ${pip_bg}
bg_opa: COVER
widgets:
- obj:
align: TOP_LEFT
width: 14
height: 2
bg_color: ${pip_green}
bg_opa: COVER
- obj:
align: TOP_RIGHT
width: 14
height: 2
bg_color: ${pip_green}
bg_opa: COVER
- button:
x: ${tab_x0}
y: 12
width: ${tab_w}
height: 44
on_press: on_press:
then: - lvgl.page.show: main_page
lvgl.page.previous: widgets:
- id: page_home - label:
text: "\uF015" id: tab_stat_label
align: CENTER
text_font: font_tab
text: "STAT"
- button:
x: ${tab_x1}
y: 12
width: ${tab_w}
height: 44
on_press: on_press:
then: - lvgl.page.show: data_page
lvgl.page.show: main_page widgets:
- id: page_next - label:
text: "\uF054" id: tab_data_label
align: CENTER
text_font: font_tab
text_color: ${pip_dim}
text: "DATA"
- button:
x: ${tab_x2}
y: 12
width: ${tab_w}
height: 44
on_press: on_press:
then: - lvgl.page.show: map_page
lvgl.page.next: widgets:
- label:
id: tab_map_label
align: CENTER
text_font: font_tab
text_color: ${pip_dim}
text: "MAP"
- button:
x: ${tab_x3}
y: 12
width: ${tab_w}
height: 44
on_press:
- lvgl.page.show: status_page
widgets:
- label:
id: tab_sys_label
align: CENTER
text_font: font_tab
text_color: ${pip_dim}
text: "SYS"
# status bar: HP | LEVEL [xp] | AP
- obj:
id: bottom_bar
x: 16
y: 432
width: 768
height: 40
pad_left: 14
pad_right: 14
bg_color: ${pip_panel}
bg_opa: COVER
layout:
type: flex
flex_flow: row
flex_align_main: SPACE_BETWEEN
flex_align_cross: center
widgets:
- label:
id: hp_label
text: "HP"
- obj:
width: SIZE_CONTENT
height: SIZE_CONTENT
layout:
type: flex
flex_flow: row
flex_align_cross: center
pad_column: 14
widgets:
- label:
id: level_label
text: "LEVEL"
- bar:
id: xp_bar
width: 140
height: 18
min_value: 0
max_value: 100
radius: 0
pad_all: 3
border_width: 2
border_color: ${pip_green}
bg_opa: TRANSP
indicator:
radius: 0
bg_color: ${pip_green}
- label:
id: ap_label
text: "AP"
pages: pages:
# 1: clock # STAT: weekday, date, weather, name day | clock
- id: main_page - id: main_page
on_load:
- script.execute:
id: select_tab
tab: 0
- script.execute: update_clock
- script.execute: update_data
widgets:
- label:
align: TOP_MID
y: 68
text: "STATUS"
- label:
id: weekday_label
x: 40
y: 108
pad_left: 8
pad_right: 8
bg_color: ${pip_green}
bg_opa: COVER
text_color: ${pip_bg}
text_font: font_big
text: "--"
- label:
id: date_label
x: 40
y: 164
text_font: font_big
text: ""
- label:
id: stat_icon
x: 36
y: 222
text_font: font_weather
text: ""
- label:
id: stat_temp
x: 124
y: 236
text_font: font_big
text: "--"
- label:
id: nameday_label
x: 40
y: 320
width: 380
long_mode: WRAP
text_color: ${pip_dim}
text: ""
- obj:
x: 470
y: 104
width: 290
height: 316
border_width: 3
border_color: ${pip_green}
widgets: widgets:
- label: - label:
id: clock_label id: clock_label
align: CENTER align: CENTER
y: -32
text_font: font_clock text_font: font_clock
text: "--:--" text_align: CENTER
text_line_space: -16
text: "--\n--"
# 2: status (shown until Home Assistant connects) # DATA: weather from Home Assistant as a Pip-Boy list
- id: data_page
on_load:
- script.execute:
id: select_tab
tab: 1
- script.execute: update_data
widgets:
- label:
align: TOP_MID
y: 68
text: "WEATHER"
- label:
x: 16
y: 106
width: 758
text_align: RIGHT
text_font: font_small
text_color: ${pip_dim}
text: "VALUE"
- obj:
x: 16
y: 130
width: 768
height: SIZE_CONTENT
layout:
type: flex
flex_flow: column
widgets:
- !include {file: common/pipboy_row.yaml, vars: {row: row_temp, name: TEMPERATURE, idx: 0}}
- !include {file: common/pipboy_row.yaml, vars: {row: row_cond, name: CONDITIONS, idx: 1}}
- !include {file: common/pipboy_row.yaml, vars: {row: row_hum, name: HUMIDITY, idx: 2}}
- !include {file: common/pipboy_row.yaml, vars: {row: row_press, name: PRESSURE, idx: 3}}
- !include {file: common/pipboy_row.yaml, vars: {row: row_wind, name: WIND, idx: 4}}
# MAP: baked map (no images over the native API), live person markers
- id: map_page
on_load:
- script.execute:
id: select_tab
tab: 2
- script.execute: update_map
widgets:
- label:
align: TOP_MID
y: 68
text: "LOCAL MAP"
- image:
src: pipboy_map
x: 16
y: ${map_y}
# home: square in a square, centre of the map
- obj:
x: 391 # 16 + map_w / 2 - 9
y: 253 # map_y + map_h / 2 - 9
width: 18
height: 18
border_width: 2
border_color: ${pip_green}
widgets:
- obj:
align: CENTER
width: 6
height: 6
bg_color: ${pip_green}
bg_opa: COVER
# ring + name; the second one has the name on the left so both stay readable at home
- obj:
id: marker_romanko
hidden: true
width: SIZE_CONTENT
height: SIZE_CONTENT
layout:
type: flex
flex_flow: ROW
flex_align_cross: center
pad_column: 6
widgets:
- obj:
width: 14
height: 14
radius: 7
border_width: 2
border_color: ${pip_green}
- label:
text_font: font_small
text: "Romanko"
- obj:
id: marker_janko
hidden: true
width: SIZE_CONTENT
height: SIZE_CONTENT
layout:
type: flex
flex_flow: ROW_REVERSE
flex_align_cross: center
pad_column: 6
widgets:
- obj:
width: 14
height: 14
radius: 7
border_width: 2
border_color: ${pip_green}
- label:
text_font: font_small
text: "Janko"
- label:
x: 26
y: 392 # map_y + map_h - 28
text_font: font_small
text_color: ${pip_dim}
text: "© OpenStreetMap"
- label:
x: 16
y: 388
width: 758
text_align: RIGHT
text: "${map_name}"
# SYS: status (shown until Home Assistant connects)
- id: status_page - id: status_page
on_load: on_load:
- script.execute:
id: select_tab
tab: 3
- script.execute: update_status - script.execute: update_status
widgets: widgets:
- label:
align: TOP_MID
y: 68
text: "SYSTEM"
- image: - image:
src: esphome_logo src: esphome_logo
align: TOP_MID align: TOP_MID
y: 16 y: 104
- label: - label:
align: TOP_MID align: TOP_MID
y: 140 y: 196
text_font: font_title text_font: font_title
text_color: 0xFFFFFF
text: "${name}" text: "${name}"
- obj: - obj:
id: status_lines id: status_lines
x: 60 x: 60
y: 196 y: 252
width: 700 width: 700
height: SIZE_CONTENT height: SIZE_CONTENT
bg_opa: TRANSP
border_width: 0
pad_all: 0
scrollbar_mode: "OFF" scrollbar_mode: "OFF"
layout: layout:
type: flex type: flex
+940
View File
@@ -0,0 +1,940 @@
# Hardware: M5Stack Core2 (AXP192) on the Faces Bottom II (600 mAh battery) with the QWERTY keyboard face
# Pinout:
# GPIO2 M-Bus (Core G15 position) -> faces_leds (light esp32_rmt_led_strip), Faces base SK6812 x10;
# also the Core2 speaker DOUT (NS4168), so no speaker while the LEDs are used
# GPIO5 -> display_tft (display mipi_spi cs_pin)
# GPIO15 -> display_tft (display mipi_spi dc_pin)
# GPIO18 -> spi_bus (spi clk_pin)
# GPIO19 M-Bus (modded NSS, stock G33) -> lora (sx127x cs_pin), LoRa868 module (Ra-01H, SX1276)
# GPIO21 -> i2c_main (i2c sda), M-Bus SDA
# GPIO22 -> i2c_main (i2c scl), M-Bus SCL
# GPIO23 -> spi_bus (spi mosi_pin)
# GPIO26 M-Bus, Port B -> lora (sx127x rst_pin)
# GPIO27 M-Bus (modded DIO1) -> LoRa868 DIO1, unused (sx127x has no dio1)
# GPIO35 M-Bus (modded DIO0, stock G36) -> lora (sx127x dio0_pin)
# GPIO38 -> spi_bus (spi miso_pin)
# GPIO39 -> touch_lcd (touchscreen ft63x6 interrupt_pin)
# AXP192 GPIO4 -> LCD reset (on_boot)
# Grove (free):
# Port A red (Core2) I2C GPIO32 SDA, GPIO33 SCL -> can_bus (esp32_can rx GPIO32, tx GPIO33), TJA1050 module
# Port B black (base) GPIO GPIO26 out/DAC, GPIO36 in/ADC (input only); GPIO26 taken by the LoRa868 RST
# Port C blue (base) UART GPIO13 RX, GPIO14 TX -> i2c_port_c (i2c scl GPIO13, sda GPIO14)
# Touch buttons (below the LCD, raw y 240-280): A prev page, B keyboard page, C next page
# I2C:
# 0x08 keyboard (m5stack_keyboard), Faces QWERTY
# 0x34 pmu_axp (axp192)
# 0x38 touch_lcd (touchscreen ft63x6)
# 0x51 rtc_time (time bm8563)
# MPU6886 IMU (0x68) is cut off while the Faces base is attached
# I2C Port C:
# 0x3C oled (display ssd1306_i2c), Unit OLED SH1107
# 0x3E unit_lcd (display m5stack_st7789v2), Unit LCD, firmware 0.3
# 0x33 thermal (mlx90640), MLX90640 32x24 thermal camera
# 0x5F cardkb (m5stack_keyboard), CardKB (unplugged for now, its warning at boot is expected)
substitutions:
device: m5core2
name: M5Core2
area: DEV
comment: Core2 + Faces keyboard
esphome:
name: mcu-${device}
friendly_name: ${name}
area: ${area}
comment: ${comment}
on_boot:
# After the I2C bus, before the display: LCD power (LDO2), backlight (DC3), M-Bus 5V boost (EXTEN)
# for the Faces base, then the LCD reset pulse on AXP GPIO4 (open drain), as M5Core2's AXP192::begin
- priority: 900
then:
- lambda: |-
auto *axp = id(pmu_axp);
axp->writeRegister(0x27, (3300 - 700) / 25); // DC3 (LCD backlight) 3.3 V
axp->writeRegister(0x28, (axp->readRegister(0x28) & 0x0F) | 0xF0); // LDO2 3.3 V
axp->writeRegister(0x12, axp->readRegister(0x12) | 0x46); // EXTEN, LDO2, DC3
axp->writeRegister(0x95, (axp->readRegister(0x95) & 0x72) | 0x84); // GPIO4 output
axp->writeRegister(0x96, axp->readRegister(0x96) & ~0x02);
delay(100);
axp->writeRegister(0x96, axp->readRegister(0x96) | 0x02);
delay(100);
- priority: -100
then:
# the m5stack component sets these in the AXP2101 layout: 4.1 V, 360 mA, end at 10 %
- lambda: id(pmu_axp)->writeRegister(0x33, 0x83);
# The SH1107 once stuck showing noise (even after a power cycle) with ESPHome's init alone;
# M5GFX's settings that ESPHome lacks or sets otherwise brought it back, kept as insurance:
# end read-modify-write, POR clock, SH1107 precharge, VCOMH, DC-DC, RAM content, on
- lambda: |-
for (uint8_t c : {0xEE, 0xD5, 0x50, 0xD9, 0x20, 0xDB, 0x35, 0xAD, 0x8B, 0xA4, 0xAF})
id(oled).write_byte(0x00, c);
- bm8563.read_time:
- lvgl.page.show: {id: status_page, lvgl_id: lvgl_main}
esp32:
variant: esp32
flash_size: 16MB
framework:
type: esp-idf
advanced:
flash_chip: generic
minimum_chip_revision: 3.0
sram1_as_iram: true
psram:
mode: quad
speed: 80MHz
packages:
common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml
status_led: !include
file: common/status_led.yaml
vars:
light_id: faces_leds
external_components:
- source: github://m5stack/esphome-yaml
components: [axp192]
refresh: 1h
- source: github://randybb/esphome-components
components: [m5stack_keyboard, m5stack_st7789v2, meshtastic, mlx90640]
refresh: 0s
# MLX90640 on Port C; settings changed at runtime are saved on the device
mlx90640:
id: thermal
i2c_id: i2c_port_c
web_ui: false # the heatmap page at /thermal would pull in web_server_base
refresh_rate: 4Hz
update_interval: 10s
min_temperature:
name: Thermal Min
max_temperature:
name: Thermal Max
mean_temperature:
name: Thermal Mean
center_temperature:
name: Thermal Center
ambient_temperature:
name: Thermal Sensor Die
frame_rate:
name: Thermal Frame Rate
i2c_errors:
name: Thermal I2C Errors
camera:
name: Thermal Camera
resolution: 320x240
api:
# status page until Home Assistant connects (log viewers don't subscribe to states)
# Home Assistant has subscribed and received every state
on_client_synced:
- lvgl.page.show: {id: main_page, lvgl_id: lvgl_main}
on_client_disconnected:
- if:
condition:
not:
api.connected:
state_subscription_only: true
then:
- lvgl.page.show: {id: status_page, lvgl_id: lvgl_main}
canbus:
- platform: esp32_can
id: can_bus
rx_pin: 32
tx_pin: 33
can_id: 5
bit_rate: 500kbps
canopen:
- id: can_open
canbus_id: can_bus
node_id: 5
i2c:
- id: i2c_main
sda: 21
scl: 22
scan: true
# Port C (blue) used as a second I2C bus, Grove yellow = SCL, white = SDA
- id: i2c_port_c
sda: 14
scl: 13
frequency: 400kHz
scan: true
spi:
id: spi_bus
clk_pin: 18
mosi_pin: 23
miso_pin: 38
# LoRa868 module on Meshtastic EU LongFast, RSSI/SNR of every packet (relays included)
sx127x:
id: lora
spi_id: spi_bus
cs_pin: GPIO19
rst_pin: GPIO26
dio0_pin: GPIO35 # modded, stock G36
modulation: LORA
frequency: 869525000 # Meshtastic EU_868 LongFast, slot 0
bandwidth: 250_0kHz
spreading_factor: 11
coding_rate: CR_4_5
preamble_size: 16
sync_value: 0x2B # Meshtastic
crc_enable: true
pa_pin: BOOST
pa_power: 14
on_packet:
- lambda: |-
id(lora_count) += 1;
id(lora_rssi).publish_state(rssi);
id(lora_snr).publish_state(snr);
- lvgl.label.update:
id: lora_stats
text: !lambda |-
return str_sprintf("%.0f dBm\n%.1f dB\n%u", id(lora_rssi).state, id(lora_snr).state, id(lora_count));
# Typed lines go to the LongFast channel, received texts to the LoRa page
meshtastic:
id: mesh
long_name: randy_m5c2
short_name: M5C2
on_message:
- text_sensor.template.publish:
id: lora_packet
state: !lambda 'return from_name + ": " + text;'
- lvgl.label.update:
id: lora_last
text: !lambda 'return from_name + ": " + text;'
# Example, off: randy_home's Meshtastic integration already gives HA every node. Without such
# a node this sends each node update to HA, an automation with device_tracker.see maps them.
# on_node:
# - homeassistant.event:
# event: esphome.meshtastic_node
# data:
# node: !lambda return node.id();
# long_name: !lambda return node.long_name;
# hops: !lambda 'return node.hops < 0 ? std::string() : to_string(node.hops);'
# rssi: !lambda return meshtastic::num(node.rssi, 0);
# latitude: !lambda return meshtastic::num(node.latitude, 7);
# longitude: !lambda return meshtastic::num(node.longitude, 7);
# altitude: !lambda return meshtastic::num(node.altitude, 0);
# battery_level: !lambda return meshtastic::num(node.battery_level, 0);
# voltage: !lambda return meshtastic::num(node.voltage, 2);
# temperature: !lambda return meshtastic::num(node.temperature, 1);
globals:
- id: lora_count
type: uint32_t
initial_value: "0"
axp192:
id: pmu_axp
i2c_id: i2c_main
m5stack_keyboard:
- id: keyboard
i2c_id: i2c_main
- id: cardkb
i2c_id: i2c_port_c
address: 0x5F
display:
- platform: mipi_spi
id: display_tft
model: M5CORE2
spi_id: spi_bus
auto_clear_enabled: false
update_interval: never
- platform: ssd1306_i2c
id: oled
i2c_id: i2c_port_c
model: "SH1107 128x64"
address: 0x3C
rotation: 90
offset_x: 32 # the 64 visible columns sit in the middle of the SH1107 RAM
update_interval: 1s
lambda: |-
auto now = id(ha_time).now();
it.strftime(it.get_width() / 2, 0, id(font_title), TextAlign::TOP_CENTER, "%H:%M:%S", now);
it.printf(0, it.get_height(), id(font_status), TextAlign::BOTTOM_LEFT, "%.2f V %.0f%%", id(battery_voltage).state,
id(battery_level).state);
- platform: m5stack_st7789v2
id: unit_lcd
i2c_id: i2c_port_c
brightness: 60%
update_interval: 10s # only reconnects a lost unit, LVGL flushes drive the transfer
auto_clear_enabled: false
touchscreen:
- platform: ft63x6
id: touch_lcd
display: display_tft
i2c_id: i2c_main
interrupt_pin: 39
light:
- platform: esp32_rmt_led_strip
id: faces_leds
name: LED Strip
pin: GPIO2
num_leds: 10
chipset: SK6812
channel_colors: GRB
restore_mode: ALWAYS_OFF
effects:
- addressable_rainbow:
- addressable_scan:
binary_sensor:
- platform: template
id: battery_charging
name: Battery Charging
device_class: battery_charging
# the three touch buttons lie below the 240 px of the LCD, only in raw coordinates
- platform: touchscreen
id: button_a
use_raw: true
x_min: 0
x_max: 106
y_min: 240
y_max: 300
on_press:
- lvgl.page.previous: {lvgl_id: lvgl_main}
- platform: touchscreen
id: button_b
use_raw: true
x_min: 107
x_max: 213
y_min: 240
y_max: 300
on_press:
- lvgl.page.show: {id: main_page, lvgl_id: lvgl_main}
- platform: touchscreen
id: button_c
use_raw: true
x_min: 214
x_max: 320
y_min: 240
y_max: 300
on_press:
- lvgl.page.next: {lvgl_id: lvgl_main}
# AXP192 ADCs read directly, the m5stack component decodes them as an AXP2101
sensor:
- platform: template
id: battery_voltage
name: Battery Voltage
unit_of_measurement: V
device_class: voltage
accuracy_decimals: 2
- platform: template
id: battery_level
name: Battery Level
unit_of_measurement: "%"
device_class: battery
accuracy_decimals: 0
- platform: template
id: battery_current
name: Battery Current # + charging, - discharging
unit_of_measurement: mA
device_class: current
accuracy_decimals: 0
- platform: template
id: vbus_voltage
internal: true
- platform: template
id: vbus_current
internal: true
- platform: template
id: acin_voltage
internal: true
- platform: template
id: acin_current
internal: true
- platform: template
id: aps_voltage
internal: true
- platform: template
id: pmu_temperature
name: PMU Temperature
unit_of_measurement: °C
device_class: temperature
accuracy_decimals: 1
- platform: template
id: lora_rssi
name: LoRa RSSI
unit_of_measurement: dBm
device_class: signal_strength
accuracy_decimals: 0
- platform: template
id: lora_snr
name: LoRa SNR
unit_of_measurement: dB
accuracy_decimals: 1
# RTC holds the time until Home Assistant connects, HA's time is written back on every sync
time:
- platform: bm8563
id: rtc_time
i2c_id: i2c_main
update_interval: never
- id: !extend ha_time
on_time_sync:
- bm8563.write_time:
# Typed line in the text area, Enter (CR LF) sends it, Backspace deletes
key_collector:
- id: line_collector
source_id: keyboard
end_keys: "\r\n"
back_keys: "\b"
min_length: 1 # the LF after CR is an empty line
max_length: 64
on_progress: &line_progress
- lvgl.textarea.update:
id: input_text
text: !lambda return x;
on_result: &line_result
- logger.log:
format: "Line: %s"
args: [x.c_str()]
- lvgl.label.update:
id: last_line
text: !lambda return x;
- lvgl.label.update:
id: unit_last_line
text: !lambda return x;
- lvgl.textarea.update:
id: input_text
text: ""
- text_sensor.template.publish:
id: keyboard_line
state: !lambda return x;
- meshtastic.send_text: !lambda return x;
- id: cardkb_collector
source_id: cardkb
end_keys: "\r\n"
back_keys: "\b"
min_length: 1
max_length: 64
on_progress: *line_progress
on_result: *line_result
select:
- platform: mlx90640
refresh_rate:
name: Thermal Refresh Rate
palette:
name: Thermal Palette
number:
- platform: mlx90640
emissivity:
name: Thermal Emissivity
range_min:
name: Thermal Range Min
range_max:
name: Thermal Range Max
switch:
- platform: mlx90640
auto_range:
name: Thermal Auto Range
mirror:
name: Thermal Mirror
- platform: template
name: Unit LCD Invert
icon: mdi:invert-colors
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
entity_category: config
on_turn_on:
- lambda: id(unit_lcd).set_invert(true);
on_turn_off:
- lambda: id(unit_lcd).set_invert(false);
- platform: template
name: Unit LCD Sleep
icon: mdi:sleep
optimistic: true
restore_mode: ALWAYS_OFF
on_turn_on:
- lambda: id(unit_lcd).set_sleep(true);
on_turn_off:
- lambda: id(unit_lcd).set_sleep(false);
text_sensor:
- platform: template
id: keyboard_line
name: Keyboard Line
- platform: template
id: lora_packet
name: Meshtastic Message
script:
# same as mcu-lvgl
- id: update_status
then:
- lambda: |-
// same colors as the other status screens: ok green, waiting orange, details gray
static const uint32_t OK = 0x4DD966, WAIT = 0xFFB300;
auto set = [](lv_obj_t *label, const std::string &text, uint32_t color) {
lv_label_set_text(label, text.c_str());
lv_obj_set_style_text_color(label, lv_color_hex(color), LV_PART_MAIN);
};
const bool wifi_ok = wifi::global_wifi_component->is_connected();
set(id(status_wifi),
wifi_ok ? str_sprintf("WiFi: connected (%d dBm)", wifi::global_wifi_component->wifi_rssi())
: std::string("WiFi: connecting..."),
wifi_ok ? OK : WAIT);
// IPv6 first (skip link-local), then IPv4
std::string ips;
if (wifi_ok) {
char buf[network::IP_ADDRESS_BUFFER_SIZE];
for (bool v6 : {true, false}) {
for (auto &ip : wifi::global_wifi_component->get_ip_addresses()) {
if (!ip.is_set() || ip.is_ip6() != v6)
continue;
ip.str_to(buf);
if (v6 && strncmp(buf, "fe80", 4) == 0)
continue;
if (!ips.empty())
ips += "\n";
ips += buf;
}
}
}
lv_label_set_text(id(status_ips), ips.c_str());
if (ips.empty())
lv_obj_add_flag(id(status_ips), LV_OBJ_FLAG_HIDDEN);
else
lv_obj_remove_flag(id(status_ips), LV_OBJ_FLAG_HIDDEN);
const bool api_ok = api::global_api_server->is_connected();
set(id(status_ha), api_ok ? "Home Assistant: connected" : "Home Assistant: waiting...",
api_ok ? OK : WAIT);
const uint32_t up = millis() / 1000;
lv_label_set_text(id(status_footer),
str_sprintf("ESPHome %s · up %ud %02u:%02u:%02u", ESPHOME_VERSION, up / 86400,
(up / 3600) % 24, (up / 60) % 60, up % 60).c_str());
- id: update_axp
then:
- lvgl.label.update:
id: axp_values
text: !lambda |-
return str_sprintf("%.2f V %.0f %%\n%+.0f mA%s\n%.2f V %.0f mA\n%.2f V %.0f mA\n%.2f V\n%.1f °C",
id(battery_voltage).state, id(battery_level).state, id(battery_current).state,
id(battery_charging).state ? " charging" : "",
id(vbus_voltage).state, id(vbus_current).state,
id(acin_voltage).state, id(acin_current).state,
id(aps_voltage).state, id(pmu_temperature).state);
interval:
- interval: 5s
then:
- lambda: |-
auto *a = id(pmu_axp);
auto r = [a](uint8_t reg) { return a->readRegister(reg) & 0xFF; };
auto adc12 = [&](uint8_t h) { return (r(h) << 4) | (r(h + 1) & 0x0F); };
auto adc13 = [&](uint8_t h) { return (r(h) << 5) | (r(h + 1) & 0x1F); };
const float bat = adc12(0x78) * 1.1f / 1000;
id(battery_voltage).publish_state(bat);
// ponytail: linear 3.3-4.1 V, a discharge curve if the percentage matters
id(battery_level).publish_state(clamp((bat - 3.3f) / 0.8f * 100, 0.0f, 100.0f));
id(battery_current).publish_state(adc13(0x7A) * 0.5f - adc13(0x7C) * 0.5f);
id(vbus_voltage).publish_state(adc12(0x5A) * 1.7f / 1000);
id(vbus_current).publish_state(adc12(0x5C) * 0.375f);
id(acin_voltage).publish_state(adc12(0x56) * 1.7f / 1000);
id(acin_current).publish_state(adc12(0x58) * 0.625f);
id(aps_voltage).publish_state(adc12(0x7E) * 1.4f / 1000);
id(pmu_temperature).publish_state(adc12(0x5E) * 0.1f - 144.7f);
id(battery_charging).publish_state(r(0x01) & 0x40);
# thermal page: the newest MLX90640 frame, 32x24 upscaled bilinear x8 with the iron palette
- interval: 125ms
then:
- if:
condition:
lvgl.page.is_showing: thermal_page
then:
- lambda: |-
static float px[32 * 24];
static uint32_t shown = 0;
static uint16_t palette[256];
static bool palette_ready = false;
if (!id(thermal).has_frame() || id(thermal).get_frame_count() == shown)
return;
shown = id(thermal).get_frame_count();
id(thermal).copy_display_frame(px);
if (!palette_ready) {
// iron: black, navy, magenta, orange, yellow, white
const float stop[][4] = {{0, 0, 0, 0}, {0.2f, 32, 0, 140}, {0.45f, 204, 0, 119},
{0.7f, 255, 140, 0}, {0.85f, 255, 215, 0}, {1, 255, 255, 255}};
for (int i = 0; i < 256; i++) {
const float t = i / 255.0f;
int k = 0;
while (k < 4 && t > stop[k + 1][0])
k++;
const float f = (t - stop[k][0]) / (stop[k + 1][0] - stop[k][0]);
auto mix = [&](int c) { return uint8_t(stop[k][c] + f * (stop[k + 1][c] - stop[k][c])); };
palette[i] = lv_color_to_u16(lv_color_make(mix(1), mix(2), mix(3)));
}
palette_ready = true;
}
float lo = px[0], hi = px[0];
for (float v : px) {
lo = std::min(lo, v);
hi = std::max(hi, v);
}
const float center = (px[11 * 32 + 15] + px[11 * 32 + 16] + px[12 * 32 + 15] + px[12 * 32 + 16]) / 4;
float a = lo, b = hi;
if (b - a < 2) { // flat scenes would show noise
a = (lo + hi) / 2 - 1;
b = a + 2;
}
const float k = 255 / (b - a);
lv_obj_t *canvas = id(thermal_canvas);
lv_draw_buf_t *buf = lv_canvas_get_draw_buf(canvas);
for (int y = 0; y < 192; y++) {
const float sy = std::clamp((y + 0.5f) / 8 - 0.5f, 0.0f, 23.0f);
const int y0 = int(sy), y1 = std::min(y0 + 1, 23);
const float fy = sy - y0;
auto *row = reinterpret_cast<uint16_t *>(buf->data + y * buf->header.stride);
for (int x = 0; x < 256; x++) {
const float sx = std::clamp((x + 0.5f) / 8 - 0.5f, 0.0f, 31.0f);
const int x0 = int(sx), x1 = std::min(x0 + 1, 31);
const float fx = sx - x0;
const float top = px[y0 * 32 + x0] + fx * (px[y0 * 32 + x1] - px[y0 * 32 + x0]);
const float bottom = px[y1 * 32 + x0] + fx * (px[y1 * 32 + x1] - px[y1 * 32 + x0]);
row[x] = palette[std::clamp(int((top + fy * (bottom - top) - a) * k), 0, 255)];
}
}
// crosshair on the center spot
const uint16_t white = lv_color_to_u16(lv_color_white());
for (int d = -6; d <= 6; d++) {
if (d > -2 && d < 2)
continue;
reinterpret_cast<uint16_t *>(buf->data + 96 * buf->header.stride)[128 + d] = white;
reinterpret_cast<uint16_t *>(buf->data + (96 + d) * buf->header.stride)[128] = white;
}
lv_obj_invalidate(canvas);
lv_label_set_text(id(thermal_max), str_sprintf("%.1f°", hi).c_str());
lv_label_set_text(id(thermal_center), str_sprintf("%.1f°", center).c_str());
lv_label_set_text(id(thermal_min), str_sprintf("%.1f°", lo).c_str());
- interval: 1s
then:
- lvgl.label.update:
id: unit_time
text: !lambda |-
auto now = id(ha_time).now();
return now.is_valid() ? now.strftime("%H:%M") : std::string("--:--");
- lvgl.bar.update:
id: unit_battery_bar
value: !lambda return id(battery_level).state;
- lvgl.label.update:
id: unit_battery
text: !lambda |-
return str_sprintf("%.2f V %.0f %%%s", id(battery_voltage).state, id(battery_level).state,
id(battery_charging).state ? " charging" : "");
- if:
condition:
lvgl.page.is_showing: status_page
then:
- script.execute: update_status
- if:
condition:
lvgl.page.is_showing: axp_page
then:
- script.execute: update_axp
image:
- platform: file
file: assets/images/made-for-esphome-white-on-black.svg
id: esphome_logo
resize: 280x83
type: RGB565
transparency: alpha_channel
font:
- file: "gfonts://Roboto"
id: font_title
size: 24
- file: "gfonts://Roboto"
id: font_status
size: 16
glyphs: "·°"
glyphsets: [GF_Latin_Kernel]
lvgl:
- id: lvgl_main
displays: display_tft
touchscreens: touch_lcd
buffer_size: 25%
log_level: WARN
bg_color: 0x000000
text_color: 0xFFFFFF
pages:
# 1: keyboard demo
- id: main_page
widgets:
- label:
align: TOP_MID
y: 6
text_font: font_title
text: ${name}
- textarea:
id: input_text
align: TOP_MID
y: 40
width: 300
height: 70
text_font: font_status
placeholder_text: Type on the keyboard...
- label:
align: TOP_LEFT
x: 10
y: 122
text_font: font_status
text: "Last line:"
- label:
id: last_line
align: TOP_LEFT
x: 90
y: 122
width: 220
long_mode: DOT
text_font: font_status
text: "-"
- slider:
id: demo_slider
align: BOTTOM_LEFT
x: 20
y: -40
width: 170
on_value:
- lvgl.arc.update:
id: demo_arc
value: !lambda return x;
- arc:
id: demo_arc
align: BOTTOM_RIGHT
x: -15
y: -15
width: 100
height: 100
adjustable: false
# 2: AXP192 diagnostics
- id: axp_page
on_load:
- script.execute: update_axp
widgets:
- label:
align: TOP_MID
y: 6
text_font: font_title
text: AXP192
- label:
x: 16
y: 44
text_font: font_status
text_color: 0x8C8C8C
text: "Battery\nCurrent\nUSB (VBUS)\nM-Bus 5V (ACIN)\nAPS\nTemperature"
- label:
id: axp_values
x: 170
y: 44
text_font: font_status
text: ""
# 3: LoRa, last received Meshtastic packet
- id: lora_page
widgets:
- label:
align: TOP_MID
y: 6
text_font: font_title
text: Meshtastic LongFast
- label:
x: 16
y: 44
text_font: font_status
text_color: 0x8C8C8C
text: "RSSI\nSNR\nPackets"
- label:
id: lora_stats
x: 170
y: 44
text_font: font_status
text: "-\n-\n0"
- label:
x: 16
y: 120
text_font: font_status
text_color: 0x8C8C8C
text: "Last message:"
- label:
id: lora_last
x: 16
y: 142
width: 288
long_mode: WRAP
text_font: font_status
text: "-"
# 4: MLX90640 thermal image, drawn by the 125 ms interval
- id: thermal_page
widgets:
- canvas:
id: thermal_canvas
x: 0
y: 24
width: 256
height: 192
- label:
x: 262
y: 24
text_font: font_status
text_color: 0x8C8C8C
text: Max
- label:
id: thermal_max
x: 262
y: 44
text_font: font_status
text_color: 0xFF6040
text: "-"
- label:
x: 262
y: 98
text_font: font_status
text_color: 0x8C8C8C
text: "Center"
- label:
id: thermal_center
x: 262
y: 118
text_font: font_status
text: "-"
- label:
x: 262
y: 172
text_font: font_status
text_color: 0x8C8C8C
text: Min
- label:
id: thermal_min
x: 262
y: 192
text_font: font_status
text_color: 0x40A0FF
text: "-"
- label:
align: TOP_MID
x: -32
y: 2
text_font: font_status
text: MLX90640
# 5: status (shown until Home Assistant connects)
- id: status_page
on_load:
- script.execute: update_status
widgets:
- image:
src: esphome_logo
align: TOP_MID
y: 8
- label:
align: TOP_MID
y: 96
text_font: font_title
text: "${name}"
- obj:
x: 16
y: 132
width: 288
height: SIZE_CONTENT
bg_opa: TRANSP
border_width: 0
pad_all: 0
scrollbar_mode: "OFF"
layout:
type: flex
flex_flow: column
pad_row: 4
widgets:
- label:
id: status_wifi
text_font: font_status
text: ""
- label:
id: status_ips
text_font: font_status
text_color: 0x8C8C8C
pad_left: 20
text: ""
- label:
id: status_ha
text_font: font_status
text: ""
- label:
id: status_footer
text_font: font_status
text_color: 0x8C8C8C
text: ""
# Unit LCD on Port C, rotated by LVGL (the display can't rotate under LVGL)
- id: lvgl_unit
displays: unit_lcd
rotation: 90
buffer_size: 100%
bg_color: 0x101830
text_color: 0xFFFFFF
widgets:
- label:
x: 6
y: 4
text_font: font_title
text_color: 0xFFB300
text: ${name}
- label:
id: unit_time
align: TOP_RIGHT
x: -6
y: 4
text_font: font_title
text: "--:--"
- label:
x: 6
y: 44
text_font: font_status
text_color: 0x8C8C8C
text: "Last line:"
- label:
id: unit_last_line
x: 6
y: 64
width: 228
long_mode: DOT
text_font: font_status
text: "-"
- bar:
id: unit_battery_bar
x: 6
y: 94
width: 228
height: 10
min_value: 0
max_value: 100
- label:
id: unit_battery
x: 6
y: 110
text_font: font_status
text: ""
+2 -15
View File
@@ -124,14 +124,8 @@ wifi:
- component.update: m5paper_display - component.update: m5paper_display
api: api:
# status screen until Home Assistant connects (log viewers don't subscribe to states) # status screen until Home Assistant has subscribed and received every state (log viewers don't subscribe)
on_client_connected: on_client_synced:
- delay: 2s
- if:
condition:
api.connected:
state_subscription_only: true
then:
- lambda: id(show_status) = false; - lambda: id(show_status) = false;
- if: - if:
condition: condition:
@@ -139,13 +133,6 @@ api:
then: then:
- component.update: m5paper_display - component.update: m5paper_display
# outside the battery cycle (power button, USB) WiFi is up anyway: always refresh # outside the battery cycle (power button, USB) WiFi is up anyway: always refresh
- if:
condition:
and:
- lambda: return !id(calendar_page);
- api.connected:
state_subscription_only: true
then:
- script.execute: fetch_events - script.execute: fetch_events
on_client_disconnected: on_client_disconnected:
- if: - if:
+340
View File
@@ -0,0 +1,340 @@
---
# 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 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)
# GPIO37 button A -> Button A (binary_sensor gpio) (inverted)
# GPIO39 button B -> Button B (binary_sensor gpio) (inverted)
# I2C:
# 0x34 pmu_axp (axp192)
# 0x51 rtc_time (time bm8563)
# 0x68 imu (sensor mpu6886)
# 0x54 joyc (m5stack_mini_joyc), Hat Mini JoyC
# 0x5F cardkb (m5stack_keyboard), Hat CardKB
# Hat CardKB: its SDA/SCL pull-ups are on 5 V (measured, the ATmega itself takes 3V3 from the hat header, bridged
# to 5 V), so G0/G26 sit at 5 V, above the ESP32's VDD + 0.3 V; works, a level shifter or removing those pull-ups
# would fix it. Mini JoyC (STM32F030 PA9/PA10) is 5 V tolerant.
# GPIO13/15 LCD CLK/MOSI, GPIO5 CS, GPIO23 DC, GPIO18 RST -> display_tft (ST7789V2 135x240)
# AXP192: LDO2 LCD backlight, LDO3 LCD logic, EXTEN 5 V for the hat header and Grove
substitutions:
device: m5stickc-plus
name: M5StickC Plus
area: DEV
comment: CANopen keypad + joystick
esphome:
name: mcu-${device}
friendly_name: ${name}
area: ${area}
comment: ${comment}
on_boot:
# AXP192 EXTEN (reg 0x10 bit 2) = 5 V for the hat header and Grove (CardKB, CAN unit)
- priority: 800
then:
- lambda: id(set_exten)->execute(true);
- then:
- output.turn_on: lcd_logic
- lambda: |-
id(cardkb).add_on_key_callback([](uint8_t key) {
id(key_code).publish_state(key);
float n = id(key_count).state; // NaN before the first key
uint32_t count = std::isnan(n) ? 1 : ((uint32_t) n + 1) % 65535;
id(key_count).publish_state(count);
id(key_event).publish_state((count % 255) * 256 + key); // one field: count (high byte) + key (low byte)
id(display_tft).update();
});
esp32:
board: m5stick-c
toolchain: esp-idf
framework:
type: esp-idf
external_components:
- source: github://m5stack/esphome-yaml
components: [axp192]
refresh: 1h
- source: github://mrk-its/esphome-canopen@canopen_entities
components: [canopen_entities]
refresh: 1h
- source: github://randybb/esphome-components
components: [m5stack_keyboard, m5stack_mini_joyc]
refresh: 1h
packages:
common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml
i2c:
- id: i2c_axp
sda: 21
scl: 22
- id: i2c_hat
sda: 0
scl: 26
axp192:
id: pmu_axp
i2c_id: i2c_axp
m5stack_keyboard:
- id: cardkb
i2c_id: i2c_hat
address: 0x5F
m5stack_mini_joyc:
- id: joyc
i2c_id: i2c_hat
# hat mounted turned 90° right of the display: X = hat Y, Y = -hat X
x:
id: joy_y
name: Joystick Y
filters:
- multiply: -1
- delta: 8
y:
id: joy_x
name: Joystick X
filters:
- delta: 8
button:
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: 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
canbus_id: can_bus
node_id: 4
# CardKB sends only the press: a consumer reacts to a change of key_count and reads the key from key_code (same
# frame), or watches key_event alone (count % 255 << 8 | key). Joystick -512..511 as UINT16 = value + 512.
canopen_entities:
canopen_id: can_open
entities:
- {id: key_code, index: 1, tpdo: 0, size: 1}
- {id: key_count, index: 2, tpdo: 0, size: 2}
- {id: key_event, index: 3, tpdo: 0, size: 2}
- {id: joy_button, index: 4, tpdo: 0}
- {id: button_a, index: 5, tpdo: 0}
- {id: button_b, index: 6, tpdo: 0}
- {id: joy_x, index: 7, tpdo: 1, size: 2, min_value: -512, max_value: 65022}
- {id: joy_y, index: 8, tpdo: 1, size: 2, min_value: -512, max_value: 65022}
- {id: led, index: 9, tpdo: 1}
- {id: joy_led, index: 10, tpdo: 1, caps: [on_off, brightness]}
time:
- platform: bm8563
id: rtc_time
i2c_id: i2c_axp
# keep the RTC in sync with Home Assistant, for the time without Wi-Fi
- id: !extend ha_time
on_time_sync:
- bm8563.write_time: rtc_time
sensor:
- platform: axp192
id: pmu_sensor
update_interval: 10s
battery_level:
id: battery_level
name: Battery Level
battery_voltage:
name: Battery Voltage
battery_charging:
id: battery_charging
name: Battery Charging
internal_temperature:
name: PMU Temperature
- platform: mpu6886
id: imu
i2c_id: i2c_axp
address: 0x68
update_interval: 1s
accel_x:
name: Accel X
accel_y:
name: Accel Y
accel_z:
name: Accel Z
gyro_x:
name: Gyro X
gyro_y:
name: Gyro Y
gyro_z:
name: Gyro Z
temperature:
name: IMU Temperature
- platform: template
id: key_code
name: Key Code
accuracy_decimals: 0
update_interval: never
- platform: template
id: key_count
name: Key Count
accuracy_decimals: 0
update_interval: never
- platform: template
id: key_event
name: Key Event
accuracy_decimals: 0
update_interval: never
binary_sensor:
- platform: gpio
id: button_a
name: Button A
pin:
number: 37
inverted: true
- platform: gpio
id: button_b
name: Button B
pin:
number: 39
inverted: true
output:
- platform: axp192
type: range
channel: DLDO2
id: lcd_backlight_out
min_voltage: 2500
max_voltage: 3300
- platform: axp192
channel: DLDO3
id: lcd_logic
voltage: 3000
- platform: gpio
id: led_out
pin:
number: 10
inverted: true
light:
- platform: monochromatic
id: lcd_backlight
name: LCD Backlight
entity_category: config
output: lcd_backlight_out
restore_mode: ALWAYS_ON
- platform: binary
id: led
name: LED
output: led_out
- platform: m5stack_mini_joyc
id: joy_led
name: Joystick LED
mini_joyc_id: joyc
script:
# AXP192 EXTEN (reg 0x10 bit 2): 5 V out on the hat header and Grove
- id: set_exten
parameters:
enable: bool
then:
- lambda: |-
uint8_t reg = 0x10, v;
if (id(i2c_axp).write_readv(0x34, &reg, 1, &v, 1) != i2c::ERROR_OK)
return;
uint8_t d[2] = {reg, (uint8_t) (enable ? v | 0x04 : v & ~0x04)};
id(i2c_axp).write(0x34, d, 2);
button:
# restarts what runs from the 5 V out (CardKB bridged to 5 V, the CAN unit); the Mini JoyC runs from 3V3
- platform: template
name: Peripheral Power Cycle
entity_category: config
on_press:
- script.execute: {id: set_exten, enable: false}
- delay: 500ms
- script.execute: {id: set_exten, enable: true}
spi:
clk_pin: 13
mosi_pin: 15
font:
- file: "gfonts://Roboto"
id: font_key
size: 48
- file: "gfonts://Roboto"
id: font_status
size: 14
display:
- platform: mipi_spi
model: ST7789V
id: display_tft
dimensions:
width: 135
height: 240
offset_width: 52
offset_height: 40
invert_colors: true
rotation: 270 # landscape, turned left
cs_pin: 5
dc_pin: 23
reset_pin: 18
update_interval: 200ms
lambda: |-
// status line top left: battery (+ = charging), Wi-Fi RSSI, API (green = a client is connected)
it.printf(0, 0, id(font_status), "%.0f%%%s", id(battery_level).state, id(battery_charging).state ? "+" : "");
it.printf(40, 0, id(font_status), "%.0f", id(wifi_signal_sensor).state);
it.print(75, 0, id(font_status), api::global_api_server->is_connected() ? Color(0, 255, 0) : Color(255, 0, 0), "API");
// landscape 240x135: joystick dot in a 135x135 square on the right
it.rectangle(105, 0, 135, 135, Color(64, 64, 64));
if (!std::isnan(id(joy_x).state) && !std::isnan(id(joy_y).state)) {
int x = 172 + id(joy_x).state * 60 / 512, y = 67 - id(joy_y).state * 60 / 512;
it.filled_circle(x, y, 6, id(joy_button).state ? Color(255, 0, 0) : Color(255, 255, 255));
}
// last key (CardKB: specials as names, unknown codes as hex)
if (std::isnan(id(key_code).state))
return;
uint8_t k = id(key_code).state;
const char *s = nullptr;
char c[5];
switch (k) {
case 0x08: s = "BS"; break;
case 0x09: s = "Tab"; break;
case 0x0D: s = "Ent"; break;
case 0x1B: s = "Esc"; break;
case 0x20: s = "Spc"; break;
case 0x7F: s = "Del"; break;
case 0xB4: s = "Lt"; break;
case 0xB5: s = "Up"; break;
case 0xB6: s = "Dn"; break;
case 0xB7: s = "Rt"; break;
default:
if (k > 0x20 && k < 0x7F) {
c[0] = (char) k;
c[1] = 0;
} else {
snprintf(c, sizeof(c), "%02X", k);
}
s = c;
}
it.print(52, 67, id(font_key), TextAlign::CENTER, s); // last key on the left
+1
View File
@@ -32,6 +32,7 @@ esphome:
- id: mains - id: mains
name: Mains name: Mains
area_id: local_area area_id: local_area
relation: child
esp32: esp32:
variant: esp32 variant: esp32
+50 -4
View File
@@ -1,9 +1,13 @@
--- ---
# Hardware: Nordic nRF52840 DK # Hardware: Nordic nRF52840 DK
# Flash: J-Link 683101126, it has no VCOM port, so with mcu-nrf-dk plugged in too run west from the NCS
# workspace (~/.cache/esphome/sdk-zephyr/frameworks/sdk-nrf-v3.4.1):
# west flash --no-rebuild -d ~/esphome/.esphome/build/mcu-nrf-ant/.west_build -i 000683101126
# Pinout: # Pinout:
# P0.06 UART0 TX -> logger (J-Link VCOM) # P0.06 UART0 TX -> logger (J-Link VCOM)
# P0.13 LED 1 (active low) -> ANT+ Connected (a configured device is received) # P0.13 LED 1 (active low) -> ANT+ Connected (a configured device is received)
# P0.14 LED 2 (active low) -> ANT+ Unknown Device (an unconfigured one is in range) # P0.14 LED 2 (active low) -> ANT+ Unknown Device (an unconfigured one is in range)
# NFC1/2 NFC antenna connector -> nfc_tag (Type 2 tag, HA tag URL)
# P1.01 UART1 RX <- mcu-nrf-dk UART1 TX (P1.02), packet_transport # P1.01 UART1 RX <- mcu-nrf-dk UART1 TX (P1.02), packet_transport
# P1.02 UART1 TX -> mcu-nrf-dk UART1 RX (P1.01), packet_transport; plus GND # P1.02 UART1 TX -> mcu-nrf-dk UART1 RX (P1.01), packet_transport; plus GND
# Radio: ANT+ receiver (RadiANT), no network of its own; values go to mcu-nrf-dk # Radio: ANT+ receiver (RadiANT), no network of its own; values go to mcu-nrf-dk
@@ -11,18 +15,19 @@
# 655730 Garmin HRM-Pro heart rate # 655730 Garmin HRM-Pro heart rate
# 498521 Concept2 PM5 (rower) fitness equipment (FE-C) # 498521 Concept2 PM5 (rower) fitness equipment (FE-C)
# 1044953 Garmin Tempe environment (temperature) # 1044953 Garmin Tempe environment (temperature)
# 604693 Garmin Varia RTL515 bike radar, battery only # 604693 Garmin Varia RTL515 bike radar: vehicles, nearest distance + closing speed, battery
# 136052 Garmin HRM-Dual heart rate (pain cave) # 136052 Garmin HRM-Dual heart rate (pain cave)
# 334424 Garmin HRM-Tri heart rate (bike) # 334424 Garmin HRM-Tri heart rate (bike)
# 886796 Garmin Rally RS200 power + cadence # 886796 Garmin Rally RS200 power + cadence
# 343922 Garmin Speed Sensor 2 speed # 343922 Garmin Speed Sensor 2 speed
# 42898 SRAM Force AXS shifting (Cube Litening C:68X), battery only # 42898 SRAM Force AXS shifting (Cube Litening C:68X), battery only
# 13888 Tacx Neo 2 fitness equipment (FE-C), basement trainer
esphome: esphome:
name: mcu-nrf-ant name: mcu-nrf-ant
friendly_name: nRF ANT+ friendly_name: nRF ANT+
# needs the esphomeplatformzephyr fork (esphome-zephyr); RadiANT needs NCS # needs the esphomeplatformzephyr fork (esphome-zephyr); RadiANT needs NCS
zephyr: nrf:
variant: NRF52 variant: NRF52
board: nrf52840dk/nrf52840 board: nrf52840dk/nrf52840
framework: framework:
@@ -33,7 +38,7 @@ logger:
external_components: external_components:
- source: github://randybb/esphome-components - source: github://randybb/esphome-components
components: [ant_plus] components: [ant_plus, nfc_tag]
output: output:
- platform: gpio - platform: gpio
@@ -43,6 +48,9 @@ output:
id: led_unknown id: led_unknown
pin: {number: P0.14, inverted: true} pin: {number: P0.14, inverted: true}
nfc_tag:
url: https://www.home-assistant.io/tag/mcu-nrf-ant
ant_plus: ant_plus:
network_key: !secret ant_plus_network_key network_key: !secret ant_plus_network_key
connected: connected:
@@ -100,6 +108,18 @@ ant_plus:
battery_low: battery_low:
id: varia_battery_low id: varia_battery_low
name: Garmin Varia RTL515 Battery Low name: Garmin Varia RTL515 Battery Low
targets:
id: varia_vehicles
name: Garmin Varia RTL515 Vehicles
distance:
id: varia_distance
name: Garmin Varia RTL515 Vehicle Distance
speed:
id: varia_speed
name: Garmin Varia RTL515 Closing Speed
fast_approach:
id: varia_fast
name: Garmin Varia RTL515 Fast Vehicle
- type: heart_rate # Garmin HRM-Dual - type: heart_rate # Garmin HRM-Dual
device_number: 136052 device_number: 136052
heart_rate: heart_rate:
@@ -138,6 +158,17 @@ ant_plus:
battery_low: battery_low:
id: speed2_battery_low id: speed2_battery_low
name: Garmin Speed Sensor 2 Battery Low name: Garmin Speed Sensor 2 Battery Low
- type: fitness_equipment # Tacx Neo 2
device_number: 13888
power:
id: neo_power
name: Tacx Neo 2 Power
cadence:
id: neo_cadence
name: Tacx Neo 2 Cadence
in_use:
id: neo_in_use
name: Tacx Neo 2 In Use
- type: shifting # SRAM Force AXS (Cube Litening C:68X) - type: shifting # SRAM Force AXS (Cube Litening C:68X)
device_number: 42898 device_number: 42898
battery_low: battery_low:
@@ -152,9 +183,17 @@ uart:
rx_pin: P1.01 rx_pin: P1.01
baud_rate: 115200 baud_rate: 115200
packet_transport: # same layers as mcu-nrf-dk, both ends must match
packet_interface:
- platform: uart - platform: uart
id: link_packets
uart_id: link uart_id: link
reliability:
session:
packet_transport:
- platform: packet_interface
packet_interface: link_packets
update_interval: 1s update_interval: 1s
sensors: sensors:
- hrm_pro_heart_rate - hrm_pro_heart_rate
@@ -166,6 +205,9 @@ packet_transport:
- tempe_temperature_max - tempe_temperature_max
- tempe_battery - tempe_battery
- varia_battery - varia_battery
- varia_vehicles
- varia_distance
- varia_speed
- hrm_dual_heart_rate - hrm_dual_heart_rate
- hrm_dual_battery - hrm_dual_battery
- hrm_tri_heart_rate - hrm_tri_heart_rate
@@ -174,12 +216,16 @@ packet_transport:
- rally_cadence - rally_cadence
- speed2_speed - speed2_speed
- speed2_battery - speed2_battery
- neo_power
- neo_cadence
binary_sensors: binary_sensors:
- ant_connected - ant_connected
- ant_unknown_device - ant_unknown_device
- pm5_in_use - pm5_in_use
- tempe_battery_low - tempe_battery_low
- varia_battery_low - varia_battery_low
- varia_fast
- rally_battery_low - rally_battery_low
- speed2_battery_low - speed2_battery_low
- sram_battery_low - sram_battery_low
- neo_in_use
+71 -4
View File
@@ -1,5 +1,7 @@
--- ---
# Hardware: Nordic nRF52840 DK # Hardware: Nordic nRF52840 DK
# Flash: J-Link 683492497 (with mcu-nrf-ant plugged in too, name the probe):
# esphome-zephyr upload mcu-nrf-dk.yaml --device /dev/serial/by-id/usb-SEGGER_J-Link_000683492497-if00
# Pinout: # Pinout:
# P0.11 Button 1 (active low) -> Button 1 (binary_sensor gpio) # P0.11 Button 1 (active low) -> Button 1 (binary_sensor gpio)
# P0.12 Button 2 (active low) -> Button 2 (binary_sensor gpio) # P0.12 Button 2 (active low) -> Button 2 (binary_sensor gpio)
@@ -11,13 +13,13 @@
# P0.25 Button 4 (active low) -> Button 4 (binary_sensor gpio) # P0.25 Button 4 (active low) -> Button 4 (binary_sensor gpio)
# P1.01 UART1 RX <- mcu-nrf-ant UART1 TX (P1.02), packet_transport; plus GND # P1.01 UART1 RX <- mcu-nrf-ant UART1 TX (P1.02), packet_transport; plus GND
# P1.02 UART1 TX -> mcu-nrf-ant UART1 RX (P1.01), packet_transport # P1.02 UART1 TX -> mcu-nrf-ant UART1 RX (P1.01), packet_transport
# ANT+ values (Garmin HRM-Pro, Concept2 PM5, Garmin Tempe, Garmin Varia RTL515) come from mcu-nrf-ant # ANT+ values (Garmin HRM-Pro, Concept2 PM5, Garmin Tempe, Garmin Varia RTL515, Tacx Neo 2, ...) come from mcu-nrf-ant
esphome: esphome:
name: mcu-nrf-dk name: mcu-nrf-dk
friendly_name: nRF DK friendly_name: nRF DK
# needs the esphomeplatformzephyr fork (esphome-zephyr), upstream has no zephyr: platform yet # needs the esphomeplatformzephyr fork (esphome-zephyr), upstream has no nrf: platform yet
zephyr: nrf:
variant: NRF52 variant: NRF52
board: nrf52840dk/nrf52840 board: nrf52840dk/nrf52840
framework: framework:
@@ -47,9 +49,21 @@ uart:
tx_pin: P1.02 tx_pin: P1.02
baud_rate: 115200 baud_rate: 115200
packet_transport: # retransmits lost frames; the session's keep-alives show whether mcu-nrf-ant is reachable
packet_interface:
- platform: uart - platform: uart
id: ant_link_packets
uart_id: ant_link uart_id: ant_link
reliability:
session:
binary_sensor:
name: ANT Link
device_class: connectivity
entity_category: diagnostic
packet_transport:
- platform: packet_interface
packet_interface: ant_link_packets
providers: providers:
- name: mcu-nrf-ant - name: mcu-nrf-ant
@@ -131,6 +145,29 @@ sensor:
device_class: voltage device_class: voltage
accuracy_decimals: 2 accuracy_decimals: 2
entity_category: diagnostic entity_category: diagnostic
- platform: packet_transport
provider: mcu-nrf-ant
remote_id: varia_vehicles
name: Garmin Varia RTL515 Vehicles
internal: false
icon: mdi:car-multiple
accuracy_decimals: 0
- platform: packet_transport
provider: mcu-nrf-ant
remote_id: varia_distance
name: Garmin Varia RTL515 Vehicle Distance
internal: false
unit_of_measurement: m
device_class: distance
accuracy_decimals: 1
- platform: packet_transport
provider: mcu-nrf-ant
remote_id: varia_speed
name: Garmin Varia RTL515 Closing Speed
internal: false
unit_of_measurement: m/s
device_class: speed
accuracy_decimals: 2
- platform: packet_transport - platform: packet_transport
provider: mcu-nrf-ant provider: mcu-nrf-ant
remote_id: hrm_dual_heart_rate remote_id: hrm_dual_heart_rate
@@ -202,6 +239,24 @@ sensor:
device_class: voltage device_class: voltage
accuracy_decimals: 2 accuracy_decimals: 2
entity_category: diagnostic entity_category: diagnostic
- platform: packet_transport
provider: mcu-nrf-ant
remote_id: neo_power
name: Tacx Neo 2 Power
internal: false
unit_of_measurement: W
device_class: power
filters:
- throttle: 1s
- platform: packet_transport
provider: mcu-nrf-ant
remote_id: neo_cadence
name: Tacx Neo 2 Cadence
internal: false
unit_of_measurement: rpm
icon: mdi:rotate-right
filters:
- throttle: 1s
output: output:
- platform: gpio - platform: gpio
@@ -257,6 +312,12 @@ binary_sensor:
internal: false internal: false
device_class: battery device_class: battery
entity_category: diagnostic entity_category: diagnostic
- platform: packet_transport
provider: mcu-nrf-ant
remote_id: varia_fast
name: Garmin Varia RTL515 Fast Vehicle
internal: false
icon: mdi:car-emergency
- platform: packet_transport - platform: packet_transport
provider: mcu-nrf-ant provider: mcu-nrf-ant
remote_id: rally_battery_low remote_id: rally_battery_low
@@ -278,6 +339,12 @@ binary_sensor:
internal: false internal: false
device_class: battery device_class: battery
entity_category: diagnostic entity_category: diagnostic
- platform: packet_transport
provider: mcu-nrf-ant
remote_id: neo_in_use
name: Tacx Neo 2 In Use
internal: false
device_class: running
- platform: gpio - platform: gpio
name: Button 1 name: Button 1
pin: {number: P0.11, inverted: true, mode: {input: true, pullup: true}} pin: {number: P0.11, inverted: true, mode: {input: true, pullup: true}}
+31 -40
View File
@@ -18,7 +18,10 @@ substitutions:
name: Bedroom NSPanel name: Bedroom NSPanel
name_short: Bedroom name_short: Bedroom
area: Bedroom area: Bedroom
comment: NSPanel comment: NSPanel (nspanel-terminal)
brightness: "80"
# backlight after 15 s idle
dim_brightness: "20"
esphome: esphome:
name: mcu-${device} name: mcu-${device}
@@ -29,51 +32,37 @@ esphome:
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml ipv6_only: !include common/ipv6_only.yaml
nspanel: !include panel: !include
file: common/nspanel.yaml file: common/nspanel_terminal/panel.yaml
vars: vars:
temperature_entity: sensor.zigbee_bedroom_temperature temperature_entity: sensor.zigbee_bedroom_temperature
first_page: page_bedroom
last_page: page_thermostat
sleep_dim: !include sleep_dim: !include
file: common/nspanel_sleep_dim.yaml file: common/nspanel_terminal/sleep_dim.yaml
vars: vars:
sleep_override_entity: light.bedroom_lights sleep_override_entity: light.bedroom_lights
# Grid page tiles: each package adds its tile to the page and fills it in this order
# Spálňa
s_tv: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_bedroom, id: s_tv, name: "TV", entity: switch.mcu_socket_01_relay, icon: "\U000F07F4", domain: switch}}
s_raid: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_bedroom, id: s_raid, name: "Raid", entity: switch.mcu_socket_02_relay, icon: "\U000F0C6E", domain: switch}}
s_socket_3: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_bedroom, id: s_socket_3, name: "", entity: switch.mcu_socket_03_relay, icon: "\U000F1108", domain: switch}}
l_bedroom: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_bedroom, id: l_bedroom, name: "Svetlo", entity: light.mcu_nspanel_bedroom_light, icon: "\U000F091D", dim: false, kmin: 0, hs: false}}
l_lamp_right: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_bedroom, id: l_lamp_right, name: "Nočná lampa J", entity: light.mcu_bedroom_lamp_right_light, icon: "\U000F06B5", dim: true, kmin: 1701, hs: true}}
l_lamp_left: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_bedroom, id: l_lamp_left, name: "Nočná lampa R", entity: light.mcu_bedroom_lamp_left_light, icon: "\U000F06B5", dim: true, kmin: 1701, hs: true}}
# Kúrenie
thermo: !include {file: common/nspanel_terminal/thermostat.yaml, vars: {id: thermo, page: page_thermostat, title: "Kúrenie - Spálňa", prev: page_bedroom, next: page_status, entity: climate.bt_trv_bedroom}}
# home page icons, right to left
i_fire: !include common/nspanel_terminal/fireplace_icon.yaml
i_radiator: !include {file: common/nspanel_terminal/radiator_icon.yaml, vars: {id: i_radiator, entity: climate.bt_trv_bedroom}}
nspanel_lovelace: # the grid pages; home, status and light detail come from panel.yaml, thermostat pages from thermostat.yaml
cards: lvgl:
- type: cardGrid pages:
title: Spálňa - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_bedroom, title: "Spálňa", prev: page_home, next: page_thermostat, skip: false}}
entities:
- name: TV
entity_id: switch.mcu_socket_01_relay
icon: television-classic
- name: Raid
entity_id: switch.mcu_socket_02_relay
icon: emoticon-dead
- name: ""
entity_id: switch.mcu_socket_03_relay
icon: power-socket-fr
- name: Svetlo
entity_id: light.mcu_nspanel_bedroom_light
icon: wall-sconce-flat
- name: Nočná lampa J
entity_id: light.mcu_bedroom_lamp_right_light
icon: lamp
- name: Nočná lampa R
entity_id: light.mcu_bedroom_lamp_left_light
icon: lamp
- type: cardThermo
title: Kúrenie
thermo_entity_id: climate.bt_trv_bedroom
- type: cardEntities
title: Info
entities:
- name: Zariadenie
entity_id: button.bedroom_nspanel_info
icon: information-outline
binary_sensor: binary_sensor:
# both buttons show the Spálňa page, where the change is visible
- platform: gpio - platform: gpio
name: Left Button name: Left Button
pin: pin:
@@ -81,7 +70,8 @@ binary_sensor:
inverted: true inverted: true
on_click: on_click:
- light.toggle: light_1 - light.toggle: light_1
- lambda: 'id(nspanel_id).render_default_page();' - lvgl.page.show: page_bedroom
- script.execute: wake_screen
- platform: gpio - platform: gpio
name: Right Button name: Right Button
@@ -95,7 +85,8 @@ binary_sensor:
action: light.toggle action: light.toggle
data: data:
entity_id: light.bedroom_lamps entity_id: light.bedroom_lamps
- lambda: 'id(nspanel_id).render_default_page();' - lvgl.page.show: page_bedroom
- script.execute: wake_screen
light: light:
- platform: binary - platform: binary
+76 -518
View File
@@ -17,452 +17,85 @@ substitutions:
device: nspanel-dev device: nspanel-dev
name: NSPanel DEV name: NSPanel DEV
area: DEV area: DEV
comment: NSPanel comment: NSPanel (nspanel-terminal)
panel_recv_topic: "tele/${device}/RESULT" brightness: "80"
panel_send_topic: "cmnd/${device}/CustomSend" # backlight after 15 s idle, tune to taste
tft_url: !secret tft_url dim_brightness: "20"
esphome: esphome:
name: mcu-${device} name: mcu-${device}
friendly_name: ${name} friendly_name: ${name}
area: ${area} area: ${area}
comment: ${comment} comment: ${comment}
on_boot:
then:
- switch.turn_off: screen_power
- delay: 1s
- switch.turn_on: screen_power
- delay: 2s
- lambda: 'id(nspanel_id).set_display_dim(5, 80);'
# priority: -100
# then:
# - wait_until:
# api.connected
# - delay: 10s
# - homeassistant.service:
# service: automation.trigger
# data:
# entity_id: automation.nspanel_send_weather_to_nspanel
esp32:
variant: esp32
toolchain: esp-idf
framework:
type: esp-idf
advanced:
flash_chip: generic
minimum_chip_revision: 3.0
sram1_as_iram: true
external_components:
# - source:
# type: git
# url: https://github.com/sairon/esphome-nspanel-lovelace-ui
# ref: dev
# refresh: 0s
# components: [nspanel_lovelace]
- source:
type: git
# url: https://github.com/olicooper/esphome-nspanel-lovelace-native
# ref: dev
url: https://github.com/randybb/esphome-nspanel-lovelace-native
ref: devices
refresh: 0s
components: [nspanel_lovelace]
# - source: components
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml ipv6_only: !include common/ipv6_only.yaml
nspanel_popup: !include common/nspanel_popup.yaml panel: !include
# common: !include common/common_dev.yaml file: common/nspanel_terminal/panel.yaml
vars:
temperature_entity: sensor.zigbee_office_r_temperature
first_page: page_kitchen
last_page: page_gate
sleep_dim: !include
file: common/nspanel_terminal/sleep_dim.yaml
vars:
sleep_override_entity: light.mcu_nspanel_office_r_light
# Grid page tiles: each package adds its tile to the page and fills it in this order
# Kuchyňa / Obývačka
l_kitchen: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen, id: l_kitchen, name: "Kuchyňa", entity: light.kitchen, icon: "\U000F0769", dim: true, kmin: 2700, hs: false}}
l_dining: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen, id: l_dining, name: "Stôl", entity: light.dining_table, icon: "\U000F1793", dim: true, kmin: 2700, hs: false}}
l_living: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen, id: l_living, name: "Gauč", entity: light.living_room, icon: "\U000F04B9", dim: true, kmin: 2700, hs: false}}
l_tv: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen, id: l_tv, name: "TV", entity: light.mcu_tv_light_light, icon: "\U000F0502", dim: false, kmin: 0, hs: false}}
l_dining_amb: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen, id: l_dining_amb, name: "(Stôl)", entity: light.dining_table_ambilight, icon: "\U000F1051", dim: true, kmin: 1700, hs: true}}
l_living_amb: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen, id: l_living_amb, name: "(Gauč)", entity: light.living_room_ambilight, icon: "\U000F1051", dim: true, kmin: 1700, hs: true}}
# Romanko
l_office: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_office, id: l_office, name: "Svetlo", entity: light.mcu_nspanel_office_r_light, icon: "\U000F0769", dim: false, kmin: 0, hs: false}}
l_strip: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_office, id: l_strip, name: "LED pásik", entity: light.office_r_desk_strip, icon: "\U000F1051", dim: true, kmin: 1700, hs: true}}
office_spacer: !include {file: common/nspanel_terminal/spacer_tile.yaml, vars: {page: page_office}}
l_monitor: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_office, id: l_monitor, name: "Monitor", entity: light.office_r_display_lamp, icon: "\U000F0379", dim: true, kmin: 2700, hs: false}}
l_monitor_amb: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_office, id: l_monitor_amb, name: "(Monitor)", entity: light.office_r_display_lamp_ambilight, icon: "\U000F1051", dim: true, kmin: 1700, hs: true}}
# Von (card_outside of the patio panel)
l_patio: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_outside, id: l_patio, name: "Terasa", entity: light.patio_lights, icon: "\U000F1253", dim: true, kmin: 2000, hs: false}}
s_patio_socket: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_patio_socket, name: "Terasa", entity: switch.mcu_patio_relay, icon: "\U000F1108", domain: switch}}
s_patio_back: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_patio_back, name: "Vzadu", entity: switch.mcu_nspanel_patio_outside_light_back, icon: "\U000F1987", domain: switch}}
s_shed_light: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_shed_light, name: "Z. domček", entity: switch.mcu_shed_light, icon: "\U000F091D", domain: switch}}
s_shed_socket: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_shed_socket, name: "Z. domček", entity: switch.mcu_shed_socket, icon: "\U000F1108", domain: switch}}
s_garden: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_garden, name: "Záhrada", entity: switch.mcu_shed_garden_light, icon: "\U000F1987", domain: switch}}
# Závlaha, robot -> page_irrigation_auto
v_a1: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation, id: v_a1, name: "A1", entity: switch.mcu_well_irrigation_valve_a1, icon: "\U000F1066", domain: switch}}
v_a2: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation, id: v_a2, name: "A2", entity: switch.mcu_well_irrigation_valve_a2, icon: "\U000F1066", domain: switch}}
v_a3: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation, id: v_a3, name: "A3", entity: switch.mcu_well_irrigation_valve_a3, icon: "\U000F1066", domain: switch}}
v_a4: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation, id: v_a4, name: "A4", entity: switch.mcu_well_irrigation_valve_a4, icon: "\U000F1066", domain: switch}}
v_a5: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation, id: v_a5, name: "A5", entity: switch.mcu_well_irrigation_valve_a5, icon: "\U000F1066", domain: switch}}
irrigation_auto: !include {file: common/nspanel_terminal/nav_tile.yaml, vars: {page: page_irrigation, to: page_irrigation_auto, icon: "\U000F06A9"}}
ir_morning: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation_auto, id: ir_morning, name: "Ráno", entity: automation.irrigation_morning, icon: "\U000F059C", domain: automation}}
ir_patio: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation_auto, id: ir_patio, name: "Terasa", entity: automation.irrigation_patio, icon: "\U000F024A", domain: automation}}
ir_grass: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation_auto, id: ir_grass, name: "Rast trávy", entity: automation.irrigation_grow_grass, icon: "\U000F1510", domain: automation}}
# Brána, robot -> page_gate_auto
gate_open: !include {file: common/nspanel_terminal/action_tile.yaml, vars: {page: page_gate, id: gate_open, name: "Otvoriť", icon: "\U000F116A", action: button.press, entity: button.mcu_gate_open}}
gate_close: !include {file: common/nspanel_terminal/action_tile.yaml, vars: {page: page_gate, id: gate_close, name: "Zatvoriť", icon: "\U000F0299", action: button.press, entity: button.mcu_gate_close}}
gate_spacer: !include {file: common/nspanel_terminal/spacer_tile.yaml, vars: {page: page_gate}}
gate: !include {file: common/nspanel_terminal/gate.yaml, vars: {page: page_gate, state: select.mcu_gate_state}}
gate_auto: !include {file: common/nspanel_terminal/nav_tile.yaml, vars: {page: page_gate, to: page_gate_auto, icon: "\U000F06A9"}}
gate_auto_open: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_gate_auto, id: gate_auto_open, name: "Auto-otváranie", entity: switch.mcu_gate_auto_open, icon: "\U000F1169", domain: switch}}
gate_auto_close: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_gate_auto, id: gate_auto_close, name: "Auto-zatváranie", entity: switch.mcu_gate_auto_close, icon: "\U000F17F7", domain: switch}}
# Kúrenie
thermostat: !include {file: common/nspanel_terminal/thermostat.yaml, vars: {id: thermo, page: page_thermostat, title: "Kúrenie - Romanko", prev: page_irrigation, next: page_gate, entity: climate.bt_trv_office_r}}
# home page icons, right to left
i_fire: !include common/nspanel_terminal/fireplace_icon.yaml
i_radiator: !include {file: common/nspanel_terminal/radiator_icon.yaml, vars: {id: i_radiator, entity: climate.bt_trv_office_r}}
# web_server: # the grid pages; home, status and light detail come from panel.yaml, the thermostat page from thermostat.yaml
# port: 80 lvgl:
# local: true pages:
- <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_kitchen, title: "Kuchyňa / Obývačka", prev: page_home, next: page_office, skip: false}}
api: - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_office, title: "Romanko", prev: page_kitchen, next: page_outside, skip: false}}
homeassistant_services: true - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_outside, title: "Von", prev: page_office, next: page_irrigation, skip: false}}
homeassistant_states: true - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_irrigation, title: "Závlaha", prev: page_outside, next: page_thermostat, skip: false}}
actions: - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_irrigation_auto, title: "Automatizácia závlahy", prev: page_irrigation, next: page_irrigation, skip: true}}
# https://github.com/granadaxronos/120-SONG_NOKIA_RTTTL_RINGTONE_PLAYER_FOR_ARDUINO_UNO/blob/master/RTTTL_PLAYER/songs.h - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_gate, title: "Brána", prev: page_thermostat, next: page_status, skip: false}}
- action: play_rtttl - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_gate_auto, title: "Automatizácia brány", prev: page_gate, next: page_gate, skip: true}}
variables:
song: string
then:
- rtttl.play:
rtttl: !lambda 'return song;'
- action: notify
variables:
heading: string
message: string
song: string
then:
- lambda: 'id(nspanel_id).notify_on_screensaver(heading, message, 10000);'
- rtttl.play:
rtttl: !lambda 'return song;'
# - delay: 10s
# - lambda: 'id(nspanel_id).send_custom_command("notify~~");'
# DISABLED until https://github.com/olicooper/esphome-nspanel-lovelace-native/issues/20 is fixed
# - service: update_tft
# then:
# - lambda: |-
# id(nspanel_id).upload_tft("${tft_url}");
# - service: upload_tft
# variables:
# url: string
# then:
# - lambda: |-
# id(nspanel_id).upload_tft(url);
# # Service to send a command directly to the display. Useful for testing
# - service: send_command
# variables:
# cmd: string
# then:
# - lambda: "id(nspanel_id).send_custom_command(cmd.c_str());"
# # Service to pusblish to mqtt used for refreshin the panel
# - service: publish_to_recv_topic
# variables:
# cmd: string
# then:
# - mqtt.publish:
# topic: $panel_recv_topic
# payload: !lambda "return cmd;"
# # Service to send a command wake the screen
# - service: wake
# then:
# - lambda: 'id(nspanel_id).send_custom_command("wake");'
# # Service to send a command to show screensaver (some of the values are hardcoded)
# - service: show_screensaver
# then:
# - mqtt.publish:
# topic: $panel_recv_topic
# payload: '{"CustomRecv":"event,sleepReached,cardGrid"}'
# # Service to navigate to screen
# - service: navigate_to_page
# variables:
# page: string
# then:
# - mqtt.publish_json:
# topic: $panel_recv_topic
# payload: |-
# root["CustomRecv"] = "event,buttonPress2,navigate." + page + ",button";
# # Service to send a command disable screensaver
# - service: disable_screensaver
# then:
# - lambda: 'id(nspanel_id).send_custom_command("timeout~0");'
# # Service to send a command enabled screensaver
# - service: enable_screensaver
# then:
# - lambda: 'id(nspanel_id).send_custom_command("timeout~20");'
# # Service to send a command wake the screen
# - service: dim_0_to_100
# variables:
# intensity: string
# then:
# - lambda: 'id(nspanel_id).send_custom_command("dimmode~"+intensity+"~100");'
# # Service to send a command To show the screen of a specific like
# - service: show_entity
# variables:
# entity: string
# title: string
# then:
# - lambda: 'id(nspanel_id).send_custom_command("pageType~popupLight~" + title + "~" + entity);'
# # Service to send a command To show the screen of a specific like
# - service: notify_on_screensaver
# variables:
# line1: string
# line2: string
# then:
# - lambda: 'id(nspanel_id).send_custom_command("notify~" + line1 + "~" + line2);'
# # - rtttl.play: "short:d=4,o=5,b=100:16e6"
# Service to send a command To show the screen of a specific like
# interaction of the buttons are on implemented yet
- action: notify_fullscreen
variables:
title: string
description: string
button1: string
button2: string
timeout: int
icon: string
then:
- lambda: 'id(nspanel_id).notify_on_screensaver(title, description, timeout);'
# show notification screen
# - lambda: 'id(nspanel_id).send_custom_command("pageType~popupNotify");'
# set values on notification screen
# color defined as number created in binary and converted to decimal (rrrrggggbbbbaaaa)
# - lambda: 'id(nspanel_id).send_custom_command("entityUpdateDetail~id~"+ title + "~65535~" + button1 +"~3840~" + button2 + "~61440~" + description + "~65535~" + timeout + "~3~" + icon + "~65535~");'
- rtttl.play: "scale_up:d=32,o=5,b=100:c,c#,d#,e,f#,g#,a#,b"
uart:
id: display_uart
tx_pin: 16
rx_pin: 17
baud_rate: 115200
nspanel_lovelace:
id: nspanel_id
sleep_timeout: 10
experimental_vertical_ui: true
locale:
language: sk
temperature_unit: celcius
screensaver:
time_id: ha_time
time_format: '%H:%M'
date_format: '%A, %d. %b. %Y'
weather:
entity_id: sensor.weather_forecast_daily
# entity_id: weather.openweathermap
# forecast_method: service
icon_color: [255, 255, 255]
entities:
- entity_id: sensor.zigbee_office_r_temperature
icon:
value: home-thermometer-outline
color: [255, 255, 255]
precision: 1
# type: screensaver2
## Custom entities, filled into the layout slots in order after the weather items.
## Use 'entity_id: delete' to leave a slot empty.
## screensaver: weather main + 4 forecast items, 1 extra entity switches to the alternative layout (max 6 items)
## screensaver2: weather main only, then 3 left + 6 bottom + 5 indicator icons (max 15 items)
# entities:
# - entity_id: sensor.outside_humidity
# name: Humidity
# icon: water-percent
# - entity_id: delete
# - entity_id: binary_sensor.front_door
# type: screensaver2
# statusIcon1:
# entity: switch.office_r_light
# icon:
# "on": mdi:sofa
# "off": mdi:sofa
# color:
# "on": [255, 255, 255]
# "off": [255, 255, 255]
# statusIcon2:
# entity: light.office_r_desk_strip
# icon:
# "on": mdi:table-furniture
# "off": mdi:table-furniture
# color:
# "on": [255, 255, 255]
# "off": [255, 255, 255]
# entities:
# - entity: sensor.weather_forecast_daily
# color: [255, 255, 255]
# - entity: delete
# - entity: delete
# - entity: delete
# - entity: sensor.weather_forecast_daily
# color: [255, 255, 255]
# type: 0
# - entity: sensor.weather_forecast_daily
# color: [255, 255, 255]
# type: 1
# - entity: sensor.weather_forecast_daily
# color: [255, 255, 255]
# type: 2
# - entity: sensor.weather_forecast_daily
# color: [255, 255, 255]
# type: 3
# - entity: delete
# - entity: sensor.zigbee_office_r_temperature
# color: [255, 255, 255]
# name: ""
# icon: mdi:home-thermometer
# - entity: switch.heating_relay_3
# icon:
# "on": mdi:radiator
# "off": "text:"
# color:
# "on": [255, 255, 255]
# - entity: binary_sensor.heating_fireplace_fire
# icon:
# "on": mdi:fireplace
# "off": "text:"
# color:
# "on": [255, 255, 255]
# - entity: delete
# - entity: delete
# - entity: delete
cards:
- type: cardGrid
title: Kuchyňa / Obývačka
entities:
- name: Kuchyňa
entity_id: light.kitchen
icon: ceiling-light
- name: Stôl
entity_id: light.dining_table
icon: ceiling-light
- name: Gauč
entity_id: light.living_room
icon: ceiling-light
- name: TV
entity_id: light.mcu_tv_light_light
icon: led-strip-variant
- name: (Stôl)
entity_id: light.dining_table_ambilight
icon: ceiling-light-multiple-outline
- name: (Gauč)
entity_id: light.living_room_ambilight
icon: ceiling-light-multiple-outline
- type: cardGrid
title: Romanko
entities:
- name: Svetlo
entity_id: light.mcu_nspanel_office_r_light
icon: wall-sconce-flat
- name: LED pásik
entity_id: light.office_r_desk_strip
icon: led-strip-variant
- entity_id: delete
- name: Monitor
entity_id: light.office_r_display_lamp
icon: monitor-star
- name: (Monitor)
entity_id: light.office_r_display_lamp_ambilight
icon: monitor-star
- type: cardGrid
title: Von
entities:
- name: Terasa
entity_id: light.patio_lights
icon: lightbulb-group
- name: Terasa
entity_id: switch.mcu_patio_relay
icon: power-socket-fr
- name: Vzadu
entity_id: switch.mcu_nspanel_patio_outside_light_back
icon: light-flood-down
- name: Z. domček
entity_id: switch.mcu_shed_light
icon: wall-sconce-flat
# state_template: '{{ is_state("binary_sensor.shed_status", "off") }}'
- name: Z. domček
entity_id: switch.mcu_shed_socket
icon: power-socket-fr
# state_template: '{{ is_state("binary_sensor.shed_status", "off") }}'
- name: Záhrada
entity_id: switch.mcu_shed_garden_light
icon: light-flood-down
# state_template: '{{ is_state("binary_sensor.shed_status", "off") }}'
- type: cardGrid
title: Brána
entities:
- name: Otvoriť
entity_id: button.mcu_gate_open
icon: gate-open
- name: Zatvoriť
entity_id: button.mcu_gate_close
icon: gate
- name: Automatizácia
entity_id: navigate.card_gate_automation
- type: cardGrid
title: Závlaha
entities:
- name: A1
entity_id: switch.mcu_well_irrigation_valve_a1
icon: valve
- name: A2
entity_id: switch.mcu_well_irrigation_valve_a2
icon: valve
- name: A3
entity_id: switch.mcu_well_irrigation_valve_a3
icon: valve
- name: A4
entity_id: switch.mcu_well_irrigation_valve_a4
icon: valve
- name: A5
entity_id: switch.mcu_well_irrigation_valve_a5
icon: valve
- name: Automatizácia
entity_id: navigate.card_irrigation_automation
- type: cardThermo
title: Kúrenie
thermo_entity_id: climate.bt_trv_office_r
# - type: cardQR
# title: Guest Wifi
# qr_text: "WIFI:T:WPA;S:LAB;P:slniecko;;"
# # qrCode: "URL:https://www.johndoe.com/"
# # entities:
# # - entity_id: delete
# # - entity_id: iText.LAB
# # name: Name
# # icon: wifi
# # - entity_id: iText.slniecko
# # name: Password
# # icon: key
- type: cardEntities
title: Zwift
entities:
- name: Svetlo
entity_id: light.mcu_basement_light
icon: lightbulb-multiple
- name: LED
entity_id: light.exercise_room
icon: led-strip-variant
- name: Ventilátor
entity_id: light.mcu_dimmer_exercise_room_fan
icon: fan
- name: Automatizácia
entity_id: navigate.card_exercise_automation
- type: cardEntities
title: Automatizácia
id: card_exercise_automation
hidden: true
entities:
- name: Start
entity_id: automation.zwift_enable_fan
- name: End
entity_id: automation.zwift_disable_fan
- type: cardEntities
title: Automatizácia
id: card_gate_automation
hidden: true
entities:
- name: Auto-otváranie
entity_id: switch.gate_auto_open
- name: Auto-zatváranie
entity_id: switch.gate_auto_close
- type: cardEntities
title: Automatizácia
id: card_irrigation_automation
hidden: true
entities:
- name: Ráno
entity_id: automation.irrigation_morning
- name: Terasa
entity_id: automation.irrigation_patio
- name: Rast trávy
entity_id: automation.irrigation_grow_grass
- type: cardEntities
title: Info
entities:
- name: Zariadenie
entity_id: button.nspanel_dev_info
icon: information-outline
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
@@ -470,12 +103,14 @@ binary_sensor:
pin: pin:
number: 14 number: 14
inverted: true inverted: true
on_press: # like the other panels: toggle the office light and show the page with its tile
- switch.toggle: relay_1 on_click:
# - homeassistant.service: - homeassistant.action:
# service: switch.toggle action: light.toggle
# data: data:
# entity_id: switch.gate_open entity_id: light.mcu_nspanel_office_r_light
- lvgl.page.show: page_office
- script.execute: wake_screen
- platform: gpio - platform: gpio
name: Right Button name: Right Button
@@ -489,92 +124,15 @@ binary_sensor:
# data: # data:
# entity_id: switch.gate_close # entity_id: switch.gate_close
output:
- platform: ledc
id: buzzer_out
pin:
number: 21
switch: switch:
- platform: gpio - platform: gpio
name: Relay 1 name: Relay 1
id: relay_1 id: relay_1
pin: pin:
number: 22 number: 22
on_turn_on:
# show a light on the panel when we swich on the light
# - lambda: 'id(nspanel).send_custom_command("pageType~popupLight~[TITLE TO SHOW ON SCREEN]~[ENTITY NAME]");'
- lambda: 'id(nspanel_id).send_display_command("pageType~popupLight~Light 1~light.bed_light");'
# on_turn_off:
# # send to screensaver when switch off the light
# - mqtt.publish:
# topic: $panel_recv_topic
# payload: '{"CustomRecv":"event,sleepReached,cardGrid"}'
- platform: gpio - platform: gpio
name: Relay 2 name: Relay 2
id: relay_2 id: relay_2
pin: pin:
number: 19 number: 19
on_turn_on:
# show a light on the panel when we swich on the light
- lambda: 'id(nspanel_id).send_display_command("pageType~popupLight~Light 2~light.bed_light2");'
# on_turn_off:
# # send to screensaver when switch off the light
# - mqtt.publish:
# topic: $panel_recv_topic
# payload: '{"CustomRecv":"event,sleepReached,cardGrid"}'
# Turn screen power on/off. Easy way to configure the screen power control, but this should not be used from HA, as all components must be re-initialized afterwards. For lights, names of lights etc. this practically means that the state must change once to happen.
- platform: gpio
name: Screen Power
id: screen_power
entity_category: config
pin:
number: 4
inverted: true
restore_mode: ALWAYS_ON
rtttl:
id: buzzer
output: buzzer_out
sensor:
- platform: adc
id: ntc_source
pin: 38
update_interval: 5min
attenuation: 12db
- platform: resistance
id: resistance_sensor
sensor: ntc_source
configuration: DOWNSTREAM
resistor: 11.2kOhm
- platform: ntc
id: temperature
sensor: resistance_sensor
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kOhm
name: Living Room Temperature Entry
- platform: template
id: room_temperature_id
text_sensor:
- platform: homeassistant
id: name_day
entity_id: sensor.nameday_sk
on_value:
- lambda: |-
id(nspanel_id).set_time_format("%H:%M~" + x);
id(nspanel_id).update_time();
# esp32_ble_tracker:
# scan_parameters:
# duration: 1min
# bluetooth_proxy:
+58 -104
View File
@@ -17,7 +17,10 @@ substitutions:
device: nspanel-fireplace device: nspanel-fireplace
name: Fireplace NSPanel name: Fireplace NSPanel
area: Living Room & Kitchen area: Living Room & Kitchen
comment: NSPanel comment: NSPanel (nspanel-terminal)
brightness: "80"
# backlight after 15 s idle
dim_brightness: "20"
esphome: esphome:
name: mcu-${device} name: mcu-${device}
@@ -28,109 +31,58 @@ esphome:
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml ipv6_only: !include common/ipv6_only.yaml
nspanel: !include panel: !include
file: common/nspanel.yaml file: common/nspanel_terminal/panel.yaml
vars: vars:
temperature_entity: sensor.zigbee_living_room_kitchen_temperature temperature_entity: sensor.zigbee_living_room_kitchen_temperature
temperature_name: Living Room Temperature temperature_name: Living Room Temperature
first_page: page_kitchen_living
last_page: page_thermostat_room
# Grid page tiles: each package adds its tile to the page and fills it in this order
# Kuchyňa / Obývačka
l_kitchen: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen_living, id: l_kitchen, name: "Kuchyňa", entity: light.kitchen, icon: "\U000F0769", dim: true, kmin: 2700, hs: false}}
l_dining: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen_living, id: l_dining, name: "Stôl", entity: light.dining_table, icon: "\U000F0769", dim: true, kmin: 2700, hs: false}}
l_living: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen_living, id: l_living, name: "Gauč", entity: light.living_room, icon: "\U000F0769", dim: true, kmin: 2700, hs: false}}
l_tv: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen_living, id: l_tv, name: "TV", entity: light.mcu_tv_light_strip, icon: "\U000F1051", dim: true, kmin: 0, hs: false}}
l_dining_amb: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen_living, id: l_dining_amb, name: "(Stôl)", entity: light.dining_table_ambilight, icon: "\U000F18DE", dim: true, kmin: 1700, hs: true}}
l_living_amb: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen_living, id: l_living_amb, name: "(Gauč)", entity: light.living_room_ambilight, icon: "\U000F18DE", dim: true, kmin: 1700, hs: true}}
# Kuchyňa
l_worktop: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen, id: l_worktop, name: "Linka", entity: light.worktop_lights, icon: "\U000F181C", dim: true, kmin: 2000, hs: false}}
l_stove: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen, id: l_stove, name: "Sporák", entity: light.mcu_kitchen_stove, icon: "\U000F04DE", dim: true, kmin: 2000, hs: false}}
# Von
l_patio: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_outside, id: l_patio, name: "Terasa", entity: light.patio_lights, icon: "\U000F1253", dim: true, kmin: 2000, hs: false}}
s_patio_socket: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_patio_socket, name: "Terasa", entity: switch.mcu_patio_relay, icon: "\U000F1108", domain: switch}}
s_patio_back: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_patio_back, name: "Vzadu", entity: switch.mcu_nspanel_patio_outside_light_back, icon: "\U000F1987", domain: switch}}
s_shed_light: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_shed_light, name: "Z. domček", entity: switch.mcu_shed_light, icon: "\U000F091D", domain: switch}}
s_shed_socket: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_shed_socket, name: "Z. domček", entity: switch.mcu_shed_socket, icon: "\U000F1108", domain: switch}}
s_garden: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_garden, name: "Záhrada", entity: switch.mcu_shed_garden_light, icon: "\U000F1987", domain: switch}}
# Brána, robot -> page_gate_auto
gate_open: !include {file: common/nspanel_terminal/action_tile.yaml, vars: {page: page_gate, id: gate_open, name: "Otvoriť", icon: "\U000F116A", action: button.press, entity: button.mcu_gate_open}}
gate_close: !include {file: common/nspanel_terminal/action_tile.yaml, vars: {page: page_gate, id: gate_close, name: "Zatvoriť", icon: "\U000F0299", action: button.press, entity: button.mcu_gate_close}}
gate_spacer: !include {file: common/nspanel_terminal/spacer_tile.yaml, vars: {page: page_gate}}
gate: !include {file: common/nspanel_terminal/gate.yaml, vars: {page: page_gate, state: select.mcu_gate_state}}
gate_auto: !include {file: common/nspanel_terminal/nav_tile.yaml, vars: {page: page_gate, to: page_gate_auto, icon: "\U000F06A9"}}
gate_auto_open: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_gate_auto, id: gate_auto_open, name: "Auto-otváranie", entity: switch.mcu_gate_auto_open, icon: "\U000F1169", domain: switch}}
gate_auto_close: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_gate_auto, id: gate_auto_close, name: "Auto-zatváranie", entity: switch.mcu_gate_auto_close, icon: "\U000F17F7", domain: switch}}
# Kúrenie
thermo: !include {file: common/nspanel_terminal/thermostat.yaml, vars: {id: thermo, page: page_thermostat, title: "Kúrenie - Obývačka", prev: page_gate, next: page_thermostat_room, entity: climate.bt_trv_living_room_kitchen}}
thermo_room: !include {file: common/nspanel_terminal/thermostat.yaml, vars: {id: thermo_room, page: page_thermostat_room, title: "Kúrenie - Izba", prev: page_thermostat, next: page_status, entity: climate.bt_trv_room}}
# home page icons, right to left
i_fire: !include common/nspanel_terminal/fireplace_icon.yaml
i_radiator: !include {file: common/nspanel_terminal/radiator_icon.yaml, vars: {id: i_radiator, entity: climate.bt_trv_living_room_kitchen}}
i_radiator_room: !include {file: common/nspanel_terminal/radiator_icon.yaml, vars: {id: i_radiator_room, entity: climate.bt_trv_room}}
nspanel_lovelace: # the grid pages; home, status and light detail come from panel.yaml, thermostat pages from thermostat.yaml
cards: lvgl:
- type: cardGrid pages:
title: Kuchyňa / Obývačka - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_kitchen_living, title: "Kuchyňa / Obývačka", prev: page_home, next: page_kitchen, skip: false}}
entities: - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_kitchen, title: "Kuchyňa", prev: page_kitchen_living, next: page_outside, skip: false}}
- name: Kuchyňa / Obývačka - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_outside, title: "Von", prev: page_kitchen, next: page_gate, skip: false}}
entity_id: light.kitchen - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_gate, title: "Brána", prev: page_outside, next: page_thermostat, skip: false}}
icon: ceiling-light - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_gate_auto, title: "Automatizácia brány", prev: page_gate, next: page_gate, skip: true}}
- name: Stôl
entity_id: light.dining_table
icon: ceiling-light
- name: Gauč
entity_id: light.living_room
icon: ceiling-light
- name: TV
entity_id: light.mcu_tv_light_strip
icon: led-strip-variant
- name: (Stôl)
entity_id: light.dining_table_ambilight
icon: ceiling-light-multiple-outline
- name: (Gauč)
entity_id: light.living_room_ambilight
icon: ceiling-light-multiple-outline
- type: cardGrid
title: Kuchyňa
entities:
- name: Linka
entity_id: light.worktop_lights
icon: countertop
- name: Sporák
entity_id: light.mcu_kitchen_stove
icon: stove
- type: cardGrid
title: Von
entities:
- name: Terasa
entity_id: light.patio_lights
icon: lightbulb-group
- name: Terasa
entity_id: switch.mcu_patio_relay
icon: power-socket-fr
- name: Vzadu
entity_id: switch.mcu_nspanel_patio_outside_light_back
icon: light-flood-down
- name: Z. domček
entity_id: switch.mcu_shed_light
icon: wall-sconce-flat
# state_template: '{{ is_state("binary_sensor.shed_status", "off") }}'
- name: Z. domček
entity_id: switch.mcu_shed_socket
icon: power-socket-fr
# state_template: '{{ is_state("binary_sensor.shed_status", "off") }}'
- name: Záhrada
entity_id: switch.mcu_shed_garden_light
icon: light-flood-down
# state_template: '{{ is_state("binary_sensor.shed_status", "off") }}'
- type: cardGrid
title: Brána
entities:
- name: Otvoriť
entity_id: button.mcu_gate_open
icon: gate-open
- name: Zatvoriť
entity_id: button.mcu_gate_close
icon: gate
- name: Automatizácia
entity_id: navigate.card_gate_automation
- type: cardThermo
title: Kúrenie
thermo_entity_id: climate.bt_trv_living_room_kitchen
- type: cardThermo
title: Kúrenie - Izba
thermo_entity_id: climate.bt_trv_room
- type: cardEntities
title: Automatizácia
id: card_gate_automation
hidden: true
entities:
- name: Auto-otváranie
entity_id: switch.gate_auto_open
- name: Auto-zatváranie
entity_id: switch.gate_auto_close
- type: cardEntities
title: Info
entities:
- name: Zariadenie
entity_id: button.fireplace_nspanel_info
icon: information-outline
binary_sensor: binary_sensor:
# short click: living room / dining table (Kuchyňa / Obývačka page), long click: worktop / stove (Kuchyňa page)
- platform: gpio - platform: gpio
name: Left Button name: Left Button
pin: pin:
@@ -145,7 +97,8 @@ binary_sensor:
action: light.toggle action: light.toggle
data: data:
entity_id: light.living_room entity_id: light.living_room
- lambda: 'id(nspanel_id).render_default_page();' - lvgl.page.show: page_kitchen_living
- script.execute: wake_screen
- min_length: 500ms - min_length: 500ms
max_length: 2000ms max_length: 2000ms
then: then:
@@ -153,8 +106,8 @@ binary_sensor:
action: light.toggle action: light.toggle
data: data:
entity_id: light.worktop_lights entity_id: light.worktop_lights
- lambda: 'id(nspanel_id).render_default_page();' - lvgl.page.show: page_kitchen
- lambda: 'id(nspanel_id).render_next_page();' - script.execute: wake_screen
- platform: gpio - platform: gpio
name: Right Button name: Right Button
@@ -170,7 +123,8 @@ binary_sensor:
action: light.toggle action: light.toggle
data: data:
entity_id: light.dining_table entity_id: light.dining_table
- lambda: 'id(nspanel_id).render_default_page();' - lvgl.page.show: page_kitchen_living
- script.execute: wake_screen
- min_length: 500ms - min_length: 500ms
max_length: 2000ms max_length: 2000ms
then: then:
@@ -178,8 +132,8 @@ binary_sensor:
action: light.toggle action: light.toggle
data: data:
entity_id: light.mcu_kitchen_stove entity_id: light.mcu_kitchen_stove
- lambda: 'id(nspanel_id).render_default_page();' - lvgl.page.show: page_kitchen
- lambda: 'id(nspanel_id).render_next_page();' - script.execute: wake_screen
switch: switch:
- platform: gpio - platform: gpio
+37 -53
View File
@@ -17,7 +17,10 @@ substitutions:
device: nspanel-office-j device: nspanel-office-j
name: Office J NSPanel name: Office J NSPanel
area: Office J area: Office J
comment: NSPanel comment: NSPanel (nspanel-terminal)
brightness: "80"
# backlight after 15 s idle
dim_brightness: "20"
esphome: esphome:
name: mcu-${device} name: mcu-${device}
@@ -28,62 +31,44 @@ esphome:
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml ipv6_only: !include common/ipv6_only.yaml
nspanel: !include panel: !include
file: common/nspanel.yaml file: common/nspanel_terminal/panel.yaml
vars: vars:
temperature_entity: sensor.zigbee_office_j_temperature temperature_entity: sensor.zigbee_office_j_temperature
ntc_reference_temperature: 22°C ntc_reference_temperature: 22°C
first_page: page_office
last_page: page_thermostat
sleep_dim: !include sleep_dim: !include
file: common/nspanel_sleep_dim.yaml file: common/nspanel_terminal/sleep_dim.yaml
vars: vars:
sleep_override_entity: light.office_j_lights sleep_override_entity: light.office_j_lights
# Grid page tiles: each package adds its tile to the page and fills it in this order
# Janko
l_office: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_office, id: l_office, name: "Svetlo", entity: light.mcu_nspanel_office_j_light, icon: "\U000F091D", dim: false, kmin: 0, hs: false}}
l_bedside: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_office, id: l_bedside, name: "Nočná lampa", entity: light.bedside_left, icon: "\U000F06B5", dim: true, kmin: 1700, hs: true}}
# Brána, robot -> page_gate_auto
gate_open: !include {file: common/nspanel_terminal/action_tile.yaml, vars: {page: page_gate, id: gate_open, name: "Otvoriť", icon: "\U000F116A", action: button.press, entity: button.mcu_gate_open}}
gate_close: !include {file: common/nspanel_terminal/action_tile.yaml, vars: {page: page_gate, id: gate_close, name: "Zatvoriť", icon: "\U000F0299", action: button.press, entity: button.mcu_gate_close}}
gate_spacer: !include {file: common/nspanel_terminal/spacer_tile.yaml, vars: {page: page_gate}}
gate: !include {file: common/nspanel_terminal/gate.yaml, vars: {page: page_gate, state: select.mcu_gate_state}}
gate_auto: !include {file: common/nspanel_terminal/nav_tile.yaml, vars: {page: page_gate, to: page_gate_auto, icon: "\U000F06A9"}}
gate_auto_open: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_gate_auto, id: gate_auto_open, name: "Auto-otváranie", entity: switch.mcu_gate_auto_open, icon: "\U000F1169", domain: switch}}
gate_auto_close: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_gate_auto, id: gate_auto_close, name: "Auto-zatváranie", entity: switch.mcu_gate_auto_close, icon: "\U000F17F7", domain: switch}}
# Kúrenie
thermo: !include {file: common/nspanel_terminal/thermostat.yaml, vars: {id: thermo, page: page_thermostat, title: "Kúrenie - Janko", prev: page_gate, next: page_status, entity: climate.bt_trv_office_j}}
# home page icons, right to left
i_fire: !include common/nspanel_terminal/fireplace_icon.yaml
i_radiator: !include {file: common/nspanel_terminal/radiator_icon.yaml, vars: {id: i_radiator, entity: climate.bt_trv_office_j}}
nspanel_lovelace: # the grid pages; home, status and light detail come from panel.yaml, thermostat pages from thermostat.yaml
cards: lvgl:
- type: cardGrid pages:
title: Janko - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_office, title: "Janko", prev: page_home, next: page_gate, skip: false}}
entities: - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_gate, title: "Brána", prev: page_office, next: page_thermostat, skip: false}}
- name: Svetlo - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_gate_auto, title: "Automatizácia brány", prev: page_gate, next: page_gate, skip: true}}
entity_id: light.mcu_nspanel_office_j_light
icon: wall-sconce-flat
- name: Nočná lampa
entity_id: light.bedside_left
icon: lamp
- type: cardGrid
title: Brána
entities:
- name: Otvoriť
entity_id: button.mcu_gate_open
icon: gate-open
- name: Zatvoriť
entity_id: button.mcu_gate_close
icon: gate
- name: Automatizácia
entity_id: navigate.card_gate_automation
- type: cardThermo
title: Kúrenie
thermo_entity_id: climate.bt_trv_office_j
- type: cardEntities
title: Automatizácia
id: card_gate_automation
hidden: true
entities:
- name: Auto-otváranie
entity_id: switch.gate_auto_open
- name: Auto-zatváranie
entity_id: switch.gate_auto_close
- type: cardEntities
title: Info
entities:
- name: Zariadenie
entity_id: button.office_j_nspanel_info
icon: information-outline
binary_sensor: binary_sensor:
# both buttons show the Janko page, where the change is visible
- platform: gpio - platform: gpio
name: Left Button name: Left Button
pin: pin:
@@ -91,7 +76,8 @@ binary_sensor:
inverted: true inverted: true
on_click: on_click:
- light.toggle: light_1 - light.toggle: light_1
- lambda: 'id(nspanel_id).render_default_page();' - lvgl.page.show: page_office
- script.execute: wake_screen
- platform: gpio - platform: gpio
name: Right Button name: Right Button
@@ -103,7 +89,8 @@ binary_sensor:
action: light.toggle action: light.toggle
data: data:
entity_id: light.bedside_left entity_id: light.bedside_left
- lambda: 'id(nspanel_id).render_default_page();' - lvgl.page.show: page_office
- script.execute: wake_screen
output: output:
- id: relay_1 - id: relay_1
@@ -121,6 +108,3 @@ light:
id: light_1 id: light_1
output: relay_1 output: relay_1
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
# # - platform: binary
# # name: Relay 2
# # output: relay_2
+40 -61
View File
@@ -17,7 +17,10 @@ substitutions:
device: nspanel-office-r device: nspanel-office-r
name: Office R NSPanel name: Office R NSPanel
area: Office R area: Office R
comment: NSPanel comment: NSPanel (nspanel-terminal)
brightness: "80"
# backlight after 15 s idle
dim_brightness: "20"
esphome: esphome:
name: mcu-${device} name: mcu-${device}
@@ -28,11 +31,40 @@ esphome:
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml ipv6_only: !include common/ipv6_only.yaml
nspanel: !include panel: !include
file: common/nspanel.yaml file: common/nspanel_terminal/panel.yaml
vars: vars:
temperature_entity: sensor.zigbee_office_r_temperature temperature_entity: sensor.zigbee_office_r_temperature
ntc_reference_temperature: 22°C ntc_reference_temperature: 22°C
first_page: page_office
last_page: page_thermostat
# Grid page tiles: each package adds its tile to the page and fills it in this order
# Romanko
l_office: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_office, id: l_office, name: "Svetlo", entity: light.mcu_nspanel_office_r_light, icon: "\U000F0769", dim: false, kmin: 0, hs: false}}
l_strip: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_office, id: l_strip, name: "LED pásik", entity: light.office_r_desk_strip, icon: "\U000F1051", dim: true, kmin: 1700, hs: true}}
office_spacer: !include {file: common/nspanel_terminal/spacer_tile.yaml, vars: {page: page_office}}
l_monitor: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_office, id: l_monitor, name: "Monitor", entity: light.office_r_display_lamp, icon: "\U000F0379", dim: true, kmin: 2700, hs: false}}
l_monitor_amb: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_office, id: l_monitor_amb, name: "(Monitor)", entity: light.office_r_display_lamp_ambilight, icon: "\U000F1051", dim: true, kmin: 1700, hs: true}}
# Brána, robot -> page_gate_auto
gate_open: !include {file: common/nspanel_terminal/action_tile.yaml, vars: {page: page_gate, id: gate_open, name: "Otvoriť", icon: "\U000F116A", action: button.press, entity: button.mcu_gate_open}}
gate_close: !include {file: common/nspanel_terminal/action_tile.yaml, vars: {page: page_gate, id: gate_close, name: "Zatvoriť", icon: "\U000F0299", action: button.press, entity: button.mcu_gate_close}}
gate_spacer: !include {file: common/nspanel_terminal/spacer_tile.yaml, vars: {page: page_gate}}
gate: !include {file: common/nspanel_terminal/gate.yaml, vars: {page: page_gate, state: select.mcu_gate_state}}
gate_auto: !include {file: common/nspanel_terminal/nav_tile.yaml, vars: {page: page_gate, to: page_gate_auto, icon: "\U000F06A9"}}
gate_auto_open: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_gate_auto, id: gate_auto_open, name: "Auto-otváranie", entity: switch.mcu_gate_auto_open, icon: "\U000F1169", domain: switch}}
gate_auto_close: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_gate_auto, id: gate_auto_close, name: "Auto-zatváranie", entity: switch.mcu_gate_auto_close, icon: "\U000F17F7", domain: switch}}
# Kúrenie
thermostat: !include {file: common/nspanel_terminal/thermostat.yaml, vars: {id: thermo, page: page_thermostat, title: "Kúrenie - Romanko", prev: page_gate, next: page_status, entity: climate.bt_trv_office_r}}
# home page icons, right to left
i_fire: !include common/nspanel_terminal/fireplace_icon.yaml
i_radiator: !include {file: common/nspanel_terminal/radiator_icon.yaml, vars: {id: i_radiator, entity: climate.bt_trv_office_r}}
# the grid pages; home, status and light detail come from panel.yaml, the thermostat page from thermostat.yaml
lvgl:
pages:
- <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_office, title: "Romanko", prev: page_home, next: page_gate, skip: false}}
- <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_gate, title: "Brána", prev: page_office, next: page_thermostat, skip: false}}
- <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_gate_auto, title: "Automatizácia brány", prev: page_gate, next: page_gate, skip: true}}
script: script:
- id: geiger_click - id: geiger_click
@@ -51,59 +83,8 @@ script:
return esphome::random_uint32() % 450 + 50; return esphome::random_uint32() % 450 + 50;
- script.execute: geiger_click - script.execute: geiger_click
nspanel_lovelace:
cards:
- type: cardGrid
title: Romanko
entities:
- name: Svetlo
entity_id: light.mcu_nspanel_office_r_light
icon: wall-sconce-flat
- name: LED pásik
entity_id: light.office_r_desk_strip
icon: led-strip-variant
- entity_id: delete
- name: Monitor
entity_id: light.office_r_display_lamp
icon: monitor-star
- name: (Monitor)
entity_id: light.office_r_display_lamp_ambilight
icon: monitor-star
- type: cardGrid
title: Brána
entities:
- name: Otvoriť
entity_id: button.mcu_gate_open
icon: gate-open
- name: Zatvoriť
entity_id: button.mcu_gate_close
icon: gate
- name: Automatizácia
entity_id: navigate.card_gate_automation
- type: cardThermo
title: Kúrenie
thermo_entity_id: climate.bt_trv_office_r
- type: cardEntities
title: Automatizácia
id: card_gate_automation
hidden: true
entities:
- name: Auto-otváranie
entity_id: switch.gate_auto_open
- name: Auto-zatváranie
entity_id: switch.gate_auto_close
- type: cardEntities
title: Info
entities:
- name: Zariadenie
entity_id: button.office_r_nspanel_info
icon: information-outline
binary_sensor: binary_sensor:
# both buttons show the Romanko page, where the change is visible
- platform: gpio - platform: gpio
name: Left Button name: Left Button
pin: pin:
@@ -114,7 +95,8 @@ binary_sensor:
action: light.toggle action: light.toggle
data: data:
entity_id: light.office_r_desk_strip entity_id: light.office_r_desk_strip
- lambda: 'id(nspanel_id).render_default_page();' - lvgl.page.show: page_office
- script.execute: wake_screen
- platform: gpio - platform: gpio
name: Right Button name: Right Button
@@ -123,17 +105,14 @@ binary_sensor:
inverted: true inverted: true
on_click: on_click:
- light.toggle: light_1 - light.toggle: light_1
- lambda: 'id(nspanel_id).render_default_page();' - lvgl.page.show: page_office
- script.execute: wake_screen
output: output:
- id: relay_1 - id: relay_1
platform: gpio platform: gpio
pin: pin:
number: 22 number: 22
# - id: relay_2
# platform: gpio
# pin:
# number: 19
light: light:
- platform: esp32_rmt_led_strip - platform: esp32_rmt_led_strip
+64 -141
View File
@@ -17,7 +17,10 @@ substitutions:
device: nspanel-patio device: nspanel-patio
name: Patio NSPanel name: Patio NSPanel
area: Living Room & Kitchen area: Living Room & Kitchen
comment: ${area}, Patio | NSPanel comment: ${area}, Patio | NSPanel (nspanel-terminal)
brightness: "80"
# backlight after 15 s idle
dim_brightness: "20"
esphome: esphome:
name: mcu-${device} name: mcu-${device}
@@ -28,140 +31,68 @@ esphome:
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml ipv6_only: !include common/ipv6_only.yaml
nspanel: !include panel: !include
file: common/nspanel.yaml file: common/nspanel_terminal/panel.yaml
vars: vars:
temperature_entity: sensor.zigbee_living_room_kitchen_temperature temperature_entity: sensor.zigbee_living_room_kitchen_temperature
temperature_name: Living Room Temperature temperature_name: Living Room Temperature
first_page: page_kitchen_living
last_page: page_thermostat
# Grid page tiles: each package adds its tile to the page and fills it in this order
# Kuchyňa / Obývačka
l_kitchen: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen_living, id: l_kitchen, name: "Kuchyňa", entity: light.kitchen, icon: "\U000F0769", dim: true, kmin: 2700, hs: false}}
l_dining: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen_living, id: l_dining, name: "Stôl", entity: light.dining_table, icon: "\U000F0769", dim: true, kmin: 2700, hs: false}}
l_living: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen_living, id: l_living, name: "Gauč", entity: light.living_room, icon: "\U000F0769", dim: true, kmin: 2700, hs: false}}
l_tv: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen_living, id: l_tv, name: "TV", entity: light.mcu_tv_light_strip, icon: "\U000F1051", dim: true, kmin: 0, hs: false}}
l_dining_amb: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen_living, id: l_dining_amb, name: "(Stôl)", entity: light.dining_table_ambilight, icon: "\U000F18DE", dim: true, kmin: 1700, hs: true}}
l_living_amb: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen_living, id: l_living_amb, name: "(Gauč)", entity: light.living_room_ambilight, icon: "\U000F18DE", dim: true, kmin: 1700, hs: true}}
# Kuchyňa
l_worktop: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen, id: l_worktop, name: "Linka", entity: light.worktop_lights, icon: "\U000F181C", dim: true, kmin: 2000, hs: false}}
l_stove: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_kitchen, id: l_stove, name: "Sporák", entity: light.mcu_kitchen_stove, icon: "\U000F04DE", dim: true, kmin: 2000, hs: false}}
# Von
l_patio: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_outside, id: l_patio, name: "Terasa", entity: light.patio_lights, icon: "\U000F1253", dim: true, kmin: 2000, hs: false}}
s_patio_socket: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_patio_socket, name: "Terasa", entity: switch.mcu_patio_relay, icon: "\U000F1108", domain: switch}}
s_patio_back: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_patio_back, name: "Vzadu", entity: switch.mcu_nspanel_patio_outside_light_back, icon: "\U000F1987", domain: switch}}
s_shed_light: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_shed_light, name: "Z. domček", entity: switch.mcu_shed_light, icon: "\U000F091D", domain: switch}}
s_shed_socket: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_shed_socket, name: "Z. domček", entity: switch.mcu_shed_socket, icon: "\U000F1108", domain: switch}}
s_garden: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_outside, id: s_garden, name: "Záhrada", entity: switch.mcu_shed_garden_light, icon: "\U000F1987", domain: switch}}
# Závlaha, robot -> page_irrigation_auto
v_a1: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation, id: v_a1, name: "A1", entity: switch.mcu_well_irrigation_valve_a1, icon: "\U000F1066", domain: switch}}
v_a2: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation, id: v_a2, name: "A2", entity: switch.mcu_well_irrigation_valve_a2, icon: "\U000F1066", domain: switch}}
v_a3: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation, id: v_a3, name: "A3", entity: switch.mcu_well_irrigation_valve_a3, icon: "\U000F1066", domain: switch}}
v_a4: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation, id: v_a4, name: "A4", entity: switch.mcu_well_irrigation_valve_a4, icon: "\U000F1066", domain: switch}}
v_a5: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation, id: v_a5, name: "A5", entity: switch.mcu_well_irrigation_valve_a5, icon: "\U000F1066", domain: switch}}
irrigation_auto: !include {file: common/nspanel_terminal/nav_tile.yaml, vars: {page: page_irrigation, to: page_irrigation_auto, icon: "\U000F06A9"}}
ir_morning: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation_auto, id: ir_morning, name: "Ráno", entity: automation.irrigation_morning, icon: "\U000F059C", domain: automation}}
ir_patio: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation_auto, id: ir_patio, name: "Terasa", entity: automation.irrigation_patio, icon: "\U000F024A", domain: automation}}
ir_grass: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation_auto, id: ir_grass, name: "Rast trávy", entity: automation.irrigation_grow_grass, icon: "\U000F1510", domain: automation}}
# Brána, robot -> page_gate_auto
gate_open: !include {file: common/nspanel_terminal/action_tile.yaml, vars: {page: page_gate, id: gate_open, name: "Otvoriť", icon: "\U000F116A", action: button.press, entity: button.mcu_gate_open}}
gate_close: !include {file: common/nspanel_terminal/action_tile.yaml, vars: {page: page_gate, id: gate_close, name: "Zatvoriť", icon: "\U000F0299", action: button.press, entity: button.mcu_gate_close}}
gate_spacer: !include {file: common/nspanel_terminal/spacer_tile.yaml, vars: {page: page_gate}}
gate: !include {file: common/nspanel_terminal/gate.yaml, vars: {page: page_gate, state: select.mcu_gate_state}}
gate_auto: !include {file: common/nspanel_terminal/nav_tile.yaml, vars: {page: page_gate, to: page_gate_auto, icon: "\U000F06A9"}}
gate_auto_open: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_gate_auto, id: gate_auto_open, name: "Auto-otváranie", entity: switch.mcu_gate_auto_open, icon: "\U000F1169", domain: switch}}
gate_auto_close: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_gate_auto, id: gate_auto_close, name: "Auto-zatváranie", entity: switch.mcu_gate_auto_close, icon: "\U000F17F7", domain: switch}}
# Kúrenie
thermo: !include {file: common/nspanel_terminal/thermostat.yaml, vars: {id: thermo, page: page_thermostat, title: "Kúrenie - Obývačka", prev: page_gate, next: page_status, entity: climate.bt_trv_living_room_kitchen}}
# home page icons, right to left
i_fire: !include common/nspanel_terminal/fireplace_icon.yaml
i_radiator: !include {file: common/nspanel_terminal/radiator_icon.yaml, vars: {id: i_radiator, entity: climate.bt_trv_living_room_kitchen}}
nspanel_lovelace: # the grid pages; home, status and light detail come from panel.yaml, thermostat pages from thermostat.yaml
cards: lvgl:
- type: cardGrid pages:
title: Kuchyňa / Obývačka - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_kitchen_living, title: "Kuchyňa / Obývačka", prev: page_home, next: page_kitchen, skip: false}}
id: card_home - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_kitchen, title: "Kuchyňa", prev: page_kitchen_living, next: page_outside, skip: false}}
entities: - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_outside, title: "Von", prev: page_kitchen, next: page_irrigation, skip: false}}
- name: Kuchyňa / Obývačka - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_irrigation, title: "Závlaha", prev: page_outside, next: page_gate, skip: false}}
entity_id: light.kitchen - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_irrigation_auto, title: "Automatizácia závlahy", prev: page_irrigation, next: page_irrigation, skip: true}}
icon: ceiling-light - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_gate, title: "Brána", prev: page_irrigation, next: page_thermostat, skip: false}}
- name: Stôl - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_gate_auto, title: "Automatizácia brány", prev: page_gate, next: page_gate, skip: true}}
entity_id: light.dining_table
icon: ceiling-light
- name: Gauč
entity_id: light.living_room
icon: ceiling-light
- name: TV
entity_id: light.mcu_tv_light_strip
icon: led-strip-variant
- name: (Stôl)
entity_id: light.dining_table_ambilight
icon: ceiling-light-multiple-outline
- name: (Gauč)
entity_id: light.living_room_ambilight
icon: ceiling-light-multiple-outline
- type: cardGrid
title: Kuchyňa
entities:
- name: Linka
entity_id: light.worktop_lights
icon: countertop
- name: Sporák
entity_id: light.mcu_kitchen_stove
icon: stove
- type: cardGrid
title: Von
id: card_outside
entities:
- name: Terasa
entity_id: light.patio_lights
icon: lightbulb-group
- name: Terasa
entity_id: switch.mcu_patio_relay
icon: power-socket-fr
- name: Vzadu
entity_id: switch.mcu_nspanel_patio_outside_light_back
icon: light-flood-down
- name: Z. domček
entity_id: switch.mcu_shed_light
icon: wall-sconce-flat
# state_template: '{{ is_state("binary_sensor.shed_status", "off") }}'
- name: Z. domček
entity_id: switch.mcu_shed_socket
icon: power-socket-fr
# state_template: '{{ is_state("binary_sensor.shed_status", "off") }}'
- name: Záhrada
entity_id: switch.mcu_shed_garden_light
icon: light-flood-down
# state_template: '{{ is_state("binary_sensor.shed_status", "off") }}'
- type: cardGrid
title: Závlaha
entities:
- name: A1
entity_id: switch.mcu_well_irrigation_valve_a1
icon: valve
- name: A2
entity_id: switch.mcu_well_irrigation_valve_a2
icon: valve
- name: A3
entity_id: switch.mcu_well_irrigation_valve_a3
icon: valve
- name: A4
entity_id: switch.mcu_well_irrigation_valve_a4
icon: valve
- name: A5
entity_id: switch.mcu_well_irrigation_valve_a5
icon: valve
- name: Automatizácia
entity_id: navigate.card_irrigation_automation
- type: cardGrid
title: Brána
entities:
- name: Otvoriť
entity_id: button.mcu_gate_open
icon: gate-open
- name: Zatvoriť
entity_id: button.mcu_gate_close
icon: gate
- name: Automatizácia
entity_id: navigate.card_gate_automation
- type: cardThermo
title: Kúrenie
thermo_entity_id: climate.bt_trv_living_room_kitchen
- type: cardEntities
title: Automatizácia
id: card_gate_automation
hidden: true
entities:
- name: Auto-otváranie
entity_id: switch.gate_auto_open
- name: Auto-zatváranie
entity_id: switch.gate_auto_close
- type: cardEntities
title: Automatizácia
id: card_irrigation_automation
hidden: true
entities:
- name: Ráno
entity_id: automation.irrigation_morning
- name: Terasa
entity_id: automation.irrigation_patio
- name: Rast trávy
entity_id: automation.irrigation_grow_grass
- type: cardEntities
title: Info
entities:
- name: Zariadenie
entity_id: button.patio_nspanel_info
icon: information-outline
binary_sensor: binary_sensor:
# both buttons show the Von page, where the change is visible
- platform: gpio - platform: gpio
name: Left Button name: Left Button
pin: pin:
@@ -169,7 +100,8 @@ binary_sensor:
inverted: true inverted: true
on_click: on_click:
- switch.toggle: relay_1 - switch.toggle: relay_1
- script.execute: show_outside_card - lvgl.page.show: page_outside
- script.execute: wake_screen
- platform: gpio - platform: gpio
name: Right Button name: Right Button
@@ -188,7 +120,8 @@ binary_sensor:
action: light.toggle action: light.toggle
data: data:
entity_id: light.patio_lights entity_id: light.patio_lights
- script.execute: show_outside_card - lvgl.page.show: page_outside
- script.execute: wake_screen
else: else:
- switch.toggle: relay_2 - switch.toggle: relay_2
@@ -210,13 +143,3 @@ switch:
entity_category: config entity_category: config
pin: pin:
number: 19 number: 19
script:
# jump straight to the "Von" card (one render instead of home + next + next):
# make it the default page for a moment, render it, restore the home card
- id: show_outside_card
then:
- lambda: |-
id(nspanel_id).set_default_page("card_outside");
id(nspanel_id).render_default_page();
id(nspanel_id).set_default_page("card_home");
+2 -1
View File
@@ -30,12 +30,13 @@ esp32:
framework: framework:
type: esp-idf type: esp-idf
advanced: advanced:
flash_chip: gd # same device as pow-dishwasher (not read from the device) flash_chip: gd
minimum_chip_revision: 3.1 minimum_chip_revision: 3.1
sram1_as_iram: true sram1_as_iram: true
packages: packages:
common: !include common/common.yaml common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml
uart: uart:
- id: cse7766_uart - id: cse7766_uart
+1 -1
View File
@@ -47,7 +47,7 @@ packages:
external_components: external_components:
- source: github://randybb/esphome-components - source: github://randybb/esphome-components
components: [pn5180, openprinttag, creality_cfs] components: [pn5180, openprinttag, creality_cfs]
refresh: 1h refresh: 0h
# Called by the OpenPrintTag integration (openprinttag.update) to update the aux region # Called by the OpenPrintTag integration (openprinttag.update) to update the aux region
api: api:
+368 -119
View File
@@ -35,8 +35,10 @@
# 0x40 es7210_adc (audio_adc es7210) # 0x40 es7210_adc (audio_adc es7210)
# 0x41 sensor ina226 (sensor ina226) # 0x41 sensor ina226 (sensor ina226)
# 0x51 rtc_time (time bm8563) # 0x51 rtc_time (time bm8563)
# 0x50 nfc_reader (st25r_i2c)
# 0x58 aw9523b_hub (aw9523b) # 0x58 aw9523b_hub (aw9523b)
# 0x68 touch_hub (si12t) # 0x68 touch_hub (si12t)
# 0x69 imu (motion bmi270)
# 0x6F m5ioe1_hub (m5ioe1) # 0x6F m5ioe1_hub (m5ioe1)
substitutions: substitutions:
device: stackchan device: stackchan
@@ -50,6 +52,20 @@ esphome:
area: ${area} area: ${area}
comment: ${comment} comment: ${comment}
on_boot: on_boot:
# the 5 V BUS after the expander parked its pins low (HARDWARE) and before si12t/st25r probe it (DATA)
- 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 - priority: -100
then: then:
- light.turn_on: - light.turn_on:
@@ -69,6 +85,11 @@ esp32:
advanced: advanced:
flash_chip: generic flash_chip: generic
type: esp-idf 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: psram:
mode: quad mode: quad
@@ -79,36 +100,27 @@ packages:
ipv6_only: !include common/ipv6_only.yaml ipv6_only: !include common/ipv6_only.yaml
external_components: external_components:
- source: github://m5stack/esphome-yaml/components - source: github://m5stack/esphome-yaml
components: [axp2101, aw88298, aw9523b, si12t, m5ioe1, ftservo, scs9009] components: [axp2101, aw88298, aw9523b, si12t, ftservo, scs9009]
refresh: 0s refresh: 0s
- source: github://randybb/esphome-components - source: github://randybb/esphome-components
components: [audio_spectrum] components: [audio_spectrum, m5ioe1, robot_face]
refresh: 1h refresh: 1h
# st25r upstream has SPI only, st25r_i2c is still on this branch
- source: github://m5stack/esphome@feat-st25r3916
components: [st25r, st25r_i2c]
refresh: 1d
globals: globals:
- id: in_love
type: bool
initial_value: 'false'
- id: show_status - id: show_status
type: bool type: bool
initial_value: 'true' 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 - id: listening
type: bool type: bool
initial_value: 'false' initial_value: 'false'
- id: gaze_x - id: speech
type: int type: std::string
initial_value: '0' - id: spin_limits # yaw servo angle limits while spinning: max << 16 | min
- id: gaze_y
type: int type: int
initial_value: '0' initial_value: '0'
@@ -178,7 +190,7 @@ switch:
pin: pin:
aw9523b_id: aw9523b_hub aw9523b_id: aw9523b_hub
number: 15 number: 15
restore_mode: RESTORE_DEFAULT_ON restore_mode: ALWAYS_OFF # switched on by bus_power_on
- platform: gpio - platform: gpio
id: usb_otg_en id: usb_otg_en
name: USB OTG name: USB OTG
@@ -194,7 +206,7 @@ switch:
pin: pin:
aw9523b_id: aw9523b_hub aw9523b_id: aw9523b_hub
number: 1 number: 1
restore_mode: RESTORE_DEFAULT_ON restore_mode: ALWAYS_OFF # switched on by bus_power_on
- platform: gpio - platform: gpio
id: light_bar_en id: light_bar_en
internal: true internal: true
@@ -244,7 +256,7 @@ audio_adc:
i2c_id: i2c_bsp i2c_id: i2c_bsp
bits_per_sample: 16bit bits_per_sample: 16bit
sample_rate: 16000 sample_rate: 16000
mic_gain: 36 mic_gain: 24
audio_dac: audio_dac:
- platform: aw88298 - platform: aw88298
@@ -293,7 +305,6 @@ media_player:
- platform: speaker - platform: speaker
id: media_out id: media_out
name: Player name: Player
buffer_size: 14000
# AW88298 maps volume linearly to -96..0 dB, the lower half is inaudible # AW88298 maps volume linearly to -96..0 dB, the lower half is inaudible
volume_min: 0.5 volume_min: 0.5
volume_max: 1.0 volume_max: 1.0
@@ -330,7 +341,8 @@ voice_assistant:
media_player: media_out media_player: media_out
micro_wake_word: mww micro_wake_word: mww
noise_suppression_level: 2 noise_suppression_level: 2
auto_gain: 31dBFS # no extra gain: a raised noise floor keeps the HA VAD from hearing the end of speech
auto_gain: 0dBFS
on_client_connected: on_client_connected:
- micro_wake_word.start: - micro_wake_word.start:
- delay: 2s - delay: 2s
@@ -341,27 +353,33 @@ voice_assistant:
- lambda: id(show_status) = true; - lambda: id(show_status) = true;
- component.update: display_tft - component.update: display_tft
on_listening: on_listening:
# someone talks: a look with one eye, then with both
- lambda: |- - lambda: |-
id(listening) = true; id(listening) = true;
id(gaze_x) = 0; id(face).peek(0);
id(gaze_y) = 0; id(face).look(0, 0);
- component.update: display_tft - component.update: display_tft
- light.turn_on: {id: light_bar, brightness: 60%, red: 0%, green: 60%, blue: 100%} - light.turn_on: {id: light_bar, brightness: 60%, red: 0%, green: 60%, blue: 100%}
on_stt_end: 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 - component.update: display_tft
- light.turn_on: {id: light_bar, brightness: 40%, red: 80%, green: 50%, blue: 0%} - light.turn_on: {id: light_bar, brightness: 40%, red: 80%, green: 50%, blue: 0%}
on_tts_start: 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%} - light.turn_on: {id: light_bar, brightness: 60%, red: 0%, green: 100%, blue: 20%}
on_end: on_end:
- wait_until: - wait_until:
not: not:
media_player.is_announcing: media_out media_player.is_announcing: media_out
- lambda: |- - lambda: |-
id(speaking) = false;
id(listening) = false; id(listening) = false;
id(mouth_open) = 0.0f; id(face).set_speaking(false);
id(face).set_idle(true);
- component.update: display_tft - component.update: display_tft
- light.turn_on: {id: light_bar, brightness: 20%, red: 0%, green: 0%, blue: 100%} - light.turn_on: {id: light_bar, brightness: 20%, red: 0%, green: 0%, blue: 100%}
- wait_until: - wait_until:
@@ -369,25 +387,93 @@ voice_assistant:
- micro_wake_word.start: - micro_wake_word.start:
on_error: on_error:
- light.turn_on: {id: light_bar, brightness: 60%, red: 100%, green: 0%, blue: 0%} - light.turn_on: {id: light_bar, brightness: 60%, red: 100%, green: 0%, blue: 0%}
- script.execute:
id: show_mood
mood: sad
seconds: 3
script: script:
# short tap on the head starts the assistant # Powers the 5 V BUS from the battery (as in m5stack/esphome-yaml stackchan base).
- id: head_tap # The BUS is a capacitive load: switched on at once it pulls a converter under its
# UVP threshold and the AXP2101 powers itself off (red LED, off on battery only).
- id: bus_power_on
then: then:
- if: - lambda: |-
condition: // REG 23H bits 4:0: DCDC1-5 under-voltage power-off, POR value all set
not: voice_assistant.is_running uint8_t reg;
then: if (id(axp2101_pmu)->read_byte(0x23, &reg))
- voice_assistant.start: id(axp2101_pmu)->write_byte(0x23, reg & ~0x1F);
# stroking the head shows the in-love face for a while id(boost_en).turn_on();
- id: head_stroke delay(50);
// eight pulses of growing on-time bring the cold BUS up to a few volts
for (int pulse = 0; pulse < 8; ++pulse) {
id(bus_out_en).turn_on();
delayMicroseconds(pulse * 16);
id(bus_out_en).turn_off();
delayMicroseconds(1000);
}
id(bus_out_en).turn_on();
delay(100);
# a mood for a while, then back to neutral (stroke: love, shake: dizzy, card: surprised)
- id: show_mood
mode: restart mode: restart
parameters:
mood: string
seconds: int
then: then:
- lambda: id(in_love) = true; - lambda: |-
- component.update: display_tft if (id(face).is_sleeping())
- delay: 5s id(face).peek(0);
- lambda: id(in_love) = false; id(face).set_mood(mood);
- component.update: display_tft - 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: |-
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
parameters:
message: string
then:
- lambda: |-
id(speech) = message;
id(face).set_speaking(true);
- delay: 8s
- lambda: |-
id(speech).clear();
id(face).set_speaking(false);
# mic and speaker share one I2S bus - the mic must be released before playback # mic and speaker share one I2S bus - the mic must be released before playback
- id: release_i2s_bus - id: release_i2s_bus
mode: single mode: single
@@ -410,6 +496,41 @@ script:
timeout: 2s timeout: 2s
interval: 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 - interval: 80ms # spectrum analyzer frame rate while music plays
then: then:
- if: - if:
@@ -420,21 +541,37 @@ interval:
then: then:
- component.update: display_tft - component.update: display_tft
# head touch gestures: a touch episode ends after 250 ms without contact; # head touch gestures: a touch episode ends after 250 ms without contact;
# tap = short episode, stroke = longer episode that reaches the pads one after another # stroke = longer episode that reaches the pads one after another (taps do nothing).
# Each ST25R scan switches its RF field on and the pads report a 50-350 ms phantom touch, at any
# si12t sensitivity, so the NFC reader is scanned from here: every 2 s between episodes, with the
# pads ignored for 400 ms afterwards, and at once when an episode starts (a card being laid on).
- interval: 50ms - interval: 50ms
then: then:
- lambda: |- - lambda: |-
static bool active = false; static bool active = false;
static uint32_t start = 0, last_on = 0; static uint32_t start = 0, last_on = 0, last_scan = 0;
static uint32_t first_on[3]; static uint32_t first_on[3];
const uint32_t now = millis();
if (!active) {
if (now - last_scan >= 2000 && id(nfc_reader).is_ready()) {
last_scan = now;
id(nfc_reader).update();
return;
}
if (now - last_scan < 400)
return;
}
const bool on[3] = {id(head_touch_1).state != "No touch", id(head_touch_2).state != "No touch", const bool on[3] = {id(head_touch_1).state != "No touch", id(head_touch_2).state != "No touch",
id(head_touch_3).state != "No touch"}; id(head_touch_3).state != "No touch"};
const uint32_t now = millis();
if (on[0] || on[1] || on[2]) { if (on[0] || on[1] || on[2]) {
if (!active) { if (!active) {
active = true; active = true;
start = now; start = now;
if (id(nfc_reader).is_ready()) {
last_scan = now;
id(nfc_reader).update();
}
first_on[0] = first_on[1] = first_on[2] = 0; first_on[0] = first_on[1] = first_on[2] = 0;
} }
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
@@ -463,9 +600,7 @@ interval:
first_on[1] ? (int) (first_on[1] - earliest) : -1, first_on[2] ? (int) (first_on[2] - earliest) : -1); 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) { if (pads >= 2 && spread >= 150 && duration >= 400) {
id(head_stroke).execute(); id(show_mood).execute(std::string("love"), 5);
} else if (duration <= 600) {
id(head_tap).execute();
} }
- interval: 1s # status screen refresh until Home Assistant connects - interval: 1s # status screen refresh until Home Assistant connects
then: then:
@@ -474,32 +609,6 @@ interval:
lambda: return id(show_status); lambda: return id(show_status);
then: then:
- component.update: display_tft - 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: spi:
- id: spi_bus - id: spi_bus
@@ -627,29 +736,26 @@ display:
return; 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 // 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 // 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(); 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 // switching between face and spectrum repaints everything
static int last_mode = -1; static bool last_music = false;
const int mode = music ? 2 : love ? 1 : 0; if (music != last_music) {
if (mode != last_mode) { last_music = music;
last_mode = mode;
first_draw = true; first_draw = true;
} }
// the in-love face is drawn outside the partially cleared areas, so it always repaints everything
static bool spectrum_reset = true; static bool spectrum_reset = true;
if (first_draw || love) { if (first_draw) {
it.fill(id(face_bg)); it.fill(id(face_bg));
id(face).invalidate();
first_draw = false; first_draw = false;
bar_drawn = false; bar_drawn = false;
spectrum_reset = true; spectrum_reset = true;
} else if (!music) { } else if (!music) {
it.filled_rectangle(70, 78, 181, 31, id(face_bg)); // eyes including gaze range it.filled_rectangle(0, 216, 320, 22, id(face_bg)); // speech text
it.filled_rectangle(105, 130, 111, 38, id(face_bg)); // mouth
if (dot_shown && !id(listening)) { if (dot_shown && !id(listening)) {
it.filled_rectangle(254, 2, 28, 28, id(face_bg)); it.filled_rectangle(254, 2, 28, 28, id(face_bg));
} }
@@ -742,42 +848,140 @@ display:
return; return;
} }
const int ex = id(gaze_x), ey = id(gaze_y); id(face).draw(it);
const int eye_y = 93 + ey, eye_r = 8;
const int lx = 90 + ex, rx = 230 + ex;
if (love) { if (!id(speech).empty()) {
// heart eyes, blush and a wide smile it.print(160, 218, id(font_status), id(face_fg), TextAlign::TOP_CENTER, id(speech).c_str());
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(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 (!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));
} }
if (id(listening)) { if (id(listening)) {
it.image(254, 2, id(icon_listening), id(face_fg), id(face_bg)); // left of the wifi bars 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
i2c_id: i2c_bsp
address: 0x69
update_interval: 50ms
accelerometer_range: 4G
accelerometer_odr: 100HZ
event:
- platform: motion
id: imu_shake
name: Shake
threshold: 1.5
cooldown: 500ms
on_event:
- script.execute:
id: show_mood
mood: dizzy
seconds: 3
st25r_i2c:
id: nfc_reader
i2c_id: i2c_bsp
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:
id: show_mood
mood: surprised
seconds: 3
- text_sensor.template.publish:
id: nfc_tag
state: !lambda return x;
on_tag_removed:
- lambda: id(speech).clear();
- component.update: display_tft
- text_sensor.template.publish:
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:
output_power: 11dB
api:
actions:
- action: stackchan_say
variables:
message: string
then:
- script.execute:
id: say
message: !lambda return message;
- action: stackchan_pet
then:
- 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:
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: touchscreen:
- platform: ft63x6 - platform: ft63x6
id: touch_lcd id: touch_lcd
@@ -814,6 +1018,25 @@ esp32_camera:
frame_buffer_location: PSRAM frame_buffer_location: PSRAM
sensor: 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 - platform: axp2101
id: axp2101_sensor id: axp2101_sensor
battery_level: battery_level:
@@ -860,6 +1083,10 @@ si12t:
intr_level: OUTPUT_ALL intr_level: OUTPUT_ALL
text_sensor: text_sensor:
- platform: template
id: nfc_tag
name: NFC Tag
icon: mdi:nfc
- platform: si12t - platform: si12t
id: head_touch_1 id: head_touch_1
name: Head Touch 1 name: Head Touch 1
@@ -903,16 +1130,38 @@ ftservo:
id: y_servo id: y_servo
address: 2 address: 2
button:
- platform: template
name: Spin
icon: mdi:rotate-360
on_press:
- script.execute:
id: spin
seconds: 3
power: 600
number: number:
- platform: ftservo - platform: ftservo
ftservo_id: x_servo ftservo_id: x_servo
# yaw: 0 = straight ahead = raw 461 (measured), 2.844 steps per degree
angle: angle:
id: servo_x_angle id: servo_x_angle
name: Servo X Angle name: Servo X Angle
min_value: -164 min_value: -160
max_value: 164 max_value: 160
use_raw_angle: false 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 step: 5
light: light:
+79
View File
@@ -0,0 +1,79 @@
---
# Hardware: WeAct Black Pill STM32F401CCU6 (256K flash, no radio)
# Pinout:
# PA11/PA12 USB-C -> logger (USB CDC), flashing via ROM DFU (hold BOOT0, tap NRST)
# PC13 blue LED (active low) -> LED (light binary)
# PA0 KEY (active low) -> Button (binary_sensor gpio)
esphome:
name: mcu-stm32-blackpill
friendly_name: STM32 Black Pill
# needs the esphomeplatformzephyr fork (esphome-zephyr), upstream has no stm32: platform yet
stm32:
variant: STM32F4
board: blackpill_f401cc
framework:
type: zephyr
advanced:
runner: dfu-util
# no network, so no OTA: one image slot, MCUboot only verifies and boots it
single_slot: true
# NVS sector = flash page; needs >= 2 of them, so storage takes the two 16K pages (sectors 2-3)
kconfig_options:
SETTINGS_NVS_SECTOR_COUNT: 2
# the stock table puts slot1 at 0x40000, past the end of the 256K flash;
# MCUboot in sectors 0-1, storage in 2-3, the app in 4-5.
# MCUboot needs the same table; the fork appends its own code-partition = &boot_partition after it
overlays:
app: &partitions |
&flash0 {
/delete-node/ partitions;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(32)>;
read-only;
};
storage_partition: partition@8000 {
label = "storage";
reg = <0x00008000 DT_SIZE_K(32)>;
};
slot0_partition: partition@10000 {
label = "image-0";
reg = <0x00010000 DT_SIZE_K(192)>;
};
};
};
/ { chosen { zephyr,code-partition = &slot0_partition; }; };
mcuboot: *partitions
logger:
hardware_uart: USB_CDC
output:
- platform: gpio
id: led_out
pin:
number: PC13
inverted: true
light:
- platform: binary
name: LED
id: led
output: led_out
binary_sensor:
- platform: gpio
name: Button
pin:
number: PA0
inverted: true
mode:
input: true
pullup: true
on_press:
light.toggle: led
+75
View File
@@ -0,0 +1,75 @@
---
# Hardware: CZ miniSTM32F103ZE-EK (STM32F103ZET6, 512K flash, no radio), external ST-LINK/V2 on SWD
# Pinout:
# PA9/PA10 USART1 TX/RX -> PL-2303 on mini-USB CN3 (logger)
# PE2 DS2 (active low) -> LED (light binary)
# PB10 K1 (active low) -> Button (binary_sensor gpio)
# ST-LINK SN: 48FF6B064967515318282087 (esphome-zephyr upload can't pick a probe without VCP)
# flash: STM32_Programmer_CLI -c port=SWD sn=48FF6B064967515318282087 mode=UR -d <build>/.west_build/mcuboot/zephyr/zephyr.bin 0x08000000
# -d <build>/.west_build/zephyr/zephyr/zephyr.signed.bin 0x08010000 -v -rst
esphome:
name: mcu-stm32-f103ze
friendly_name: STM32 F103ZE
# needs the esphomeplatformzephyr fork (esphome-zephyr), upstream has no stm32: platform yet
# waveshare_open103z: same F103ZE, 8 MHz HSE, console on USART1 PA9/PA10
stm32:
variant: STM32F1
board: waveshare_open103z
framework:
type: zephyr
# no network, so no OTA: one image slot, MCUboot only verifies and boots it
single_slot: true
# waveshare_open103z ships no partitions: MCUboot 32K, storage 32K (16 x 2K pages), the app in the rest.
# MCUboot needs the same table; the fork appends its own code-partition = &boot_partition after it
overlays:
app: &partitions |
&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(32)>;
read-only;
};
storage_partition: partition@8000 {
label = "storage";
reg = <0x00008000 DT_SIZE_K(32)>;
};
slot0_partition: partition@10000 {
label = "image-0";
reg = <0x00010000 DT_SIZE_K(448)>;
};
};
};
/ { chosen { zephyr,code-partition = &slot0_partition; }; };
mcuboot: *partitions
logger:
output:
- platform: gpio
id: led_out
pin:
number: PE2
inverted: true
light:
- platform: binary
name: LED
id: led
output: led_out
binary_sensor:
- platform: gpio
name: Button
pin:
number: PB10
inverted: true
mode:
input: true
pullup: true
on_press:
light.toggle: led
+75
View File
@@ -0,0 +1,75 @@
---
# Hardware: ST STM32F4DISCOVERY (STM32F407VGT6, 1M flash, no radio), ST-LINK/V2 without VCP
# Pinout:
# PA11/PA12 micro-USB CN5 (OTG FS) -> logger (USB CDC)
# PD12 LD4 green (active high) -> LED (light binary)
# PA0 B1 user (active high) -> Button (binary_sensor gpio)
# ST-LINK SN: 53FF6E065087545435390387 (esphome-zephyr upload can't pick a probe without VCP)
# flash: STM32_Programmer_CLI -c port=SWD sn=53FF6E065087545435390387 mode=UR -d <build>/.west_build/mcuboot/zephyr/zephyr.bin 0x08000000
# -d <build>/.west_build/zephyr/zephyr/zephyr.signed.bin 0x08010000 -v -rst
esphome:
name: mcu-stm32-f4disco
friendly_name: STM32 F4 Discovery
# needs the esphomeplatformzephyr fork (esphome-zephyr), upstream has no stm32: platform yet
stm32:
variant: STM32F4
board: stm32f4_disco
framework:
type: zephyr
# no network, so no OTA: one image slot, MCUboot only verifies and boots it
single_slot: true
# NVS sector = flash page; needs >= 2 of them, so storage takes the two 16K pages (sectors 2-3)
kconfig_options:
SETTINGS_NVS_SECTOR_COUNT: 2
# stm32f4_disco ships no partitions at all: MCUboot in sectors 0-1, storage in 2-3, the app in 4-11.
# MCUboot needs the same table; the fork appends its own code-partition = &boot_partition after it
overlays:
app: &partitions |
&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(32)>;
read-only;
};
storage_partition: partition@8000 {
label = "storage";
reg = <0x00008000 DT_SIZE_K(32)>;
};
slot0_partition: partition@10000 {
label = "image-0";
reg = <0x00010000 DT_SIZE_K(960)>;
};
};
};
/ { chosen { zephyr,code-partition = &slot0_partition; }; };
mcuboot: *partitions
logger:
hardware_uart: USB_CDC
output:
- platform: gpio
id: led_out
pin: PD12
light:
- platform: binary
name: LED
id: led
output: led_out
# B1 has an external pull-down on the board
binary_sensor:
- platform: gpio
name: Button
pin: PA0
# B1 bounces, toggle fired twice per press
filters:
- delayed_on_off: 30ms
on_press:
light.toggle: led
+74
View File
@@ -0,0 +1,74 @@
---
# Hardware: ST NUCLEO-F411RE (STM32F411RE, 512K flash, no radio)
# Pinout:
# PA2/PA3 USART2 TX/RX -> ST-LINK virtual COM port (logger)
# PA5 LD2 green (active high) -> LED (light binary)
# PC13 B1 user (active low) -> Button (binary_sensor gpio)
# ST-LINK SN: 066BFF554954777167032417 (on-board V2-1, upload --device /dev/ttyACM0 resolves it from the VCP)
esphome:
name: mcu-stm32-nucleo
friendly_name: STM32 Nucleo
# needs the esphomeplatformzephyr fork (esphome-zephyr), upstream has no stm32: platform yet
stm32:
variant: STM32F4
board: nucleo_f411re
framework:
type: zephyr
# no network, so no OTA: one image slot, MCUboot only verifies and boots it
single_slot: true
# NVS sector = flash page; needs >= 2 of them, so storage takes the two 16K pages (sectors 2-3)
kconfig_options:
SETTINGS_NVS_SECTOR_COUNT: 2
# nucleo_f411re ships no partitions at all: MCUboot in sectors 0-1, storage in 2-3, the app in 4-7.
# MCUboot needs the same table; the fork appends its own code-partition = &boot_partition after it
overlays:
app: &partitions |
&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(32)>;
read-only;
};
storage_partition: partition@8000 {
label = "storage";
reg = <0x00008000 DT_SIZE_K(32)>;
};
slot0_partition: partition@10000 {
label = "image-0";
reg = <0x00010000 DT_SIZE_K(448)>;
};
};
};
/ { chosen { zephyr,code-partition = &slot0_partition; }; };
mcuboot: *partitions
logger:
output:
- platform: gpio
id: led_out
pin: PA5
light:
- platform: binary
name: LED
id: led
output: led_out
# B1 has an external pull-up on the board
binary_sensor:
- platform: gpio
name: Button
pin:
number: PC13
inverted: true
# B1 bounces, toggle fired twice per press
filters:
- delayed_on_off: 30ms
on_press:
light.toggle: led
+34
View File
@@ -0,0 +1,34 @@
---
# One-shot for a Seeed XIAO STM32C5 still on TinyUF2: erases TinyUF2 5 s after boot (mrk's tinyuf2_eraser, LED on when
# done), then hold BOOT + press RESET (ROM DFU, 0483:df11) and flash the MCUboot build of the node:
# dfu-util -a 0 -s 0x08000000 -D .esphome/build/<node>/.west_build/mcuboot/zephyr/zephyr.bin
# dfu-util -a 0 -s 0x08008000:leave -D .esphome/build/<node>/.west_build/zephyr/zephyr/zephyr.signed.bin
esphome:
name: mcu-stm32-xiao-c5-eraser
on_boot:
priority: -100
then:
- delay: 5s
- tinyuf2_eraser.erase: eraser
# LED on: erased, go to DFU (BOOT + RESET)
- output.turn_on: led_out
external_components:
- source: github://mrk-its/esphome-canopen@canopen_entities
components: [tinyuf2_eraser]
stm32:
variant: STM32C5
board: xiao_stm32c5
logger:
tinyuf2_eraser:
id: eraser
output:
- platform: gpio
id: led_out
pin:
number: PB12
inverted: true
+275
View File
@@ -0,0 +1,275 @@
---
# 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}
+230
View File
@@ -0,0 +1,230 @@
---
# Hardware: LilyGO T-Beam v1.1 (ESP32, AXP192), geolocation test receiver
# Pinout:
# GPIO12 GNSS RX -> uart_gnss (uart tx_pin)
# GPIO21 -> system_i2c (i2c sda)
# GPIO22 -> system_i2c (i2c scl)
# GPIO34 GNSS TX -> uart_gnss (uart rx_pin)
# GPIO38 User button (middle) -> user_button (binary_sensor gpio)
# I2C:
# 0x34 pmu_axp (axp192), LDO3 powers the GNSS, DCDC3 the ESP32
# 0x3C oled (display ssd1306_i2c)
# GNSS: u-blox NEO-6M (u-blox 6, fw 7.03), 9600 baud -> gnss (ubx), active antenna
# LoRa (SX1276) not set up yet
substitutions:
device: tbeam
name: T-Beam
area: DEV
comment: geolocation test receiver
esphome:
name: mcu-${device}
friendly_name: ${name}
area: ${area}
comment: ${comment}
esp32:
board: ttgo-t-beam
framework:
type: esp-idf
packages:
common: !include common/common.yaml
ipv6_only: !include common/ipv6_only.yaml
external_components:
- source: github://m5stack/esphome-yaml
components: [axp192]
refresh: 1h
# geolocation hub + nmea and ubx platforms, esphome/esphome#23301 (stacked on #23293)
- source: github://pr#23301
components: [geolocation, nmea, ubx]
i2c:
id: system_i2c
sda: 21
scl: 22
axp192:
id: pmu_axp
address: 0x34
i2c_id: system_i2c
output:
- platform: axp192
id: gnss_power
channel: DLDO3
voltage: 3300
switch:
- platform: output
id: gnss_enable
name: GNSS Power
output: gnss_power
restore_mode: ALWAYS_ON
uart:
id: uart_gnss
rx_pin: 34
tx_pin: 12
baud_rate: 9600
# Test aid: decode the NAV-SVINFO answers to the poll in interval below
debug:
direction: RX
after:
bytes: 512
timeout: 50ms
sequence:
- lambda: |-
for (size_t i = 0; i + 8 <= bytes.size(); i++) {
if (bytes[i] != 0xB5 || bytes[i + 1] != 0x62 || bytes[i + 2] != 0x01 || bytes[i + 3] != 0x30)
continue;
const size_t len = bytes[i + 4] | (bytes[i + 5] << 8);
if (i + 6 + len > bytes.size() || len < 8)
break;
const uint8_t *p = bytes.data() + i + 6;
const uint8_t num = p[4];
int tracked = 0, used = 0;
std::string sats;
for (uint8_t k = 0; k < num && 8 + 12 * (k + 1) <= len; k++) {
const uint8_t *c = p + 8 + 12 * k;
if (c[4] == 0)
continue;
tracked++;
if (c[2] & 0x01)
used++;
char buf[12];
snprintf(buf, sizeof(buf), " %u:%u", c[1], c[4]);
sats += buf;
}
ESP_LOGI("ubxdbg", "NAV-SVINFO used %d, tracked %d of %u channels, PRN:cno%s", used, tracked, num,
sats.c_str());
break;
}
geolocation:
- platform: ubx
id: gnss
update_interval: 10s
sensor:
- platform: geolocation
type: latitude
id: latitude
name: Latitude
- platform: geolocation
type: longitude
id: longitude
name: Longitude
- platform: geolocation
type: altitude
id: altitude
name: Altitude
- platform: geolocation
type: speed
id: speed
name: Speed
- platform: geolocation
type: course
id: course
name: Course
- platform: geolocation
type: satellites
id: satellites
name: Satellites
- platform: geolocation
type: hdop
id: hdop
name: HDOP
- platform: geolocation
type: horizontal_accuracy
id: horizontal_accuracy
name: Horizontal Accuracy
- platform: geolocation
type: vertical_accuracy
name: Vertical Accuracy
- platform: axp192
id: pmu_sensors
axp192_id: pmu_axp
update_interval: 60s
battery_voltage:
id: battery_voltage
name: Battery Voltage
battery_level:
id: battery_level
name: Battery Level
battery_charge_current:
name: Battery Charge Current
entity_category: diagnostic
battery_discharge_current:
name: Battery Discharge Current
entity_category: diagnostic
vbus_voltage:
name: VBUS Voltage
entity_category: diagnostic
internal_temperature:
name: PMU Temperature
entity_category: diagnostic
battery_charging:
name: Battery Charging
battery_connected:
id: battery_connected
name: Battery Connected
vbus_present:
id: usb_power
name: USB Power
binary_sensor:
- platform: gpio
id: user_button
name: Button
pin:
number: 38
inverted: true
time:
- platform: geolocation
id: gnss_time
interval:
# Test aid: poll NAV-SVINFO (u-blox 6 has no NAV-SAT)
- interval: 10s
then:
- uart.write:
id: uart_gnss
data: [0xB5, 0x62, 0x01, 0x30, 0x00, 0x00, 0x31, 0x94]
font:
# Tiny5 Mono bitmap, 6x9 cell: 21 columns, 7 rows on 128x64
- file: assets/fonts/Tiny5Mono.bdf
id: font_mono
display:
- platform: ssd1306_i2c
id: oled
model: "SSD1306 128x64"
address: 0x3C
i2c_id: system_i2c
update_interval: 2s
lambda: |-
it.printf(0, 0, id(font_mono), "Sats %.0f", id(satellites).state);
if (!std::isnan(id(hdop).state))
it.printf(127, 0, id(font_mono), TextAlign::TOP_RIGHT, "HDOP %.1f", id(hdop).state);
if (std::isnan(id(latitude).state)) {
it.print(0, 9, id(font_mono), "No fix");
} else {
it.printf(0, 9, id(font_mono), "Lat %11.6f", id(latitude).state);
it.printf(0, 18, id(font_mono), "Lon %11.6f", id(longitude).state);
it.printf(0, 27, id(font_mono), "Alt %.0f m", id(altitude).state);
it.printf(127, 27, id(font_mono), TextAlign::TOP_RIGHT, "+-%.0f m", id(horizontal_accuracy).state);
it.printf(0, 36, id(font_mono), "%.1f km/h", id(speed).state);
if (!std::isnan(id(course).state))
it.printf(127, 36, id(font_mono), TextAlign::TOP_RIGHT, "%.0f deg", id(course).state);
}
auto now = id(gnss_time).now();
if (now.is_valid())
it.strftime(0, 46, id(font_mono), "%H:%M:%S", now);
if (id(battery_connected).state && !std::isnan(id(battery_level).state))
it.printf(127, 46, id(font_mono), TextAlign::TOP_RIGHT, "Bat %.0f%%", id(battery_level).state);
if (id(usb_power).state)
it.print(127, 55, id(font_mono), TextAlign::TOP_RIGHT, "USB");
+2 -7
View File
@@ -38,13 +38,8 @@ packages:
api: api:
# status page until Home Assistant connects (log viewers don't subscribe to states) # status page until Home Assistant connects (log viewers don't subscribe to states)
on_client_connected: # Home Assistant has subscribed and received every state
- delay: 2s on_client_synced:
- if:
condition:
api.connected:
state_subscription_only: true
then:
- lvgl.page.show: main_page - lvgl.page.show: main_page
on_client_disconnected: on_client_disconnected:
- if: - if:
+458 -389
View File
@@ -1,24 +1,51 @@
--- ---
# Hardware: LilyGO T-PCIE # Hardware: LilyGO T-PCIE with SIM7600 module
# Pinout:
# GPIO4 Modem PWRKEY -> modem_powerkey (switch gpio)
# GPIO12 LED -> led (switch gpio) (inverted)
# GPIO21 -> system_i2c (i2c sda)
# GPIO22 -> system_i2c (i2c scl)
# GPIO25 Modem power enable -> modem_enable (switch gpio)
# GPIO26 Modem TXD -> atmodem (modem rx_pin)
# GPIO27 Modem RXD -> atmodem (modem tx_pin)
# GPIO32 Modem DTR -> modem_dtr (binary_sensor gpio)
# GPIO33 Modem RI -> modem_ri (binary_sensor gpio)
# GPIO36 Modem STATUS -> modem_status (binary_sensor gpio)
# I2C:
# 0x34 pmu_axp (axp192), LDO3 powers the GNSS antenna
# 0x3C OLED (display ssd1306_i2c)
substitutions: substitutions:
device: tracker device: tracker
name: Tracker name: Tracker
area: DEV area: DEV
comment: LTE GPS tracker comment: LTE GPS tracker
# 2400 mAh cell, charged only to 4.1 V by the axp192 component, so ~90% of it is usable
battery_capacity_mah: "2160"
# O2 Telemetria bills per day, the cheapest tier is up to 0.1 MB: values go out on a real change,
# otherwise once per report_interval
report_interval: 1h
# Parked: GNSS goes off after gnss_parked_min minutes under parked_speed km/h, then wakes every
# gnss_probe_min minutes for gnss_probe_window_min to check whether the car moved
parked_speed: "5"
gnss_parked_min: "10"
gnss_probe_min: "30"
gnss_probe_window_min: "3"
# Without USB: Battery Low at battery_low_percent, power off below battery_off_voltage (V);
# the AXP itself cuts off at 2.9 V (VOFF)
battery_low_percent: "20"
battery_off_voltage: "3.3"
# The modem reports only DOP; accuracy in m = DOP * this typical range error. Tune against a known spot
gnss_uere_m: "5"
esphome: esphome:
name: mcu-${device} name: mcu-${device}
friendly_name: ${device} friendly_name: ${name}
area: ${area} area: ${area}
comment: ${comment} comment: ${comment}
on_boot: on_boot:
# priority: -10
priority: 600 priority: 600
then: then:
- logger.log: turning modem off - logger.log: turning modem on
- binary_sensor.template.publish:
id: modem_ready
state: OFF
- switch.turn_on: led - switch.turn_on: led
- switch.turn_on: modem_enable - switch.turn_on: modem_enable
- delay: 1s - delay: 1s
@@ -32,80 +59,24 @@ esphome:
binary_sensor.is_on: modem_status binary_sensor.is_on: modem_status
timeout: 30s timeout: 30s
- logger.log: modem on - logger.log: modem on
- binary_sensor.template.publish: - modem.enable
id: modem_ready
state: ON
# - switch.turn_on: cmd_gnss_enable
# on_boot:
# priority: 600
# then:
# # https://www.manualslib.com/manual/1498555/Simcom-Sim7000g.html?page=25#manual
# - logger.log: turning modem off
# - binary_sensor.template.publish:
# id: modem_ready
# state: OFF
# # The doc says that pulling 'modem_power' to ground works,
# # But I had to put if off for 2.6s, then on ?
# - switch.turn_off: modem_powerkey
# - delay: 2.6s
# - switch.turn_on: modem_powerkey
# - logger.log: waiting off status
# - delay: 5s
# - wait_until:
# condition:
# binary_sensor.is_off: modem_status
# timeout: 30s
# - if:
# condition:
# binary_sensor.is_off: modem_status
# then:
# - logger.log: modem off
# else:
# #- logger.log: modem off timeout
# - logger.log:
# level: ERROR
# format: "Timeout while waiting modem power off"
# - delay: 1s
# # https://github.com/Xinyuan-LilyGO/LilyGO-T-SIM7000G/issues/251
# - logger.log: turning modem on
# - switch.turn_on: modem_powerkey
# - delay: 10ms
# - switch.turn_off: modem_powerkey
# - delay: 1010ms
# - switch.turn_on: modem_powerkey
# - delay: 5s
# - wait_until:
# condition:
# binary_sensor.is_on: modem_status
# timeout: 30s
# - logger.log: modem on
# - binary_sensor.template.publish:
# id: modem_ready
# state: ON
esp32: esp32:
variant: esp32 variant: esp32
toolchain: esp-idf
framework: framework:
type: esp-idf type: esp-idf
# platform_version: 53.03.11 advanced:
flash_chip: generic
## TESTING sram1_as_iram: true
external_components:
- source:
type: git
url: https://github.com/crossan007/esphome
ref: "feature/AXP192"
components: [axp192]
- source: github://pr#6721
components: [network, modem]
- source: github://pr#9802
components: [modem]
# packages: # packages:
# common: !include common/common.yaml # common: !include common/common.yaml # modem only for now, no WiFi
# ipv6_only: !include common/ipv6_only.yaml
external_components:
- source: github://m5stack/esphome-yaml
components: [axp192]
refresh: 1h
logger: logger:
level: VERBOSE level: VERBOSE
@@ -116,366 +87,464 @@ i2c:
scl: 22 scl: 22
scan: true scan: true
modem:
id: atmodem
# ready: modem_ready
rx_pin: 26
tx_pin: 27
model: SIM7600
apn: o2internet
# username: ""
# password: ""
pin_code: ""
init_at:
- AT+CGNSSMODE=15,1 # GNSS all navigation systems
- AT+CGPS=1 # GPS on
mqtt:
id: mqtt_client
broker: !secret mqtt_ext
username: !secret mqtt_username
password: !secret mqtt_password
discovery: true
axp192: axp192:
id: pmu_axp id: pmu_axp
address: 0x34 address: 0x34
i2c_id: system_i2c i2c_id: system_i2c
modem:
id: atmodem
rx_pin: 26
tx_pin: 27
model: SIM7600
apn: o2internet
enable_on_boot: false # on_boot powers the modem up first
# pin_code: ""
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:
condition:
switch.is_on: gnss_switch
then:
- modem.send_at: AT+CGPS=1
# API is unreachable over LTE, the tracker has to talk MQTT
mqtt:
id: mqtt_client
broker: !secret mqtt_ext
# Own user, so the broker ACL can limit it to its own topics
username: !secret mqtt_tracker_username
password: !secret mqtt_tracker_password
discovery: true
# MAC in the unique_id: the default ESP<type><object_id> clashes with other devices' common entities
discovery_unique_id_generator: mac
# Every message costs data: logs stay on USB, and one ping per 10 min keeps the session.
# Lower keepalive if O2's CGNAT drops idle TCP sooner (reconnects resend all discovery)
log_topic: null
keepalive: 600s
on_connect:
# ESPHome has no device_tracker, so the discovery for one is sent here; the identifiers put it on
# the same device as the other entities, and the position comes from the attributes.
# on_connect fires before the client counts as connected, and a publish before that is dropped
- wait_until: mqtt.connected
- mqtt.publish_json:
topic: homeassistant/device_tracker/mcu-${device}/location/config
retain: true
payload: |-
root["name"] = "Location";
root["unique_id"] = "mcu-${device}-location";
root["source_type"] = "gps";
root["json_attributes_topic"] = "mcu-${device}/location";
root["availability_topic"] = "mcu-${device}/status";
root["device"].to<JsonObject>()["identifiers"].to<JsonArray>().add(get_mac_address());
output:
# DLDO3 in the m5stack component = AXP192 LDO3
- platform: axp192
id: gnss_power
channel: DLDO3
voltage: 3300
binary_sensor: binary_sensor:
- <<: !include common/binary_sensor/status.yaml
- platform: template
id: battery_low
name: Battery Low
device_class: battery
lambda: return !id(usb_power).state && id(battery).state <= ${battery_low_percent};
filters:
- delayed_on: 2min
# Below battery_off_voltage for 3 min without USB: power off before the cell is deep discharged.
# The AXP starts again on PWR, or on USB when the board powers on with external power
- platform: template
id: battery_empty
internal: true
lambda: return !id(usb_power).state && id(battery_voltage).state < ${battery_off_voltage};
filters:
- delayed_on: 3min
on_press:
- logger.log:
level: WARN
format: Battery empty, powering off
- modem.disable
- delay: 10s
# REG 32H bit 7: power off; the component's shutdown() writes the AXP2101 register
- lambda: id(pmu_axp).writeRegister(0x32, id(pmu_axp).readRegister(0x32) | 0x80);
- platform: gpio - platform: gpio
id: modem_dtr id: modem_dtr
# name: Cellular DTR
pin: 32 pin: 32
- platform: gpio - platform: gpio
id: modem_ri id: modem_ri
# name: ellular RI
pin: 33 pin: 33
- platform: gpio - platform: gpio
id: modem_status id: modem_status
# name: Cellular Status
pin: 36 pin: 36
- platform: template
id: modem_ready button:
# name: Cellular Ready - <<: !include common/button/restart.yaml
sensor: sensor:
- <<: !include common/sensor/uptime.yaml
update_interval: ${report_interval}
# State of charge from the AXP192 coulomb counter. The counter and the marker live in the AXP, so
# they survive ESP reboots and are lost together when the battery is pulled; until the next full
# charge this reports unknown.
- platform: template
id: battery_soc
name: Battery Charge
internal: true
device_class: battery
unit_of_measurement: "%"
accuracy_decimals: 0
update_interval: 60s
lambda: |-
auto *pmu = id(pmu_axp);
if (pmu->is_failed() || !pmu->isBatteryConnect())
return NAN;
int ctl = pmu->readRegister(0xB8);
if (ctl < 0)
return NAN;
if (!(ctl & 0x80))
pmu->writeRegister(0xB8, 0x80); // start counting
if (pmu->readRegister(0x06) != 0xCC)
return NAN; // no full charge since the AXP lost power
int64_t cnt[2] = {0, 0}; // 0xB0 charge, 0xB4 discharge, 32 bit big endian
for (int c = 0; c < 2; c++) {
for (int i = 0; i < 4; i++) {
int b = pmu->readRegister(0xB0 + 4 * c + i);
if (b < 0)
return NAN;
cnt[c] = (cnt[c] << 8) | b;
}
}
// Datasheet: mAh = 65536 * 0.5 mA * (charge - discharge) / 3600 / ADC rate (25 Hz << reg 0x84[7:6])
float rate = 25 << ((pmu->readRegister(0x84) >> 6) & 3);
float mah = 32768.0f * (cnt[0] - cnt[1]) / 3600.0f / rate;
return clamp(100.0f + mah * 100.0f / ${battery_capacity_mah}, 0.0f, 100.0f);
# The only battery value HA gets: the coulomb counter once calibrated, the voltage estimate until
# then, in 10 % steps
- platform: template
id: battery
name: Battery
device_class: battery
unit_of_measurement: "%"
accuracy_decimals: 0
update_interval: 60s
lambda: |-
return std::isnan(id(battery_soc).state) ? id(battery_level).state : id(battery_soc).state;
filters:
- lambda: return roundf(x / 10.0f) * 10.0f;
- or:
- heartbeat: ${report_interval}
- delta: 10
- platform: axp192
id: pmu_sensors
axp192_id: pmu_axp
update_interval: 60s
battery_voltage:
id: battery_voltage
name: Battery Voltage
internal: true
battery_level:
id: battery_level
name: Battery Level
internal: true
battery_charge_current:
name: Battery Charge Current
internal: true
battery_discharge_current:
name: Battery Discharge Current
internal: true
vbus_voltage:
name: VBUS Voltage
internal: true
internal_temperature:
name: PMU Temperature
internal: true
battery_charging:
name: Battery Charging
internal: true
on_release:
# Charging ended on USB at full voltage: that is 100%, so restart the coulomb counter here.
# ponytail: a USB unplug near full also passes the voltage check, a few % off at most
- lambda: |-
auto *pmu = id(pmu_axp);
if (pmu->isVbusIn() && id(battery_voltage).state > 4.05f) {
pmu->writeRegister(0xB8, 0xA0); // counter on, clear
pmu->writeRegister(0x06, 0xCC); // marker in the AXP data buffer: counter starts at full
}
battery_connected:
name: Battery Connected
internal: true
vbus_present:
id: usb_power
name: USB Power
usb_present:
name: USB Present
internal: true
- platform: modem - platform: modem
rssi: rssi:
name: rssi id: modem_rssi
name: Modem Signal
entity_category: diagnostic
filters:
- or:
- heartbeat: ${report_interval}
- delta: 6
ber: ber:
name: ber name: Modem BER
latitude: entity_category: diagnostic
filters:
- heartbeat: ${report_interval}
# Filled from the +CGNSSINFO URC. lat/lon deltas are ~50 m at 48° N
- platform: template
id: latitude
name: Latitude name: Latitude
longitude: internal: true
update_interval: never
on_value:
- script.execute: publish_location
filters:
- or:
- heartbeat: ${report_interval}
- delta: 0.0005
- platform: template
id: longitude
name: Longitude name: Longitude
altitude: internal: true
update_interval: never
on_value:
- script.execute: publish_location
filters:
- or:
- heartbeat: ${report_interval}
- delta: 0.0007
- platform: template
id: altitude
name: Altitude name: Altitude
internal: true
update_interval: never
- platform: template
id: speed
name: Speed
internal: true
update_interval: never
- platform: template
id: course
name: Course
internal: true
update_interval: never
- platform: template
id: gnss_accuracy
name: GNSS Accuracy
internal: true
update_interval: never
- platform: template
id: gnss_vertical_accuracy
name: GNSS Vertical Accuracy
internal: true
update_interval: never
switch: switch:
- platform: gpio - platform: gpio
id: modem_powerkey id: modem_powerkey
# name: Cellular PowerKey
pin: 4 pin: 4
# inverted: true
- platform: gpio - platform: gpio
id: led id: led
# name: LED
pin: 12 pin: 12
inverted: true inverted: true
- platform: gpio - platform: gpio
id: modem_enable id: modem_enable
# name: Cellular Enable
pin: 25 pin: 25
- platform: axp192 - platform: output
id: gnss_enable id: gnss_enable
# name: GNSS Enable output: gnss_power
port: LDO3 - platform: template
- platform: modem id: gnss_switch
gnss:
name: GNSS name: GNSS
optimistic: true
restore_mode: ALWAYS_ON restore_mode: ALWAYS_ON
turn_on_action:
- modem.send_at: AT+CGPS=1
turn_off_action:
- modem.send_at: AT+CGPS=0
text_sensor: text_sensor:
- <<: !include common/text_sensor/version.yaml
# Text sensors publish every value, so these copy theirs only when it changes
- platform: template
id: modem_operator
name: Modem Operator
entity_category: diagnostic
update_interval: never
- platform: template
id: modem_network
name: Modem Network
entity_category: diagnostic
update_interval: never
# The operator comes from the +CPSI URC, the position from +CGNSSINFO; the component has sensors for neither
- platform: modem - platform: modem
network_type: network_type:
name: network type id: modem_network_raw
signal_strength: internal: true
name: Signal strength on_value:
# - platform: template - lambda: |-
# name: "cgpaddr" if (id(modem_network).state != x)
# update_interval: 25s id(modem_network).publish_state(x);
# lambda: |- urc:
# esp_modem::command_result err; id: modem_urc
# std::string response; internal: true
on_value:
- lambda: |-
// +CPSI: <system mode>,<operation mode>[,<MCC>-<MNC>,...]
char op[16];
if (sscanf(x.c_str(), "+CPSI: %*[^,],%*[^,],%15[^,]", op) == 1) {
if (id(modem_operator).state != op)
id(modem_operator).publish_state(op);
return;
}
// +CGNSSINFO: <mode>,<satellite counts>,<ddmm.mmmmmm>,<N/S>,<dddmm.mmmmmm>,<E/W>,<date>,<UTC time>,
// <alt m>,<speed kn>,<course>,<PDOP>,<HDOP>,<VDOP>
// The number of satellite counts differs between firmwares, so the fields are found from N/S.
// Without a fix all fields are empty
if (x.rfind("+CGNSSINFO:", 0) != 0)
return;
std::vector<std::string> f;
for (size_t i = x.find(':') + 1, j; ; i = j + 1) {
j = x.find(',', i);
f.push_back(x.substr(i, j == std::string::npos ? j : j - i));
if (j == std::string::npos)
break;
}
size_t ns = 1;
while (ns < f.size() && f[ns] != "N" && f[ns] != "S")
ns++;
if (ns + 10 > f.size()) {
id(latitude).publish_state(NAN);
id(longitude).publish_state(NAN);
id(speed).publish_state(NAN);
return;
}
auto num = [&](size_t i) { return f[i].empty() ? NAN : strtof(f[i].c_str(), nullptr); };
auto deg = [](double v) { double d = floor(v / 100); return d + (v - d * 100) / 60; };
double lat = deg(strtod(f[ns - 1].c_str(), nullptr)), lon = deg(strtod(f[ns + 1].c_str(), nullptr));
id(altitude).publish_state(num(ns + 5));
id(speed).publish_state(num(ns + 6) * 1.852f);
id(course).publish_state(num(ns + 7));
id(gnss_accuracy).publish_state(num(ns + 9) * ${gnss_uere_m});
id(gnss_vertical_accuracy).publish_state(ns + 10 < f.size() ? num(ns + 10) * ${gnss_uere_m} : NAN);
id(latitude).publish_state(f[ns] == "S" ? -lat : lat);
id(longitude).publish_state(f[ns + 2] == "W" ? -lon : lon);
# err = id(atmodem)->dce->at("AT+CGPADDR", response, 3000); script:
# if (err != esp_modem::command_result::OK) { # Latitude and longitude change in the same poll; one message for both
# return { "AT+CGPADDR ERROR" }; - id: publish_location
# } else { mode: restart
# return { response }; then:
# } - delay: 1s
# - platform: template - if:
# name: "get_ccid" condition:
# update_interval: 40s lambda: return !std::isnan(id(latitude).state) && !std::isnan(id(longitude).state);
# lambda: |- then:
# esp_modem::command_result err; - mqtt.publish_json:
# std::string response; topic: mcu-${device}/location
retain: true
payload: |-
root["latitude"] = id(latitude).state;
root["longitude"] = id(longitude).state;
if (!std::isnan(id(altitude).state))
root["altitude"] = id(altitude).state;
if (!std::isnan(id(speed).state))
root["speed"] = id(speed).state;
if (!std::isnan(id(course).state))
root["course"] = id(course).state;
if (!std::isnan(id(gnss_accuracy).state))
root["gps_accuracy"] = roundf(id(gnss_accuracy).state);
if (!std::isnan(id(gnss_vertical_accuracy).state))
root["vertical_accuracy"] = roundf(id(gnss_vertical_accuracy).state);
if (!std::isnan(id(battery).state))
root["battery_level"] = id(battery).state;
# err = id(atmodem)->dce->at("AT+CCID", response, 3000); time:
# if (err != esp_modem::command_result::OK) { # Over PPP; one NTP exchange is ~150 B, so a few a day are enough for the ESP's clock
# return { "AT+CCID ERROR" }; - platform: sntp
# } else { id: sntp_time
# return { response }; update_interval: 6h
# }
# - platform: template
# name: "get_rssi"
# update_interval: 42s
# lambda: |-
# esp_modem::command_result err;
# std::string response;
# err = id(atmodem)->dce->at("AT+CSQ", response, 3000); globals:
# if (err != esp_modem::command_result::OK) { - id: still_minutes
# return { "AT+CSQ ERROR" }; type: int
# } else { initial_value: "0"
# return { response }; - id: parked
# } type: bool
# - platform: template initial_value: "false"
# name: "get_creg" - id: parked_minutes
# update_interval: 44s type: int
# lambda: |- initial_value: "0"
# esp_modem::command_result err;
# std::string response;
# err = id(atmodem)->dce->at("AT+CREG?", response, 3000); interval:
# if (err != esp_modem::command_result::OK) { # Saves the GNSS current while parked; the speed comes from GNSS, the board has no accelerometer
# return { "AT+CGNSSINFO ERROR" }; - interval: 60s
# } else { then:
# return { response }; - lambda: |-
# } if (id(parked)) {
# - platform: template if (++id(parked_minutes) >= ${gnss_probe_min}) {
# name: "gmap" // A look around: the logic below keeps GNSS on if the car moves within the window
# update_interval: 60s id(parked) = false;
# lambda: |- id(still_minutes) = ${gnss_parked_min} - ${gnss_probe_window_min};
# esp_modem::command_result err; id(gnss_enable).turn_on();
# std::string gnss_info; id(gnss_switch).turn_on();
}
return;
}
float v = id(speed).state; // NAN without a fix
if (!std::isnan(v) && v >= ${parked_speed}) {
id(still_minutes) = 0;
} else if (++id(still_minutes) >= ${gnss_parked_min}) {
id(parked) = true;
id(parked_minutes) = 0;
id(gnss_switch).turn_off();
id(gnss_enable).turn_off();
}
# err = id(atmodem)->dce->at("AT+CGNSSINFO", gnss_info, 3000); font:
# if (err != esp_modem::command_result::OK) { - file: "gfonts://Roboto"
# return { "AT+CGNSSINFO ERROR" }; id: font_small
# } size: 12
# std::string data = gnss_info.substr(12); display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
# std::vector<std::string> parts; address: 0x3C
# size_t pos = 0; i2c_id: system_i2c
# std::string delimiter = ","; update_interval: 2s
# while ((pos = data.find(delimiter)) != std::string::npos) { lambda: |-
# parts.push_back(data.substr(0, pos)); it.printf(0, 0, id(font_small), "%s %s", id(modem_network).has_state() ? id(modem_network).state.c_str() : "--",
# data.erase(0, pos + delimiter.length()); id(modem_operator).state.c_str());
# } if (id(modem_rssi).has_state() && !std::isnan(id(modem_rssi).state))
# parts.push_back(data); it.printf(127, 0, id(font_small), TextAlign::TOP_RIGHT, "%.0f dBm", id(modem_rssi).state);
it.printf(0, 16, id(font_small), "PPP: %s", id(atmodem).is_connected() ? "OK" : "--");
# if (parts.size() < 14) { it.printf(127, 16, id(font_small), TextAlign::TOP_RIGHT, "MQTT: %s", id(mqtt_client)->is_connected() ? "OK" : "--");
# return { "Invalid GNSS data: " + gnss_info }; if (std::isnan(id(latitude).state))
# } it.printf(0, 32, id(font_small), "GNSS: no fix");
else
# std::string latitude = parts[4]; it.printf(0, 32, id(font_small), "%.5f %.5f", id(latitude).state, id(longitude).state);
# std::string lat_direction = parts[5]; auto now = id(sntp_time).now();
# std::string longitude = parts[6]; if (now.is_valid())
# std::string lon_direction = parts[7]; it.strftime(0, 48, id(font_small), "%H:%M", now);
else
# if (latitude.empty() || lat_direction.empty() || longitude.empty() || lon_direction.empty()) { it.printf(0, 48, id(font_small), "Up %.2f d", id(uptime_sensor).state);
# return { "Invalid GNSS data: " + gnss_info }; // The unrounded value; HA only gets 10 % steps
# } float bat = std::isnan(id(battery_soc).state) ? id(battery_level).state : id(battery_soc).state;
if (!std::isnan(bat))
# double lat_deg = std::stod(latitude.substr(0, 2)); it.printf(127, 48, id(font_small), TextAlign::TOP_RIGHT, "Bat %.0f%%", bat);
# double lat_min = std::stod(latitude.substr(2));
# double lat = lat_deg + (lat_min / 60.0);
# if (lat_direction == "S") lat = -lat;
# double lon_deg = std::stod(longitude.substr(0, 3));
# double lon_min = std::stod(longitude.substr(3));
# double lon = lon_deg + (lon_min / 60.0);
# if (lon_direction == "W") lon = -lon;
# std::string google_maps_link = "https://www.google.com/maps/search/?api=1&query=" + std::to_string(lat) + "," + std::to_string(lon);
# return { google_maps_link };
## WORKING ONE
# external_components:
# - source:
# type: git
# url: https://github.com/crossan007/esphome
# ref: "feature/AXP192"
# components: [ axp192 ]
# # - source: github://pr#6721
# # components: [ gsm ]
# - source:
# type: git
# url: https://github.com/ssieb/custom_components
# components: [ serial ]
# - source: components
# packages:
# common: !include common/common.yaml
# api:
# services:
# - service: send_sms
# variables:
# recipient: string
# message: string
# then:
# - sim7600.send_sms:
# recipient: !lambda 'return recipient;'
# message: !lambda 'return message;'
# - service: send_sms_test
# then:
# - sim7600.send_sms:
# recipient: "+421907538553"
# message: TEST TEST
# - service: dial
# variables:
# recipient: string
# then:
# - sim7600.dial:
# recipient: !lambda 'return recipient;'
# - service: connect
# then:
# - sim7600.connect
# - service: disconnect
# then:
# - sim7600.disconnect
# - service: send_ussd
# variables:
# ussdCode: string
# then:
# - sim7600.send_ussd:
# ussd: !lambda 'return ussdCode;'
# - service: send_at_command
# variables:
# at_command: string
# then:
# - uart.write:
# id: modem_uart
# data: "AT+DT=+42197538553"
# # data: !lambda 'return at_command;'
# i2c:
# - id: system_i2c
# sda: 21
# scl: 22
# scan: true #false
# uart:
# # - id: usb_uart
# # baud_rate: 115200
# # tx_pin: 1
# # rx_pin: 3
# - id: modem_uart
# baud_rate: 115200
# tx_pin: 27
# rx_pin: 26
# debug:
# sequence:
# - lambda: UARTDebug::log_string(direction, bytes);
# # gsm:
# # rx_pin: 26
# # tx_pin: 27
# # power_pin: 4
# # flight_pin: 25
# # status_pin: 34
# # dtr_pin: 32
# # model: SIM7600
# # apn: orange
# # username: orange
# # password: orange
# # pin_code: "0000"
# axp192:
# address: 0x34
# i2c_id: system_i2c
# sim7600:
# uart_id: modem_uart
# on_sms_received:
# - lambda: |-
# id(sms_sender).publish_state(sender);
# id(sms_message).publish_state(message);
# on_incoming_call:
# - lambda: |-
# id(caller_id_text_sensor).publish_state(caller_id);
# on_call_connected:
# - logger.log:
# format: Call connected
# on_call_disconnected:
# - logger.log:
# format: Call disconnected
# on_ussd_received:
# - lambda: |-
# id(ussd_message).publish_state(ussd);
# binary_sensor:
# - platform: sim7600
# registered:
# name: Cellular
# - platform: gpio
# id: modem_status
# name: Cellular Status
# pin: 36
# sensor:
# - platform: sim7600
# rssi:
# name: Cellular RSSI
# switch:
# - platform: gpio
# id: modem_powerkey
# # name: Modem Powerkey
# pin: 4
# - platform: gpio
# id: led
# # name: LED
# pin: 12
# inverted: true
# - platform: gpio
# id: modem_enable
# # name: Modem Enable
# pin: 25
# - platform: axp192
# id: gnss_enable
# port: LDO3
# - platform: template
# id: cmd_gnss_enable
# turn_on_action:
# - uart.write:
# id: modem_uart
# data: "AT+CGPS=on"
# turn_off_action:
# - uart.write:
# id: modem_uart
# data: "AT+CGPS=off"
# text_sensor:
# - platform: template
# id: sms_sender
# name: SMS Sender
# - platform: template
# id: sms_message
# name: SMS Message
# - platform: template
# id: caller_id_text_sensor
# name: Caller ID
# - platform: template
# id: ussd_message
# name: USSD Code
# - platform: serial
# uart_id: modem_uart
# id: modem_read
+227
View File
@@ -0,0 +1,227 @@
---
# Hardware: Ebyte E104-BT5040U (nRF52840 USB dongle)
# Flash: Open DFU bootloader (USB 1915:521f), RESET button -> blue LED blinks, then upload
# No USB in the app: the USB stack holds HFCLK through onoff, so RadiANT's clock_control_on()
# gets -EPERM and ANT setup fails (0x33). So no logger and no DFU touch either.
# Pinout (LEDs and button active low):
# pin 17 VDD 3.3 V not together with USB power (datasheet)
# pin 18 GND
# pin 19 P0.04 UART TX -> mcu-trainer GPIO18 (RX), packet_transport
# pin 20 P0.26 UART RX <- mcu-trainer GPIO17 (TX), packet_transport
# P0.06 LED (red) -> ANT+ Connected (a configured device is received),
# blinks when ANT+ setup failed
# P0.08, P1.09, P0.12: RGB LED per datasheet, unused (only red lit reliably in tests)
# P1.06 function button -> Button (binary_sensor gpio)
# Radio: ANT+ receiver (RadiANT), no network of its own; values go over the UART link
# ANT+ devices:
# 655730 Garmin HRM-Pro heart rate
# 498521 Concept2 PM5 (rower) fitness equipment (FE-C)
# 1044953 Garmin Tempe environment (temperature)
# 604693 Garmin Varia RTL515 bike radar, battery only
# 136052 Garmin HRM-Dual heart rate (pain cave)
# 334424 Garmin HRM-Tri heart rate (bike)
# 886796 Garmin Rally RS200 power + cadence
# 343922 Garmin Speed Sensor 2 speed
# 42898 SRAM Force AXS shifting (Cube Litening C:68X), battery only
# 13888 Tacx Neo 2 fitness equipment (FE-C), basement trainer
esphome:
name: mcu-trainer-ant
friendly_name: Trainer ANT+
# needs the esphomeplatformzephyr fork (esphome-zephyr); RadiANT needs NCS
nrf:
variant: NRF52
board: nrf52840dongle/nrf52840
framework:
type: ncs
advanced:
# factory MBR + Open DFU bootloader stay, the app starts at 0x1000
bootloader: nrf
dfu: false
kconfig_options:
BOARD_SERIAL_BACKEND_CDC_ACM: false
external_components:
- source: github://randybb/esphome-components
components: [ant_plus]
output:
- platform: gpio
id: led_known
pin: {number: P0.06, inverted: true}
binary_sensor:
- platform: gpio
id: button
name: Button
pin: {number: P1.06, mode: INPUT_PULLUP, inverted: true}
ant_plus:
id: ant
network_key: !secret ant_plus_network_key
connected:
id: ant_connected
name: ANT+ Connected
on_press: {output.turn_on: led_known}
on_release: {output.turn_off: led_known}
unknown_device:
id: ant_unknown_device
name: ANT+ Unknown Device
devices:
- type: heart_rate # Garmin HRM-Pro
device_number: 655730
heart_rate:
id: hrm_pro_heart_rate
name: Garmin HRM-Pro Heart Rate
battery_level:
id: hrm_pro_battery
name: Garmin HRM-Pro Battery
- type: fitness_equipment # Concept2 PM5 (rower)
device_number: 498521
power:
id: pm5_power
name: Concept2 PM5 Power
cadence:
id: pm5_stroke_rate
name: Concept2 PM5 Stroke Rate
in_use:
id: pm5_in_use
name: Concept2 PM5 In Use
- type: temperature # Garmin Tempe
device_number: 1044953
temperature:
id: tempe_temperature
name: Garmin Tempe Temperature
temperature_min:
id: tempe_temperature_min
name: Garmin Tempe Temperature 24h Min
temperature_max:
id: tempe_temperature_max
name: Garmin Tempe Temperature 24h Max
battery_voltage:
id: tempe_battery
name: Garmin Tempe Battery
battery_low:
id: tempe_battery_low
name: Garmin Tempe Battery Low
- type: bike_radar # Garmin Varia RTL515
device_number: 604693
battery_voltage:
id: varia_battery
name: Garmin Varia RTL515 Battery
battery_low:
id: varia_battery_low
name: Garmin Varia RTL515 Battery Low
- type: heart_rate # Garmin HRM-Dual
device_number: 136052
heart_rate:
id: hrm_dual_heart_rate
name: Garmin HRM-Dual Heart Rate
battery_level:
id: hrm_dual_battery
name: Garmin HRM-Dual Battery
- type: heart_rate # Garmin HRM-Tri
device_number: 334424
heart_rate:
id: hrm_tri_heart_rate
name: Garmin HRM-Tri Heart Rate
battery_level:
id: hrm_tri_battery
name: Garmin HRM-Tri Battery
- type: power # Garmin Rally RS200 (a battery in each pedal)
device_number: 886796
power:
id: rally_power
name: Garmin Rally RS200 Power
cadence:
id: rally_cadence
name: Garmin Rally RS200 Cadence
battery_low:
id: rally_battery_low
name: Garmin Rally RS200 Battery Low
- type: speed # Garmin Speed Sensor 2
device_number: 343922
speed:
id: speed2_speed
name: Garmin Speed Sensor 2 Speed
battery_voltage:
id: speed2_battery
name: Garmin Speed Sensor 2 Battery
battery_low:
id: speed2_battery_low
name: Garmin Speed Sensor 2 Battery Low
- type: fitness_equipment # Tacx Neo 2
device_number: 13888
power:
id: neo_power
name: Tacx Neo 2 Power
cadence:
id: neo_cadence
name: Tacx Neo 2 Cadence
in_use:
id: neo_in_use
name: Tacx Neo 2 In Use
- type: shifting # SRAM Force AXS (Cube Litening C:68X)
device_number: 42898
battery_low:
id: sram_battery_low
name: SRAM Force AXS Battery Low
uart:
id: link
port: UART1
tx_pin: P0.04
rx_pin: P0.26
baud_rate: 115200
# same layers as the receiving end, both ends must match
packet_interface:
- platform: uart
id: link_packets
uart_id: link
reliability:
session:
packet_transport:
- platform: packet_interface
packet_interface: link_packets
update_interval: 1s
sensors:
- hrm_pro_heart_rate
- hrm_pro_battery
- pm5_power
- pm5_stroke_rate
- tempe_temperature
- tempe_temperature_min
- tempe_temperature_max
- tempe_battery
- varia_battery
- hrm_dual_heart_rate
- hrm_dual_battery
- hrm_tri_heart_rate
- hrm_tri_battery
- rally_power
- rally_cadence
- speed2_speed
- speed2_battery
- neo_power
- neo_cadence
binary_sensors:
- button
- ant_connected
- ant_unknown_device
- pm5_in_use
- tempe_battery_low
- varia_battery_low
- rally_battery_low
- speed2_battery_low
- sram_battery_low
- neo_in_use
# blink the red LED when ANT+ setup failed (no logger without USB)
interval:
- interval: 500ms
then:
- lambda: |-
static bool on = false;
if (id(ant).is_failed()) { on = !on; if (on) id(led_known).turn_on(); else id(led_known).turn_off(); }
+2 -2
View File
@@ -7,8 +7,8 @@
# GPIO32 Grove SDA # GPIO32 Grove SDA
# GPIO33 Grove SCL # GPIO33 Grove SCL
substitutions: substitutions:
device: dimmer device: trainer-fan
name: Dimmer name: Trainer Fan
area: Basement area: Basement
comment: Pain cave fan comment: Pain cave fan
+309 -44
View File
@@ -4,6 +4,8 @@
# GPIO1 -> gpio_backlight_pwm (output ledc) # GPIO1 -> gpio_backlight_pwm (output ledc)
# GPIO4 -> touchscreen_bus (i2c sda) # GPIO4 -> touchscreen_bus (i2c sda)
# GPIO8 -> touchscreen_bus (i2c scl) # GPIO8 -> touchscreen_bus (i2c scl)
# GPIO17 -> ant_link (uart tx_pin) to mcu-trainer-ant P0.26 (RX)
# GPIO18 <- ant_link (uart rx_pin) from mcu-trainer-ant P0.04 (TX)
# GPIO21 -> display_qspi (spi data_pins) # GPIO21 -> display_qspi (spi data_pins)
# GPIO39 -> display_qspi (spi data_pins) # GPIO39 -> display_qspi (spi data_pins)
# GPIO40 -> display_qspi (spi data_pins) # GPIO40 -> display_qspi (spi data_pins)
@@ -15,14 +17,17 @@
# I2C: # I2C:
# 0x3B main_touch (touchscreen axs15231) # 0x3B main_touch (touchscreen axs15231)
substitutions: substitutions:
device: lvgl-trainer device: trainer
name: Trainer Display name: Trainer Display
area: Basement area: Basement
comment: "${area} | Pain Cave" comment: "${area} | Pain Cave"
light_basement: light.mcu_basement_2_light light_basement: light.mcu_basement_2_light
light_workbench: light.mcu_basement_2_workbench_light light_workbench: light.mcu_basement_2_workbench_light
light_exercise: light.exercise_room light_exercise: light.exercise_room
fan: light.mcu_dimmer_exercise_room_fan 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): # Pages (480x320, navigation bar at the bottom):
# clock, lights, training, fan, stopwatch, status # clock, lights, training, fan, stopwatch, status
@@ -109,14 +114,7 @@ touchscreen:
# no calibration/transform: the driver defaults to the native 320x480 panel and # no calibration/transform: the driver defaults to the native 320x480 panel and
# LVGL applies its own rotation to touch points # LVGL applies its own rotation to touch points
on_release: on_release:
- if: - script.execute: display_idle
condition: lvgl.is_paused
then:
- lvgl.resume:
- lvgl.widget.redraw:
- light.turn_on:
id: display_backlight
transition_length: 300ms
uart: uart:
- id: ext_uart - id: ext_uart
@@ -125,8 +123,36 @@ uart:
baud_rate: 115200 baud_rate: 115200
stop_bits: 1 stop_bits: 1
parity: NONE parity: NONE
# ANT+ values from mcu-trainer-ant (E104-BT5040U), wires crossed: GPIO17 -> P0.26, P0.04 -> GPIO18
- id: ant_link
tx_pin: 17
rx_pin: 18
baud_rate: 115200
# same layers as mcu-trainer-ant; session keep-alives show whether it's reachable
packet_interface:
- platform: uart
id: ant_link_packets
uart_id: ant_link
reliability:
session:
binary_sensor:
name: ANT Link
device_class: connectivity
entity_category: diagnostic
packet_transport:
- platform: packet_interface
packet_interface: ant_link_packets
providers:
- name: mcu-trainer-ant
binary_sensor: binary_sensor:
- platform: homeassistant
id: training_on
entity_id: ${training}
on_state:
- script.execute: update_training_status
- platform: homeassistant - platform: homeassistant
id: basement_light id: basement_light
entity_id: ${light_basement} entity_id: ${light_basement}
@@ -136,6 +162,7 @@ binary_sensor:
id: basement_light_btn id: basement_light_btn
state: state:
checked: !lambda return x; checked: !lambda return x;
- script.execute: display_idle
- platform: homeassistant - platform: homeassistant
id: workbench_light id: workbench_light
entity_id: ${light_workbench} entity_id: ${light_workbench}
@@ -145,6 +172,7 @@ binary_sensor:
id: workbench_light_btn id: workbench_light_btn
state: state:
checked: !lambda return x; checked: !lambda return x;
- script.execute: display_idle
- platform: homeassistant - platform: homeassistant
id: exercise_light id: exercise_light
entity_id: ${light_exercise} entity_id: ${light_exercise}
@@ -154,6 +182,7 @@ binary_sensor:
id: exercise_light_btn id: exercise_light_btn
state: state:
checked: !lambda return x; checked: !lambda return x;
- script.execute: display_idle
# brightness and color temperature only make sense while the light is on # brightness and color temperature only make sense while the light is on
- if: - if:
condition: condition:
@@ -168,6 +197,70 @@ binary_sensor:
trigger_on_initial_state: true trigger_on_initial_state: true
on_state: on_state:
- script.execute: update_fan_buttons - script.execute: update_fan_buttons
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: ant_connected
name: ANT+ Connected
internal: false
device_class: connectivity
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: ant_unknown_device
name: ANT+ Unknown Device
internal: false
icon: mdi:access-point
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: pm5_in_use
name: Concept2 PM5 In Use
internal: false
device_class: running
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: tempe_battery_low
name: Garmin Tempe Battery Low
internal: false
device_class: battery
entity_category: diagnostic
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: varia_battery_low
name: Garmin Varia RTL515 Battery Low
internal: false
device_class: battery
entity_category: diagnostic
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: rally_battery_low
name: Garmin Rally RS200 Battery Low
internal: false
device_class: battery
entity_category: diagnostic
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: speed2_battery_low
name: Garmin Speed Sensor 2 Battery Low
internal: false
device_class: battery
entity_category: diagnostic
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: sram_battery_low
name: SRAM Force AXS Battery Low
internal: false
device_class: battery
entity_category: diagnostic
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: neo_in_use
name: Tacx Neo 2 In Use
internal: false
device_class: running
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: button
name: ANT Button
internal: false
sensor: sensor:
- platform: homeassistant - platform: homeassistant
@@ -176,6 +269,172 @@ sensor:
attribute: brightness attribute: brightness
on_value: on_value:
- script.execute: update_fan_buttons - script.execute: update_fan_buttons
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: hrm_pro_heart_rate
name: Garmin HRM-Pro Heart Rate
internal: false
unit_of_measurement: bpm
icon: mdi:heart-pulse
filters:
- throttle: 1s
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: hrm_pro_battery
name: Garmin HRM-Pro Battery
internal: false
unit_of_measurement: "%"
device_class: battery
entity_category: diagnostic
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: pm5_power
name: Concept2 PM5 Power
internal: false
unit_of_measurement: W
device_class: power
filters:
- throttle: 1s
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: pm5_stroke_rate
name: Concept2 PM5 Stroke Rate
internal: false
unit_of_measurement: spm
icon: mdi:rowing
filters:
- throttle: 1s
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: tempe_temperature
name: Garmin Tempe Temperature
internal: false
unit_of_measurement: °C
device_class: temperature
accuracy_decimals: 1
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: tempe_temperature_min
name: Garmin Tempe Temperature 24h Min
internal: false
unit_of_measurement: °C
device_class: temperature
accuracy_decimals: 1
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: tempe_temperature_max
name: Garmin Tempe Temperature 24h Max
internal: false
unit_of_measurement: °C
device_class: temperature
accuracy_decimals: 1
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: tempe_battery
name: Garmin Tempe Battery
internal: false
unit_of_measurement: V
device_class: voltage
accuracy_decimals: 2
entity_category: diagnostic
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: varia_battery
name: Garmin Varia RTL515 Battery
internal: false
unit_of_measurement: V
device_class: voltage
accuracy_decimals: 2
entity_category: diagnostic
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: hrm_dual_heart_rate
name: Garmin HRM-Dual Heart Rate
internal: false
unit_of_measurement: bpm
icon: mdi:heart-pulse
filters:
- throttle: 1s
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: hrm_dual_battery
name: Garmin HRM-Dual Battery
internal: false
unit_of_measurement: "%"
device_class: battery
entity_category: diagnostic
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: hrm_tri_heart_rate
name: Garmin HRM-Tri Heart Rate
internal: false
unit_of_measurement: bpm
icon: mdi:heart-pulse
filters:
- throttle: 1s
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: hrm_tri_battery
name: Garmin HRM-Tri Battery
internal: false
unit_of_measurement: "%"
device_class: battery
entity_category: diagnostic
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: rally_power
name: Garmin Rally RS200 Power
internal: false
unit_of_measurement: W
device_class: power
filters:
- throttle: 1s
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: rally_cadence
name: Garmin Rally RS200 Cadence
internal: false
unit_of_measurement: rpm
icon: mdi:rotate-right
filters:
- throttle: 1s
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: speed2_speed
name: Garmin Speed Sensor 2 Speed
internal: false
unit_of_measurement: m/s
device_class: speed
accuracy_decimals: 2
filters:
- throttle: 1s
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: speed2_battery
name: Garmin Speed Sensor 2 Battery
internal: false
unit_of_measurement: V
device_class: voltage
accuracy_decimals: 2
entity_category: diagnostic
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: neo_power
name: Tacx Neo 2 Power
internal: false
unit_of_measurement: W
device_class: power
filters:
- throttle: 1s
- platform: packet_transport
provider: mcu-trainer-ant
remote_id: neo_cadence
name: Tacx Neo 2 Cadence
internal: false
unit_of_measurement: rpm
icon: mdi:rotate-right
filters:
- throttle: 1s
text_sensor: text_sensor:
# light attributes read as text: they are 'None' while the light is off # light attributes read as text: they are 'None' while the light is off
@@ -205,19 +464,36 @@ text_sensor:
value: !lambda return *parse_number<float>(x); value: !lambda return *parse_number<float>(x);
# a running automation (e.g. its delay) has current > 0 # a running automation (e.g. its delay) has current > 0
- platform: homeassistant - platform: homeassistant
id: training_start_running id: training_running
entity_id: automation.zwift_enable_fan entity_id: ${training_automation}
attribute: current
on_value:
- script.execute: update_training_status
- platform: homeassistant
id: training_stop_running
entity_id: automation.zwift_disable_fan
attribute: current attribute: current
on_value: on_value:
- script.execute: update_training_status - script.execute: update_training_status
script: script:
# wakes the display, then turns it off once all basement lights stay off for 5 min;
# restarted by every light change and touch
- id: display_idle
mode: restart
then:
- if:
condition: lvgl.is_paused
then:
- lvgl.resume:
- lvgl.widget.redraw:
- light.turn_on:
id: display_backlight
transition_length: 300ms
- delay: 5min
- if:
condition:
lambda: return !id(basement_light).state && !id(workbench_light).state && !id(exercise_light).state;
then:
- light.turn_off:
id: display_backlight
transition_length: 1s
- delay: 1s
- lvgl.pause:
- id: update_fan_buttons - id: update_fan_buttons
then: then:
- lambda: |- - lambda: |-
@@ -244,14 +520,17 @@ script:
- id: update_training_status - id: update_training_status
then: 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: - lvgl.label.update:
id: training_status_label id: training_status_label
text: !lambda |- text: !lambda |-
if (id(training_start_running).state != "0" && !id(training_start_running).state.empty()) const bool running = !id(training_running).state.empty() && id(training_running).state != "0";
return std::string("Tréning sa spúšťa, ventilátor sa zapne o 10 min"); if (id(training_on).state)
if (id(training_stop_running).state != "0" && !id(training_stop_running).state.empty()) return std::string(running ? "Tréning beží, ventilátor sa zapne o 10 min" : "Tréning beží");
return std::string("Tréning sa ukončuje, ventilátor sa vypne o 2 min"); return std::string(running ? "Tréning skončil, ventilátor sa vypne o 2 min" : "");
return std::string("");
- id: update_stopwatch - id: update_stopwatch
then: then:
@@ -540,42 +819,28 @@ lvgl:
entity_id: ${light_exercise} entity_id: ${light_exercise}
color_temp_kelvin: !lambda return (int) x; color_temp_kelvin: !lambda return (int) x;
# 3: training start / stop # 3: training start / stop, one toggle showing input_boolean.training
- id: training_page - id: training_page
pad_all: 10 pad_all: 10
widgets: widgets:
- button: - button:
align: TOP_LEFT id: training_btn
align: TOP_MID
y: 10 y: 10
width: 222 width: 460
height: 150 height: 150
bg_color: 0x1E7D32 bg_color: 0x1E7D32
widgets: widgets:
- label: - label:
id: training_btn_label
align: CENTER align: CENTER
text_font: font_button text_font: font_button
text: "Štart" text: "Štart"
on_click: on_click:
- homeassistant.action: - homeassistant.action:
action: automation.trigger action: input_boolean.toggle
data: data:
entity_id: automation.zwift_enable_fan entity_id: ${training}
- 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
- label: - label:
id: training_status_label id: training_status_label
align: TOP_MID align: TOP_MID
+1
View File
@@ -22,3 +22,4 @@ esp32_ble_beacon:
uuid: !secret ble_beacon_honda_uuid uuid: !secret ble_beacon_honda_uuid
major: !secret ble_beacon_honda_major major: !secret ble_beacon_honda_major
minor: !secret ble_beacon_honda_minor minor: !secret ble_beacon_honda_minor
tx_power: 9dBm
+1
View File
@@ -22,3 +22,4 @@ esp32_ble_beacon:
uuid: !secret ble_beacon_suzuki_uuid uuid: !secret ble_beacon_suzuki_uuid
major: !secret ble_beacon_suzuki_major major: !secret ble_beacon_suzuki_major
minor: !secret ble_beacon_suzuki_minor minor: !secret ble_beacon_suzuki_minor
tx_power: 9dBm
+1 -16
View File
@@ -12,29 +12,14 @@ esphome:
friendly_name: ${name} friendly_name: ${name}
area: ${area} area: ${area}
comment: ${comment} comment: ${comment}
on_boot:
then:
- if:
condition:
- binary_sensor.is_off: button
then:
- wifi.disable:
packages: packages:
base: !include common/vehicle_base.yaml base: !include common/vehicle_base.yaml
wifi: !include common/wifi.yaml
logger: !include common/logger.yaml logger: !include common/logger.yaml
ota: !include common/ota.yaml
binary_sensor:
- platform: gpio
id: button
filters:
- invert:
pin: 39
esp32_ble_beacon: esp32_ble_beacon:
type: iBeacon type: iBeacon
uuid: !secret ble_beacon_toyota_auris_uuid uuid: !secret ble_beacon_toyota_auris_uuid
major: !secret ble_beacon_toyota_auris_major major: !secret ble_beacon_toyota_auris_major
minor: !secret ble_beacon_toyota_auris_minor minor: !secret ble_beacon_toyota_auris_minor
tx_power: 9dBm
+1
View File
@@ -22,3 +22,4 @@ esp32_ble_beacon:
uuid: !secret ble_beacon_toyota_yaris_uuid uuid: !secret ble_beacon_toyota_yaris_uuid
major: !secret ble_beacon_toyota_yaris_major major: !secret ble_beacon_toyota_yaris_major
minor: !secret ble_beacon_toyota_yaris_minor minor: !secret ble_beacon_toyota_yaris_minor
tx_power: 9dBm
+10 -3
View File
@@ -10,12 +10,16 @@ api_key: "oSsCFxRUqIJLpT98cQwSwNxYoC7zbUh0YBHczAWRyBI="
ota_password: "password" ota_password: "password"
ha_url: http://ha.local:8123/ ha_url: http://ha.local:8123/
tft_url: http://ha.local:8123/local/tft/lui.tft tft_url_terminal: http://ha.local/local/tft/terminal-eu.tft
mqtt_ip: ha.local mqtt_ip: ha.local
mqtt_ext: ha.example.com mqtt_ext: ha.example.com
mqtt_username: "username" mqtt_username: "username"
mqtt_password: "password" mqtt_password: "password"
mqtt_tracker_username: "username"
mqtt_tracker_password: "password"
mqtt_its_g5_username: "username"
mqtt_its_g5_password: "password"
ble_beacon_honda_uuid: "00000000-0000-0000-0000-000000000000" ble_beacon_honda_uuid: "00000000-0000-0000-0000-000000000000"
ble_beacon_honda_major: 10167 ble_beacon_honda_major: 10167
@@ -27,11 +31,14 @@ ble_beacon_toyota_auris_uuid: "00000000-0000-0000-0000-000000000000"
ble_beacon_toyota_auris_major: 10167 ble_beacon_toyota_auris_major: 10167
ble_beacon_toyota_auris_minor: 61958 ble_beacon_toyota_auris_minor: 61958
ble_beacon_toyota_yaris_uuid: "00000000-0000-0000-0000-000000000000" ble_beacon_toyota_yaris_uuid: "00000000-0000-0000-0000-000000000000"
ble_beacon_toyota_yaris_honda_major: 10167 ble_beacon_toyota_yaris_major: 10167
ble_beacon_toyota_yaris_honda_minor: 61958 ble_beacon_toyota_yaris_minor: 61958
ble_beacon_gate_uuid: "00000000-0000-0000-0000-000000000000"
# Thread active dataset (hex TLV) from Home Assistant # Thread active dataset (hex TLV) from Home Assistant
thread_tlv: "0E080000000000010000" thread_tlv: "0E080000000000010000"
# ANT+ network key (8 bytes hex), from thisisant.com # ANT+ network key (8 bytes hex), from thisisant.com
ant_plus_network_key: "0000000000000000" ant_plus_network_key: "0000000000000000"
wifi_ssid_0: "ssid"
wifi_password_0: "password"