Compare commits
19 Commits
1.0.13
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f56f225ff8 | ||
|
|
9917b41381 | ||
|
|
d23d12fbb2 | ||
|
|
948a8b565d | ||
|
|
479bd008b6 | ||
|
|
d67afe7eda | ||
|
|
9950622314 | ||
|
|
72decbcc05 | ||
|
|
e75365fc26 | ||
|
|
4562f5d31d | ||
|
|
5623e60da7 | ||
|
|
93f239feeb | ||
|
|
cbb3b4734b | ||
|
|
bd18f74507 | ||
|
|
cfa7b00135 | ||
|
|
f10c04b006 | ||
|
|
5014f702fd | ||
|
|
1a4718db0c | ||
|
|
cfcee7dd2d |
10
.github/workflows/publish.yml
vendored
10
.github/workflows/publish.yml
vendored
@@ -12,7 +12,7 @@ jobs:
|
|||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2.4.0
|
uses: actions/checkout@v3
|
||||||
- name: Bump version
|
- name: Bump version
|
||||||
uses: remorses/bump-version@js
|
uses: remorses/bump-version@js
|
||||||
id: version
|
id: version
|
||||||
@@ -21,7 +21,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2.4.0
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: main
|
ref: main
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
@@ -29,14 +29,14 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
|
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1.6.0
|
uses: docker/setup-buildx-action@v2.5.0
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
uses: docker/login-action@v1.12.0
|
uses: docker/login-action@v1.14.1
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v2.7.0
|
uses: docker/build-push-action@v2.10.0
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -20,7 +20,8 @@ It supports the following environment variables:
|
|||||||
- `MQTT_TLS_KEY` (required if using TLS) - path to the private key
|
- `MQTT_TLS_KEY` (required if using TLS) - path to the private key
|
||||||
- `HOME_ASSISTANT` (optional, default = false)
|
- `HOME_ASSISTANT` (optional, default = false)
|
||||||
- `HOME_ASSISTANT_PREFIX` (optional, default = 'homeassistant')
|
- `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:
|
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]/doorbell` - doorbell status (if AD110 or AD410)
|
||||||
- `amcrest2mqtt/[SERIAL_NUMBER]/human` - human detection (if AD410)
|
- `amcrest2mqtt/[SERIAL_NUMBER]/human` - human detection (if AD410)
|
||||||
- `amcrest2mqtt/[SERIAL_NUMBER]/motion` - motion events (if supported)
|
- `amcrest2mqtt/[SERIAL_NUMBER]/motion` - motion events (if supported)
|
||||||
|
- `amcrest2mqtt/[SERIAL_NUMBER]/config` - device configuration information
|
||||||
|
|
||||||
## Device Support
|
## Device Support
|
||||||
|
|
||||||
@@ -62,12 +64,22 @@ services:
|
|||||||
|
|
||||||
### Multiple Devices
|
### 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
|
### 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.
|
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
|
||||||
|
[](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
|
||||||
|
[](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 🍻
|
## 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"
|
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"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
amcrest==1.9.3
|
amcrest==1.9.7
|
||||||
paho-mqtt==1.6.1
|
paho-mqtt==1.6.1
|
||||||
python-slugify==5.0.2
|
python-slugify==6.1.1
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from json import dumps
|
|||||||
import signal
|
import signal
|
||||||
from threading import Timer
|
from threading import Timer
|
||||||
import ssl
|
import ssl
|
||||||
|
import asyncio
|
||||||
|
|
||||||
is_exiting = False
|
is_exiting = False
|
||||||
mqtt_client = None
|
mqtt_client = None
|
||||||
@@ -17,7 +18,9 @@ amcrest_host = os.getenv("AMCREST_HOST")
|
|||||||
amcrest_port = int(os.getenv("AMCREST_PORT") or 80)
|
amcrest_port = int(os.getenv("AMCREST_PORT") or 80)
|
||||||
amcrest_username = os.getenv("AMCREST_USERNAME") or "admin"
|
amcrest_username = os.getenv("AMCREST_USERNAME") or "admin"
|
||||||
amcrest_password = os.getenv("AMCREST_PASSWORD")
|
amcrest_password = os.getenv("AMCREST_PASSWORD")
|
||||||
|
|
||||||
storage_poll_interval = int(os.getenv("STORAGE_POLL_INTERVAL") or 3600)
|
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_host = os.getenv("MQTT_HOST") or "localhost"
|
||||||
mqtt_qos = int(os.getenv("MQTT_QOS") or 0)
|
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:
|
if msg.rc == mqtt.MQTT_ERR_SUCCESS:
|
||||||
msg.wait_for_publish()
|
msg.wait_for_publish(2)
|
||||||
return msg
|
return
|
||||||
|
|
||||||
log(f"Error publishing MQTT message: {mqtt.error_string(msg.rc)}", level="ERROR")
|
log(f"Error publishing MQTT message: {mqtt.error_string(msg.rc)}", level="ERROR")
|
||||||
|
|
||||||
@@ -77,7 +80,6 @@ def exit_gracefully(rc, skip_mqtt=False):
|
|||||||
|
|
||||||
if mqtt_client is not None and mqtt_client.is_connected() and skip_mqtt == False:
|
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_publish(topics["status"], "offline", exit_on_error=False)
|
||||||
mqtt_client.loop_stop(force=True)
|
|
||||||
mqtt_client.disconnect()
|
mqtt_client.disconnect()
|
||||||
|
|
||||||
# Use os._exit instead of sys.exit to ensure an MQTT disconnect event causes the program to exit correctly as they
|
# Use os._exit instead of sys.exit to ensure an MQTT disconnect event causes the program to exit correctly as they
|
||||||
@@ -102,14 +104,6 @@ def refresh_storage_sensors():
|
|||||||
def to_gb(total):
|
def to_gb(total):
|
||||||
return str(round(float(total[0]) / 1024 / 1024 / 1024, 2))
|
return str(round(float(total[0]) / 1024 / 1024 / 1024, 2))
|
||||||
|
|
||||||
def ping_camera():
|
|
||||||
Timer(30, ping_camera).start()
|
|
||||||
response = os.system(f"ping -c1 -W100 {amcrest_host} >/dev/null 2>&1")
|
|
||||||
|
|
||||||
if response != 0:
|
|
||||||
log("Ping unsuccessful", level="ERROR")
|
|
||||||
exit_gracefully(1)
|
|
||||||
|
|
||||||
def signal_handler(sig, frame):
|
def signal_handler(sig, frame):
|
||||||
# exit immediately upon receiving a second SIGINT
|
# exit immediately upon receiving a second SIGINT
|
||||||
global is_exiting
|
global is_exiting
|
||||||
@@ -160,7 +154,13 @@ try:
|
|||||||
exit_gracefully(1)
|
exit_gracefully(1)
|
||||||
|
|
||||||
sw_version = camera.software_information[0].replace("version=", "").strip()
|
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_name = camera.machine_name.replace("name=", "").strip()
|
||||||
|
|
||||||
device_slug = slugify(device_name, separator="_")
|
device_slug = slugify(device_name, separator="_")
|
||||||
except AmcrestError as error:
|
except AmcrestError as error:
|
||||||
log(f"Error fetching camera details", level="ERROR")
|
log(f"Error fetching camera details", level="ERROR")
|
||||||
@@ -168,7 +168,7 @@ except AmcrestError as error:
|
|||||||
|
|
||||||
log(f"Device type: {device_type}")
|
log(f"Device type: {device_type}")
|
||||||
log(f"Serial number: {serial_number}")
|
log(f"Serial number: {serial_number}")
|
||||||
log(f"Software version: {sw_version}")
|
log(f"Software version: {amcrest_version}")
|
||||||
log(f"Device name: {device_name}")
|
log(f"Device name: {device_name}")
|
||||||
|
|
||||||
# MQTT topics
|
# MQTT topics
|
||||||
@@ -182,13 +182,27 @@ topics = {
|
|||||||
"storage_used": f"amcrest2mqtt/{serial_number}/storage/used",
|
"storage_used": f"amcrest2mqtt/{serial_number}/storage/used",
|
||||||
"storage_used_percent": f"amcrest2mqtt/{serial_number}/storage/used_percent",
|
"storage_used_percent": f"amcrest2mqtt/{serial_number}/storage/used_percent",
|
||||||
"storage_total": f"amcrest2mqtt/{serial_number}/storage/total",
|
"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",
|
"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",
|
"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",
|
"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": 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_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",
|
"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",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,12 +252,15 @@ if home_assistant:
|
|||||||
"manufacturer": "Amcrest",
|
"manufacturer": "Amcrest",
|
||||||
"model": device_type,
|
"model": device_type,
|
||||||
"identifiers": serial_number,
|
"identifiers": serial_number,
|
||||||
"sw_version": sw_version,
|
"sw_version": amcrest_version,
|
||||||
"via_device": "amcrest2mqtt",
|
"via_device": "amcrest2mqtt",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_doorbell:
|
if is_doorbell:
|
||||||
|
doorbell_name = "Doorbell" if device_name == "Doorbell" else f"{device_name} Doorbell"
|
||||||
|
|
||||||
|
mqtt_publish(topics["home_assistant_legacy"]["doorbell"], "")
|
||||||
mqtt_publish(
|
mqtt_publish(
|
||||||
topics["home_assistant"]["doorbell"],
|
topics["home_assistant"]["doorbell"],
|
||||||
base_config
|
base_config
|
||||||
@@ -251,13 +268,15 @@ if home_assistant:
|
|||||||
"state_topic": topics["doorbell"],
|
"state_topic": topics["doorbell"],
|
||||||
"payload_on": "on",
|
"payload_on": "on",
|
||||||
"payload_off": "off",
|
"payload_off": "off",
|
||||||
"name": f"{device_name} Doorbell",
|
"icon": "mdi:doorbell",
|
||||||
|
"name": doorbell_name,
|
||||||
"unique_id": f"{serial_number}.doorbell",
|
"unique_id": f"{serial_number}.doorbell",
|
||||||
},
|
},
|
||||||
json=True,
|
json=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
if is_ad410:
|
if is_ad410:
|
||||||
|
mqtt_publish(topics["home_assistant_legacy"]["human"], "")
|
||||||
mqtt_publish(
|
mqtt_publish(
|
||||||
topics["home_assistant"]["human"],
|
topics["home_assistant"]["human"],
|
||||||
base_config
|
base_config
|
||||||
@@ -272,6 +291,7 @@ if home_assistant:
|
|||||||
json=True,
|
json=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mqtt_publish(topics["home_assistant_legacy"]["motion"], "")
|
||||||
mqtt_publish(
|
mqtt_publish(
|
||||||
topics["home_assistant"]["motion"],
|
topics["home_assistant"]["motion"],
|
||||||
base_config
|
base_config
|
||||||
@@ -286,7 +306,56 @@ if home_assistant:
|
|||||||
json=True,
|
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:
|
if storage_poll_interval > 0:
|
||||||
|
mqtt_publish(topics["home_assistant_legacy"]["storage_used_percent"], "")
|
||||||
mqtt_publish(
|
mqtt_publish(
|
||||||
topics["home_assistant"]["storage_used_percent"],
|
topics["home_assistant"]["storage_used_percent"],
|
||||||
base_config
|
base_config
|
||||||
@@ -295,12 +364,14 @@ if home_assistant:
|
|||||||
"unit_of_measurement": "%",
|
"unit_of_measurement": "%",
|
||||||
"icon": "mdi:micro-sd",
|
"icon": "mdi:micro-sd",
|
||||||
"name": f"{device_name} Storage Used %",
|
"name": f"{device_name} Storage Used %",
|
||||||
|
"object_id": f"{device_slug}_storage_used_percent",
|
||||||
"unique_id": f"{serial_number}.storage_used_percent",
|
"unique_id": f"{serial_number}.storage_used_percent",
|
||||||
"entity_category": "diagnostic",
|
"entity_category": "diagnostic",
|
||||||
},
|
},
|
||||||
json=True,
|
json=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mqtt_publish(topics["home_assistant_legacy"]["storage_used"], "")
|
||||||
mqtt_publish(
|
mqtt_publish(
|
||||||
topics["home_assistant"]["storage_used"],
|
topics["home_assistant"]["storage_used"],
|
||||||
base_config
|
base_config
|
||||||
@@ -315,6 +386,7 @@ if home_assistant:
|
|||||||
json=True,
|
json=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mqtt_publish(topics["home_assistant_legacy"]["storage_total"], "")
|
||||||
mqtt_publish(
|
mqtt_publish(
|
||||||
topics["home_assistant"]["storage_total"],
|
topics["home_assistant"]["storage_total"],
|
||||||
base_config
|
base_config
|
||||||
@@ -335,19 +407,19 @@ mqtt_publish(topics["config"], {
|
|||||||
"version": version,
|
"version": version,
|
||||||
"device_type": device_type,
|
"device_type": device_type,
|
||||||
"device_name": device_name,
|
"device_name": device_name,
|
||||||
"sw_version": sw_version,
|
"sw_version": amcrest_version,
|
||||||
"serial_number": serial_number,
|
"serial_number": serial_number,
|
||||||
|
"host": amcrest_host,
|
||||||
}, json=True)
|
}, json=True)
|
||||||
|
|
||||||
if storage_poll_interval > 0:
|
if storage_poll_interval > 0:
|
||||||
refresh_storage_sensors()
|
refresh_storage_sensors()
|
||||||
|
|
||||||
ping_camera()
|
|
||||||
|
|
||||||
log("Listening for events...")
|
log("Listening for events...")
|
||||||
|
|
||||||
try:
|
async def main():
|
||||||
for code, payload in camera.event_actions("All", retries=5, timeout_cmd=(10.00, 3600)):
|
try:
|
||||||
|
async for code, payload in camera.async_event_actions("All"):
|
||||||
if (is_ad110 and code == "ProfileAlarmTransmit") or (code == "VideoMotion" and not is_ad110):
|
if (is_ad110 and code == "ProfileAlarmTransmit") or (code == "VideoMotion" and not is_ad110):
|
||||||
motion_payload = "on" if payload["action"] == "Start" else "off"
|
motion_payload = "on" if payload["action"] == "Start" else "off"
|
||||||
mqtt_publish(topics["motion"], motion_payload)
|
mqtt_publish(topics["motion"], motion_payload)
|
||||||
@@ -361,6 +433,8 @@ try:
|
|||||||
mqtt_publish(topics["event"], payload, json=True)
|
mqtt_publish(topics["event"], payload, json=True)
|
||||||
log(str(payload))
|
log(str(payload))
|
||||||
|
|
||||||
except AmcrestError as error:
|
except AmcrestError as error:
|
||||||
log(f"Amcrest error {error}", level="ERROR")
|
log(f"Amcrest error: {error}", level="ERROR")
|
||||||
exit_gracefully(1)
|
exit_gracefully(1)
|
||||||
|
|
||||||
|
asyncio.run(main())
|
||||||
|
|||||||
Reference in New Issue
Block a user