mirror of
https://github.com/randybb/esphome-configs.git
synced 2026-12-06 09:06:52 +01:00
Compare commits
4
Commits
72afe7c622
...
5025159798
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5025159798 | ||
|
|
342ef79771 | ||
|
|
a110e0c536 | ||
|
|
1b003fd167 |
No files matched your search
+384
-384
@@ -1,24 +1,49 @@
|
|||||||
---
|
---
|
||||||
# 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"
|
||||||
|
|
||||||
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 +57,28 @@ 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
|
||||||
|
components: [axp192]
|
||||||
|
refresh: 1h
|
||||||
|
# Signal, network type and GNSS sensors from pr#9802 plus our fix for the AT+CGPS=1 resend loop
|
||||||
|
# (https://github.com/esphome/esphome/pull/9802#issuecomment-6381760281); the modem itself is in dev
|
||||||
|
- source: github://randybb/esphome@modem-gnss-fix
|
||||||
|
components: [modem]
|
||||||
|
|
||||||
logger:
|
logger:
|
||||||
level: VERBOSE
|
level: VERBOSE
|
||||||
@@ -116,366 +89,393 @@ 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
|
||||||
|
|
||||||
|
# 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
|
||||||
|
# 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
|
||||||
|
entity_category: diagnostic
|
||||||
|
filters:
|
||||||
|
- heartbeat: ${report_interval}
|
||||||
|
# lat/lon deltas are ~50 m at 48° N
|
||||||
latitude:
|
latitude:
|
||||||
|
id: latitude
|
||||||
name: Latitude
|
name: Latitude
|
||||||
|
internal: true
|
||||||
|
on_value:
|
||||||
|
- script.execute: publish_location
|
||||||
|
filters:
|
||||||
|
- or:
|
||||||
|
- heartbeat: ${report_interval}
|
||||||
|
- delta: 0.0005
|
||||||
longitude:
|
longitude:
|
||||||
|
id: longitude
|
||||||
name: Longitude
|
name: Longitude
|
||||||
|
internal: true
|
||||||
|
on_value:
|
||||||
|
- script.execute: publish_location
|
||||||
|
filters:
|
||||||
|
- or:
|
||||||
|
- heartbeat: ${report_interval}
|
||||||
|
- delta: 0.0007
|
||||||
altitude:
|
altitude:
|
||||||
|
id: altitude
|
||||||
name: Altitude
|
name: Altitude
|
||||||
|
internal: true
|
||||||
|
speed:
|
||||||
|
id: speed
|
||||||
|
name: Speed
|
||||||
|
internal: true
|
||||||
|
course:
|
||||||
|
id: course
|
||||||
|
name: Course
|
||||||
|
internal: true
|
||||||
|
accuracy:
|
||||||
|
id: gnss_accuracy
|
||||||
|
name: GNSS Accuracy
|
||||||
|
internal: true
|
||||||
|
|
||||||
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: modem
|
- platform: modem
|
||||||
gnss:
|
gnss:
|
||||||
|
id: gnss_switch
|
||||||
name: GNSS
|
name: GNSS
|
||||||
restore_mode: ALWAYS_ON
|
restore_mode: ALWAYS_ON
|
||||||
|
|
||||||
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 component has no sensor for it
|
||||||
- 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 && id(modem_operator).state != op)
|
||||||
|
id(modem_operator).publish_state(op);
|
||||||
|
|
||||||
# err = id(atmodem)->dce->at("AT+CGPADDR", response, 3000);
|
font:
|
||||||
# if (err != esp_modem::command_result::OK) {
|
- file: "gfonts://Roboto"
|
||||||
# return { "AT+CGPADDR ERROR" };
|
id: font_small
|
||||||
# } else {
|
size: 12
|
||||||
# return { response };
|
|
||||||
# }
|
|
||||||
# - platform: template
|
|
||||||
# name: "get_ccid"
|
|
||||||
# update_interval: 40s
|
|
||||||
# lambda: |-
|
|
||||||
# esp_modem::command_result err;
|
|
||||||
# std::string response;
|
|
||||||
|
|
||||||
# err = id(atmodem)->dce->at("AT+CCID", response, 3000);
|
display:
|
||||||
# if (err != esp_modem::command_result::OK) {
|
- platform: ssd1306_i2c
|
||||||
# return { "AT+CCID ERROR" };
|
model: "SSD1306 128x64"
|
||||||
# } else {
|
address: 0x3C
|
||||||
# return { response };
|
i2c_id: system_i2c
|
||||||
# }
|
update_interval: 2s
|
||||||
# - platform: template
|
lambda: |-
|
||||||
# name: "get_rssi"
|
it.printf(0, 0, id(font_small), "%s %s", id(modem_network).has_state() ? id(modem_network).state.c_str() : "--",
|
||||||
# update_interval: 42s
|
id(modem_operator).state.c_str());
|
||||||
# lambda: |-
|
if (id(modem_rssi).has_state() && !std::isnan(id(modem_rssi).state))
|
||||||
# esp_modem::command_result err;
|
it.printf(127, 0, id(font_small), TextAlign::TOP_RIGHT, "%.0f dBm", id(modem_rssi).state);
|
||||||
# std::string response;
|
it.printf(0, 16, id(font_small), "PPP: %s", id(atmodem).is_connected() ? "OK" : "--");
|
||||||
|
it.printf(127, 16, id(font_small), TextAlign::TOP_RIGHT, "MQTT: %s", id(mqtt_client)->is_connected() ? "OK" : "--");
|
||||||
|
if (std::isnan(id(latitude).state))
|
||||||
|
it.printf(0, 32, id(font_small), "GNSS: no fix");
|
||||||
|
else
|
||||||
|
it.printf(0, 32, id(font_small), "%.5f %.5f", id(latitude).state, id(longitude).state);
|
||||||
|
auto now = id(sntp_time).now();
|
||||||
|
if (now.is_valid())
|
||||||
|
it.strftime(0, 48, id(font_small), "%H:%M", now);
|
||||||
|
else
|
||||||
|
it.printf(0, 48, id(font_small), "Up %.2f d", id(uptime_sensor).state);
|
||||||
|
// 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))
|
||||||
|
it.printf(127, 48, id(font_small), TextAlign::TOP_RIGHT, "Bat %.0f%%", bat);
|
||||||
|
|
||||||
# err = id(atmodem)->dce->at("AT+CSQ", response, 3000);
|
script:
|
||||||
# if (err != esp_modem::command_result::OK) {
|
# Latitude and longitude change in the same poll; one message for both
|
||||||
# return { "AT+CSQ ERROR" };
|
- id: publish_location
|
||||||
# } else {
|
mode: restart
|
||||||
# return { response };
|
then:
|
||||||
# }
|
- delay: 1s
|
||||||
# - platform: template
|
- if:
|
||||||
# name: "get_creg"
|
condition:
|
||||||
# update_interval: 44s
|
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(gnss_accuracy).state))
|
||||||
|
root["gps_accuracy"] = id(gnss_accuracy).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;
|
||||||
|
|
||||||
# err = id(atmodem)->dce->at("AT+CREG?", 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+CGNSSINFO ERROR" };
|
- platform: sntp
|
||||||
# } else {
|
id: sntp_time
|
||||||
# return { response };
|
update_interval: 6h
|
||||||
# }
|
|
||||||
# - platform: template
|
|
||||||
# name: "gmap"
|
|
||||||
# update_interval: 60s
|
|
||||||
# lambda: |-
|
|
||||||
# esp_modem::command_result err;
|
|
||||||
# std::string gnss_info;
|
|
||||||
|
|
||||||
# err = id(atmodem)->dce->at("AT+CGNSSINFO", gnss_info, 3000);
|
globals:
|
||||||
# if (err != esp_modem::command_result::OK) {
|
- id: still_minutes
|
||||||
# return { "AT+CGNSSINFO ERROR" };
|
type: int
|
||||||
# }
|
initial_value: "0"
|
||||||
|
- id: parked
|
||||||
|
type: bool
|
||||||
|
initial_value: "false"
|
||||||
|
- id: parked_minutes
|
||||||
|
type: int
|
||||||
|
initial_value: "0"
|
||||||
|
|
||||||
# std::string data = gnss_info.substr(12);
|
interval:
|
||||||
|
# Saves the GNSS current while parked; the speed comes from GNSS, the board has no accelerometer
|
||||||
|
- interval: 60s
|
||||||
# std::vector<std::string> parts;
|
then:
|
||||||
# size_t pos = 0;
|
- lambda: |-
|
||||||
# std::string delimiter = ",";
|
if (id(parked)) {
|
||||||
# while ((pos = data.find(delimiter)) != std::string::npos) {
|
if (++id(parked_minutes) >= ${gnss_probe_min}) {
|
||||||
# parts.push_back(data.substr(0, pos));
|
// A look around: the logic below keeps GNSS on if the car moves within the window
|
||||||
# data.erase(0, pos + delimiter.length());
|
id(parked) = false;
|
||||||
# }
|
id(still_minutes) = ${gnss_parked_min} - ${gnss_probe_window_min};
|
||||||
# parts.push_back(data);
|
id(gnss_enable).turn_on();
|
||||||
|
id(gnss_switch).turn_on();
|
||||||
# if (parts.size() < 14) {
|
}
|
||||||
# return { "Invalid GNSS data: " + gnss_info };
|
return;
|
||||||
# }
|
}
|
||||||
|
float v = id(speed).state; // NAN without a fix
|
||||||
# std::string latitude = parts[4];
|
if (!std::isnan(v) && v >= ${parked_speed}) {
|
||||||
# std::string lat_direction = parts[5];
|
id(still_minutes) = 0;
|
||||||
# std::string longitude = parts[6];
|
} else if (++id(still_minutes) >= ${gnss_parked_min}) {
|
||||||
# std::string lon_direction = parts[7];
|
id(parked) = true;
|
||||||
|
id(parked_minutes) = 0;
|
||||||
# if (latitude.empty() || lat_direction.empty() || longitude.empty() || lon_direction.empty()) {
|
id(gnss_switch).turn_off();
|
||||||
# return { "Invalid GNSS data: " + gnss_info };
|
id(gnss_enable).turn_off();
|
||||||
# }
|
}
|
||||||
|
|
||||||
# double lat_deg = std::stod(latitude.substr(0, 2));
|
|
||||||
# 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
|
|
||||||
@@ -16,6 +16,8 @@ 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"
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
Reference in new issue
Block a user