1
0
mirror of synced 2026-03-09 20:13:40 +00:00

Compare commits

43 Commits
1.0.8 ... main

Author SHA1 Message Date
bump_version
9917b41381 Version 1.0.16 [skip ci] 2022-03-23 12:31:00 +00:00
Daniel Chesterton
d23d12fbb2 Various updates
- Bump dependencies
- Remove ping functionality in favour of new python-amcrest functionality (closes #33 and #38)
- Fix issue with MQTT publish hanging indefinitely if the app cannot connect to broker
- Display build date in software version (closes #53)
2022-03-23 12:30:33 +00:00
Daniel Chesterton
948a8b565d Merge pull request #62 from dchesterton/dependabot/github_actions/actions/checkout-3
[ci skip]: Bump actions/checkout from 2.4.0 to 3
2022-03-23 10:17:16 +00:00
Daniel Chesterton
479bd008b6 Merge pull request #61 from dchesterton/dependabot/github_actions/docker/login-action-1.14.1
[ci skip]: Bump docker/login-action from 1.12.0 to 1.14.1
2022-03-23 10:17:05 +00:00
Daniel Chesterton
d67afe7eda Merge pull request #66 from dchesterton/dependabot/github_actions/docker/build-push-action-2.10.0
[ci skip]: Bump docker/build-push-action from 2.7.0 to 2.10.0
2022-03-23 10:16:56 +00:00
dependabot[bot]
9950622314 [ci skip]: Bump docker/build-push-action from 2.7.0 to 2.10.0
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 2.7.0 to 2.10.0.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v2.7.0...v2.10.0)

---
updated-dependencies:
- dependency-name: docker/build-push-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-15 12:06:52 +00:00
Daniel Chesterton
72decbcc05 [ci skip] Merge pull request #64 from SirGoodenough/main
Mention HA Addons in out of scope
2022-03-15 11:46:02 +00:00
Sir GoodEnough
e75365fc26 HA Addons Section 2022-03-09 17:10:37 -06:00
Sir GoodEnough
4562f5d31d HA Addons Section 2022-03-09 17:08:08 -06:00
dependabot[bot]
5623e60da7 [ci skip]: Bump actions/checkout from 2.4.0 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.4.0 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.4.0...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-02 12:08:50 +00:00
dependabot[bot]
93f239feeb [ci skip]: Bump docker/login-action from 1.12.0 to 1.14.1
Bumps [docker/login-action](https://github.com/docker/login-action) from 1.12.0 to 1.14.1.
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](https://github.com/docker/login-action/compare/v1.12.0...v1.14.1)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-02 12:08:48 +00:00
bump_version
cbb3b4734b Version 1.0.15 [skip ci] 2021-12-31 03:21:49 +00:00
Daniel Chesterton
bd18f74507 fix: fix doorbell entity name when device is called 'Doorbell' 2021-12-31 03:21:30 +00:00
Daniel Chesterton
cfa7b00135 fix: move to more static Home Assistant topic names 2021-12-31 03:21:30 +00:00
Daniel Chesterton
f10c04b006 fix: ensure entity_id is correct for Storage Used % entity 2021-12-31 03:21:30 +00:00
bump_version
5014f702fd Version 1.0.14 [skip ci] 2021-12-31 00:01:04 +00:00
Daniel Chesterton
1a4718db0c Add support for overriding device name and add optional additional entities 2021-12-31 00:00:37 +00:00
bump_version
cfcee7dd2d Version 1.0.13 [skip ci] 2021-12-30 23:05:26 +00:00
Daniel Chesterton
ad323ec8ef Fix Dockerfile to send correct STOPSIGNAL 2021-12-30 23:05:09 +00:00
bump_version
8b6ee051d4 Version 1.0.12 [skip ci] 2021-12-30 16:22:04 +00:00
Daniel Chesterton
fd2123535d Switch action for bump-version 2021-12-30 16:21:43 +00:00
Daniel Chesterton
477aa89606 Merge pull request #52 from dchesterton/dependabot/github_actions/docker/login-action-1.12.0
[ci skip]: Bump docker/login-action from 1.10.0 to 1.12.0
2021-12-24 02:31:08 +00:00
Daniel Chesterton
8e5f0620cc Merge pull request #50 from dchesterton/dependabot/github_actions/actions/checkout-2.4.0
[ci skip]: Bump actions/checkout from 2.3.5 to 2.4.0
2021-12-24 02:31:00 +00:00
Daniel Chesterton
cc5e374419 Add entity_category and fix bug with storage totals 2021-12-24 02:30:37 +00:00
dependabot[bot]
afaef732c5 [ci skip]: Bump docker/login-action from 1.10.0 to 1.12.0
Bumps [docker/login-action](https://github.com/docker/login-action) from 1.10.0 to 1.12.0.
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](https://github.com/docker/login-action/compare/v1.10.0...v1.12.0)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-21 12:08:06 +00:00
dependabot[bot]
4cd3b1add8 [ci skip]: Bump actions/checkout from 2.3.5 to 2.4.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.5 to 2.4.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.3.5...v2.4.0)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-03 12:06:23 +00:00
bump_version
766aa50499 Version 1.0.11 [skip ci] 2021-10-26 20:38:41 +00:00
Daniel Chesterton
594a42320f Fix issue with fetching serial number (closes #35) 2021-10-26 21:38:19 +01:00
Daniel Chesterton
2886e5c1ca Merge pull request #36 from dchesterton/dependabot/github_actions/docker/build-push-action-2.7.0
[ci skip]: Bump docker/build-push-action from 2.6.1 to 2.7.0
2021-10-26 21:25:18 +01:00
Daniel Chesterton
9ba2544237 Merge pull request #39 from dchesterton/dependabot/github_actions/docker/setup-buildx-action-1.6.0
[ci skip]: Bump docker/setup-buildx-action from 1.5.1 to 1.6.0
2021-10-26 21:25:03 +01:00
bump_version
0ccdc6fe11 Version 1.0.10 [skip ci] 2021-10-26 20:13:44 +00:00
Daniel Chesterton
ed38b86eb6 Change bump-version 2021-10-26 21:13:17 +01:00
Daniel Chesterton
9d3d44f36b Merge pull request #46 from dchesterton/dependabot/pip/paho-mqtt-1.6.1
Bump paho-mqtt from 1.5.1 to 1.6.1
2021-10-26 21:09:59 +01:00
dependabot[bot]
8cb2cc2327 Bump paho-mqtt from 1.5.1 to 1.6.1
Bumps [paho-mqtt](https://github.com/eclipse/paho.mqtt.python) from 1.5.1 to 1.6.1.
- [Release notes](https://github.com/eclipse/paho.mqtt.python/releases)
- [Changelog](https://github.com/eclipse/paho.mqtt.python/blob/master/ChangeLog.txt)
- [Commits](https://github.com/eclipse/paho.mqtt.python/compare/v1.5.1...v1.6.1)

---
updated-dependencies:
- dependency-name: paho-mqtt
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-26 20:07:01 +00:00
Daniel Chesterton
4d4961e842 Merge pull request #45 from dchesterton/dependabot/github_actions/actions/checkout-2.3.5
[ci skip]: Bump actions/checkout from 2.3.4 to 2.3.5
2021-10-26 21:06:39 +01:00
Daniel Chesterton
cbb1995deb Merge pull request #42 from dchesterton/dependabot/pip/amcrest-1.9.3
Bump amcrest from 1.8.0 to 1.9.3
2021-10-26 21:06:20 +01:00
dependabot[bot]
781becf0d0 [ci skip]: Bump actions/checkout from 2.3.4 to 2.3.5
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.4 to 2.3.5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.3.4...v2.3.5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-18 12:06:55 +00:00
dependabot[bot]
8a1b1945ff Bump amcrest from 1.8.0 to 1.9.3
Bumps [amcrest](https://github.com/tchellomello/python-amcrest) from 1.8.0 to 1.9.3.
- [Release notes](https://github.com/tchellomello/python-amcrest/releases)
- [Commits](https://github.com/tchellomello/python-amcrest/compare/1.8.0...1.9.3)

---
updated-dependencies:
- dependency-name: amcrest
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-20 12:03:25 +00:00
dependabot[bot]
65623b45a2 [ci skip]: Bump docker/setup-buildx-action from 1.5.1 to 1.6.0
Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 1.5.1 to 1.6.0.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](https://github.com/docker/setup-buildx-action/compare/v1.5.1...v1.6.0)

---
updated-dependencies:
- dependency-name: docker/setup-buildx-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-06 12:05:58 +00:00
dependabot[bot]
4af6eac710 [ci skip]: Bump docker/build-push-action from 2.6.1 to 2.7.0
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 2.6.1 to 2.7.0.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v2.6.1...v2.7.0)

---
updated-dependencies:
- dependency-name: docker/build-push-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-20 12:06:38 +00:00
bump_version
7bbe3cbcf4 Version 1.0.9 [skip ci] 2021-08-07 20:26:29 +00:00
Daniel Chesterton
8e96fc5408 Add ping functionality to stop app hanging 2021-08-07 21:26:07 +01:00
bump_version
0f8858cef4 Version 1.0.8 [skip ci] 2021-08-03 17:10:40 +00:00
6 changed files with 160 additions and 46 deletions

View File

@@ -12,17 +12,16 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2.3.4
uses: actions/checkout@v3
- name: Bump version
uses: remorses/bump-version@js
id: version
with:
version_file: ./VERSION
github_token: ${{ secrets.GITHUB_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout code
uses: actions/checkout@v2.3.4
uses: actions/checkout@v3
with:
ref: main
- name: Set up QEMU
@@ -30,14 +29,14 @@ jobs:
with:
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1.5.1
uses: docker/setup-buildx-action@v1.6.0
- name: Login to DockerHub
uses: docker/login-action@v1.10.0
uses: docker/login-action@v1.14.1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v2.6.1
uses: docker/build-push-action@v2.10.0
with:
context: .
push: true

View File

@@ -8,6 +8,7 @@ COPY requirements.txt /
RUN pip install --no-warn-script-location --prefix=/install -r /requirements.txt
FROM base
STOPSIGNAL SIGINT
COPY --from=builder /install /usr/local
COPY src /app
COPY VERSION /app

View File

@@ -20,7 +20,8 @@ It supports the following environment variables:
- `MQTT_TLS_KEY` (required if using TLS) - path to the private key
- `HOME_ASSISTANT` (optional, default = false)
- `HOME_ASSISTANT_PREFIX` (optional, default = 'homeassistant')
- `STORAGE_POLL_INTERVAL` (optional, default = 3600) - how often to fetch storage data (in seconds)
- `STORAGE_POLL_INTERVAL` (optional, default = 3600) - how often to fetch storage data (in seconds) (set to 0 to disable functionality)
- `DEVICE_NAME` (optional) - override the default device name used in the Amcrest app
It exposes events to the following topics:
@@ -28,6 +29,7 @@ It exposes events to the following topics:
- `amcrest2mqtt/[SERIAL_NUMBER]/doorbell` - doorbell status (if AD110 or AD410)
- `amcrest2mqtt/[SERIAL_NUMBER]/human` - human detection (if AD410)
- `amcrest2mqtt/[SERIAL_NUMBER]/motion` - motion events (if supported)
- `amcrest2mqtt/[SERIAL_NUMBER]/config` - device configuration information
## Device Support
@@ -62,12 +64,22 @@ services:
### Multiple Devices
The app will not support multiple devices. You can run multiple instances of the app if you need to expose events for multiple devies.
The app will not support multiple devices. You can run multiple instances of the app if you need to expose events for multiple devices.
### Non-Docker Environments
Docker is the only supported way of deploying the application. The app should run directly via Python but this is not supported.
### Home Assistant Addons
There are a couple of Home Assistant Addons that use my code to be able to port this software into Supervised versions of Home Assistant. I do not specifically support the add-ons themselves, only the base software in the original docker format. Please contact the authors of those add-ons for support if using that method.
https://github.com/ikifar2012/amcrest2mqtt-addon/blob/master/README.md
[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fikifar2012%2Fha-addons)
https://github.com/robsonke/hassio-addons/blob/master/amcrest2mqtt/README.md
[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Frobsonke%2Fhassio-addons)
## Buy Me A ~~Coffee~~ Beer 🍻
A few people have kindly requested a way to donate a small amount of money. If you feel so inclined I've set up a "Buy Me A Coffee"

View File

@@ -1 +1 @@
1.0.7
1.0.16

View File

@@ -1,3 +1,3 @@
amcrest==1.8.0
paho-mqtt==1.5.1
python-slugify==5.0.2
amcrest==1.9.7
paho-mqtt==1.6.1
python-slugify==6.1.1

View File

@@ -8,6 +8,7 @@ from json import dumps
import signal
from threading import Timer
import ssl
import asyncio
is_exiting = False
mqtt_client = None
@@ -17,7 +18,9 @@ amcrest_host = os.getenv("AMCREST_HOST")
amcrest_port = int(os.getenv("AMCREST_PORT") or 80)
amcrest_username = os.getenv("AMCREST_USERNAME") or "admin"
amcrest_password = os.getenv("AMCREST_PASSWORD")
storage_poll_interval = int(os.getenv("STORAGE_POLL_INTERVAL") or 3600)
device_name = os.getenv("DEVICE_NAME")
mqtt_host = os.getenv("MQTT_HOST") or "localhost"
mqtt_qos = int(os.getenv("MQTT_QOS") or 0)
@@ -57,8 +60,8 @@ def mqtt_publish(topic, payload, exit_on_error=True, json=False):
)
if msg.rc == mqtt.MQTT_ERR_SUCCESS:
msg.wait_for_publish()
return msg
msg.wait_for_publish(2)
return
log(f"Error publishing MQTT message: {mqtt.error_string(msg.rc)}", level="ERROR")
@@ -73,9 +76,10 @@ def on_mqtt_disconnect(client, userdata, rc):
def exit_gracefully(rc, skip_mqtt=False):
global topics, mqtt_client
log("Exiting app...")
if mqtt_client is not None and mqtt_client.is_connected() and skip_mqtt == False:
mqtt_publish(topics["status"], "offline", exit_on_error=False)
mqtt_client.loop_stop(force=True)
mqtt_client.disconnect()
# Use os._exit instead of sys.exit to ensure an MQTT disconnect event causes the program to exit correctly as they
@@ -90,12 +94,16 @@ def refresh_storage_sensors():
try:
storage = camera.storage_all
mqtt_publish(topics["storage_used_percent"], str(storage["used_percent"]))
mqtt_publish(topics["storage_used"], str(storage["used"][0]))
mqtt_publish(topics["storage_total"], str(storage["total"][0]))
mqtt_publish(topics["storage_used"], to_gb(storage["used"]))
mqtt_publish(topics["storage_total"], to_gb(storage["total"]))
except AmcrestError as error:
log(f"Error fetching storage information {error}", level="WARNING")
def to_gb(total):
return str(round(float(total[0]) / 1024 / 1024 / 1024, 2))
def signal_handler(sig, frame):
# exit immediately upon receiving a second SIGINT
global is_exiting
@@ -134,18 +142,33 @@ camera = AmcrestCamera(
# Fetch camera details
log("Fetching camera details...")
device_type = camera.device_type.replace("type=", "").strip()
is_ad110 = device_type == "AD110"
is_ad410 = device_type == "AD410"
is_doorbell = is_ad110 or is_ad410
serial_number = camera.serial_number.strip()
sw_version = camera.software_information[0].replace("version=", "").strip()
device_name = camera.machine_name.replace("name=", "").strip()
device_slug = slugify(device_name, separator="_")
try:
device_type = camera.device_type.replace("type=", "").strip()
is_ad110 = device_type == "AD110"
is_ad410 = device_type == "AD410"
is_doorbell = is_ad110 or is_ad410
serial_number = camera.serial_number
if not isinstance(serial_number, str):
log(f"Error fetching serial number", level="ERROR")
exit_gracefully(1)
sw_version = camera.software_information[0].replace("version=", "").strip()
build_version = camera.software_information[1].strip()
amcrest_version = f"{sw_version} ({build_version})"
if not device_name:
device_name = camera.machine_name.replace("name=", "").strip()
device_slug = slugify(device_name, separator="_")
except AmcrestError as error:
log(f"Error fetching camera details", level="ERROR")
exit_gracefully(1)
log(f"Device type: {device_type}")
log(f"Serial number: {serial_number}")
log(f"Software version: {sw_version}")
log(f"Software version: {amcrest_version}")
log(f"Device name: {device_name}")
# MQTT topics
@@ -159,13 +182,27 @@ topics = {
"storage_used": f"amcrest2mqtt/{serial_number}/storage/used",
"storage_used_percent": f"amcrest2mqtt/{serial_number}/storage/used_percent",
"storage_total": f"amcrest2mqtt/{serial_number}/storage/total",
"home_assistant": {
"home_assistant_legacy": {
"doorbell": f"{home_assistant_prefix}/binary_sensor/amcrest2mqtt-{serial_number}/{device_slug}_doorbell/config",
"human": f"{home_assistant_prefix}/binary_sensor/amcrest2mqtt-{serial_number}/{device_slug}_human/config",
"motion": f"{home_assistant_prefix}/binary_sensor/amcrest2mqtt-{serial_number}/{device_slug}_motion/config",
"storage_used": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/{device_slug}_storage_used/config",
"storage_used_percent": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/{device_slug}_storage_used_percent/config",
"storage_total": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/{device_slug}_storage_total/config",
"version": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/{device_slug}_version/config",
"host": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/{device_slug}_host/config",
"serial_number": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/{device_slug}_serial_number/config",
},
"home_assistant": {
"doorbell": f"{home_assistant_prefix}/binary_sensor/amcrest2mqtt-{serial_number}/doorbell/config",
"human": f"{home_assistant_prefix}/binary_sensor/amcrest2mqtt-{serial_number}/human/config",
"motion": f"{home_assistant_prefix}/binary_sensor/amcrest2mqtt-{serial_number}/motion/config",
"storage_used": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/storage_used/config",
"storage_used_percent": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/storage_used_percent/config",
"storage_total": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/storage_total/config",
"version": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/version/config",
"host": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/host/config",
"serial_number": f"{home_assistant_prefix}/sensor/amcrest2mqtt-{serial_number}/serial_number/config",
},
}
@@ -215,12 +252,15 @@ if home_assistant:
"manufacturer": "Amcrest",
"model": device_type,
"identifiers": serial_number,
"sw_version": sw_version,
"sw_version": amcrest_version,
"via_device": "amcrest2mqtt",
},
}
if is_doorbell:
doorbell_name = "Doorbell" if device_name == "Doorbell" else f"{device_name} Doorbell"
mqtt_publish(topics["home_assistant_legacy"]["doorbell"], "")
mqtt_publish(
topics["home_assistant"]["doorbell"],
base_config
@@ -228,13 +268,15 @@ if home_assistant:
"state_topic": topics["doorbell"],
"payload_on": "on",
"payload_off": "off",
"name": f"{device_name} Doorbell",
"icon": "mdi:doorbell",
"name": doorbell_name,
"unique_id": f"{serial_number}.doorbell",
},
json=True,
)
if is_ad410:
mqtt_publish(topics["home_assistant_legacy"]["human"], "")
mqtt_publish(
topics["home_assistant"]["human"],
base_config
@@ -249,6 +291,7 @@ if home_assistant:
json=True,
)
mqtt_publish(topics["home_assistant_legacy"]["motion"], "")
mqtt_publish(
topics["home_assistant"]["motion"],
base_config
@@ -263,7 +306,56 @@ if home_assistant:
json=True,
)
mqtt_publish(topics["home_assistant_legacy"]["version"], "")
mqtt_publish(
topics["home_assistant"]["version"],
base_config
| {
"state_topic": topics["config"],
"value_template": "{{ value_json.sw_version }}",
"icon": "mdi:package-up",
"name": f"{device_name} Version",
"unique_id": f"{serial_number}.version",
"entity_category": "diagnostic",
"enabled_by_default": False
},
json=True,
)
mqtt_publish(topics["home_assistant_legacy"]["serial_number"], "")
mqtt_publish(
topics["home_assistant"]["serial_number"],
base_config
| {
"state_topic": topics["config"],
"value_template": "{{ value_json.serial_number }}",
"icon": "mdi:alphabetical-variant",
"name": f"{device_name} Serial Number",
"unique_id": f"{serial_number}.serial_number",
"entity_category": "diagnostic",
"enabled_by_default": False
},
json=True,
)
mqtt_publish(topics["home_assistant_legacy"]["host"], "")
mqtt_publish(
topics["home_assistant"]["host"],
base_config
| {
"state_topic": topics["config"],
"value_template": "{{ value_json.host }}",
"icon": "mdi:ip-network",
"name": f"{device_name} Host",
"unique_id": f"{serial_number}.host",
"entity_category": "diagnostic",
"enabled_by_default": False
},
json=True,
)
if storage_poll_interval > 0:
mqtt_publish(topics["home_assistant_legacy"]["storage_used_percent"], "")
mqtt_publish(
topics["home_assistant"]["storage_used_percent"],
base_config
@@ -272,11 +364,14 @@ if home_assistant:
"unit_of_measurement": "%",
"icon": "mdi:micro-sd",
"name": f"{device_name} Storage Used %",
"object_id": f"{device_slug}_storage_used_percent",
"unique_id": f"{serial_number}.storage_used_percent",
"entity_category": "diagnostic",
},
json=True,
)
mqtt_publish(topics["home_assistant_legacy"]["storage_used"], "")
mqtt_publish(
topics["home_assistant"]["storage_used"],
base_config
@@ -286,10 +381,12 @@ if home_assistant:
"icon": "mdi:micro-sd",
"name": f"{device_name} Storage Used",
"unique_id": f"{serial_number}.storage_used",
"entity_category": "diagnostic",
},
json=True,
)
mqtt_publish(topics["home_assistant_legacy"]["storage_total"], "")
mqtt_publish(
topics["home_assistant"]["storage_total"],
base_config
@@ -299,6 +396,7 @@ if home_assistant:
"icon": "mdi:micro-sd",
"name": f"{device_name} Storage Total",
"unique_id": f"{serial_number}.storage_total",
"entity_category": "diagnostic",
},
json=True,
)
@@ -309,8 +407,9 @@ mqtt_publish(topics["config"], {
"version": version,
"device_type": device_type,
"device_name": device_name,
"sw_version": sw_version,
"sw_version": amcrest_version,
"serial_number": serial_number,
"host": amcrest_host,
}, json=True)
if storage_poll_interval > 0:
@@ -318,21 +417,24 @@ if storage_poll_interval > 0:
log("Listening for events...")
try:
for code, payload in camera.event_actions("All", retries=5):
if (is_ad110 and code == "ProfileAlarmTransmit") or (code == "VideoMotion" and not is_ad110):
motion_payload = "on" if payload["action"] == "Start" else "off"
mqtt_publish(topics["motion"], motion_payload)
elif code == "CrossRegionDetection" and payload["data"]["ObjectType"] == "Human":
human_payload = "on" if payload["action"] == "Start" else "off"
mqtt_publish(topics["human"], human_payload)
elif code == "_DoTalkAction_":
doorbell_payload = "on" if payload["data"]["Action"] == "Invite" else "off"
mqtt_publish(topics["doorbell"], doorbell_payload)
async def main():
try:
async for code, payload in camera.async_event_actions("All"):
if (is_ad110 and code == "ProfileAlarmTransmit") or (code == "VideoMotion" and not is_ad110):
motion_payload = "on" if payload["action"] == "Start" else "off"
mqtt_publish(topics["motion"], motion_payload)
elif code == "CrossRegionDetection" and payload["data"]["ObjectType"] == "Human":
human_payload = "on" if payload["action"] == "Start" else "off"
mqtt_publish(topics["human"], human_payload)
elif code == "_DoTalkAction_":
doorbell_payload = "on" if payload["data"]["Action"] == "Invite" else "off"
mqtt_publish(topics["doorbell"], doorbell_payload)
mqtt_publish(topics["event"], payload, json=True)
log(str(payload))
mqtt_publish(topics["event"], payload, json=True)
log(str(payload))
except AmcrestError as error:
log(f"Amcrest error {error}", level="ERROR")
exit_gracefully(1)
except AmcrestError as error:
log(f"Amcrest error: {error}", level="ERROR")
exit_gracefully(1)
asyncio.run(main())