Ik ben nog steeds tevreden met deze custom component / integration.
Afgelopen week is er weer e.e.a. aan gesleuteld en verbeterd.
Behalve een aantal binary_sensors kun je zoals bovenstaand genoemd dus ook direct events afvangen in een
automation:
YAML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
| alias: Melding Dahua CLD
description: Cross Line Detection (event-based)
trigger:
- platform: event
event_type: dahua_event_received
event_data:
name: Dahua
Code: CrossLineDetection
action: Start
id: general
- platform: event
event_type: dahua_event_received
event_data:
name: Dahua
Code: CrossLineDetection
action: Start
data:
Object:
ObjectType: Human
id: Human Motion
- platform: event
event_type: dahua_event_received
event_data:
name: Dahua
Code: CrossLineDetection
action: Start
data:
Object:
ObjectType: Vehicle
id: Vehicle Motion
condition:
- condition: state
entity_id: input_boolean.dahua_cld_snapshot
state: 'on'
action:
- service: camera.snapshot
target:
entity_id: camera.dahua_sub
data:
filename: >-
/media/camera_snapshots/dahua_{{ datum_tijdstip }}_{{ ivs_rule_name }}.jpg
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 250
- service: notify.mobile_app_moto_g_8_power
data:
message: '{{ tijdstip }} Er is beweging gedetecteerd! ({{ ivs_rule_name }})'
data:
image: >-
/media/local/camera_snapshots/dahua_{{ datum_tijdstip }}_{{ ivs_rule_name }}.jpg
clickAction: /lovelace-thuis/camera-dahua
group: Cross Line Detection
ttl: 0
priority: high
tag: >-
/media/camera_snapshots/dahua_{{ datum_tijdstip }}_{{ ivs_rule_name}}.jpg
actions:
- action: DELETE_CAMERA_SNAPSHOT
title: Verwijderen
- action: TURN_OFF_DAHUA_CLD_SNAPSHOT
title: Uitschakelen + verwijderen
mode: queued
variables:
tijdstip: '{{ now().strftime("%H:%M") }}'
datum_tijdstip: '{{ now().strftime("%Y%m%d-%H%M%S.%f") }}'
ivs_rule_name: '{{ trigger.event.data.data.Name }}'
max: 3
max_exceeded: silent |
De beste beeldkwaliteit krijg je via handmatige instellingen (zie IPCamTalk). Probleem is dat dan het automatisch schakelen tussen dag- en nachtmodus niet lekker werkt. Dat valt op te lossen door te schakelen op tijd via een vast tijdschema, maar dan moet je wel telkens handmatig het tijdschema aanpassen aan zonopkomst en zonondergang.
Op IPCamTalk is hiervoor een DahuaSunriseSunset switch utility beschikbaar.
Maat het kan natuurlijk minstens zo goed direct vanuit Home Assistant!
configuration.yaml
YAML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| ### Include yaml files
script: !include scripts.yaml
script secret: !include scripts_secret.yaml
...
### Rest (multiple) sensors
rest:
# Dahua sensors
# alternatively retrieve resource from secrets.yaml
- resource: http://192.168.0.10/cgi-bin/configManager.cgi?action=getConfig&name=VideoInOptions[0].NightOptions
username: !secret dahua_usr
password: !secret dahua_pwd
authentication: digest
scan_interval: 3600
sensor:
# Dahua Sunrise/Sunset + SwitchMode
- name: "Dahua SunriseHour"
value_template: "{{ value.split('SunriseHour=')[1].split('\n')[0] }}"
- name: "Dahua SunriseMinute"
value_template: "{{ value.split('SunriseMinute=')[1].split('\n')[0] }}"
- name: "Dahua SunsetHour"
value_template: "{{ value.split('SunsetHour=')[1].split('\n')[0] }}"
- name: "Dahua SunsetMinute"
value_template: "{{ value.split('SunsetMinute=')[1].split('\n')[0] }}"
- name: "Dahua SwitchMode"
value_template: "{{ value.split('SwitchMode=')[1].split('\n')[0] }}"
...
### Shell commands
shell_command:
# Dahua configManager (because digest not supported in rest_command)
# (placeholder values go in data: section of service call)
dahua_config: curl -s -g --digest -u {{ usr }}:{{ pwd }} "http://{{ ip }}/cgi-bin/configManager.cgi?action={{ action }}" |
Elke nacht om 4:00 uur wordt gechecked of het verschil meer is dan 10 minuten. Zo ja, dan wordt het tijdschema bijgewerkt.
automations.yaml
YAML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| alias: Dahua Sunrise/Sunset schedule
trigger:
- platform: time
at: '04:00'
condition:
- condition: or
conditions:
- condition: template
value_template: '{{ (sunrise_min - dawn_min) | abs > 10 }}'
- condition: template
value_template: '{{ (sunset_min - dusk_min) | abs > 10 }}'
action:
- service: script.dahua_sunrise_sunset
- delay: 2
- service: script.dahua_update_sensors
mode: single
variables:
next_dawn: >-
{{ (as_timestamp(state_attr('sun.sun','next_dawn')) |
timestamp_custom('%-H:%-M')).split(':') }}
next_dusk: >-
{{ (as_timestamp(state_attr('sun.sun','next_dusk')) |
timestamp_custom('%-H:%-M')).split(':') }}
dawn_min: '{{ next_dawn[0] | int(0) * 60 + next_dawn[1] | int(0) }}'
dusk_min: '{{ next_dusk[0] | int(0) * 60 + next_dusk[1] | int(0) }}'
sunrise_min: >-
{{ states('sensor.dahua_sunrisehour') | int(0) * 60 +
states('sensor.dahua_sunriseminute') | int(0) }}
sunset_min: >-
{{ states('sensor.dahua_sunsethour') | int(0) * 60 +
states('sensor.dahua_sunsetminute') | int(0) }} |
Door te werken met een los bestand
scripts_secret.yaml is het gebruik van secrets mogelijk (kan niet via de GUI editor).
YAML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| dahua_update_sensors:
alias: Dahua update sensors
mode: single
sequence:
- service: homeassistant.update_entity
target:
entity_id:
- sensor.dahua_sunrisehour
- sensor.dahua_sunriseminute
- sensor.dahua_sunsethour
- sensor.dahua_sunsetminute
- sensor.dahua_switchmode
dahua_sunrise_sunset:
alias: Dahua Sunrise/Sunset
mode: single
sequence:
- service: shell_command.dahua_config
data:
ip: !secret dahua_ip
usr: !secret dahua_usr
pwd: !secret dahua_pwd
action: "setConfig&VideoInOptions[0].NightOptions.SunriseHour={{ time_sunrise[0] }}&VideoInOptions[0].NightOptions.SunriseMinute={{ time_sunrise[1] }}&VideoInOptions[0].NightOptions.SunsetHour={{ time_sunset[0] }}&VideoInOptions[0].NightOptions.SunsetMinute={{ time_sunset[1] }}"
- choose:
- conditions:
- condition: not
conditions:
- condition: state
entity_id: sensor.dahua_switchmode
state: '2'
sequence:
- service: shell_command.dahua_config
data:
ip: !secret dahua_ip
usr: !secret dahua_usr
pwd: !secret dahua_pwd
action: setConfig&VideoInOptions[0].NightOptions.SwitchMode=2
variables: # in list form
# rising occurs after dawn
time_sunrise: "{{ (as_timestamp(state_attr('sun.sun','next_rising')) | timestamp_custom('%-H:%-M')).split(':') }}"
# setting occurs before dusk
time_sunset: "{{ (as_timestamp(state_attr('sun.sun','next_setting')) | timestamp_custom('%-H:%-M')).split(':') }}" |
De check op
sensor.dahua_switchmode is om te voorkomen dat het tijdschema wordt ingeschakeld als er een andere instelling actief is op de camera.
Het mooie aan Home Assistant vind ik dat je veel dingen aan elkaar kunt scripten, met trial-and-error kom je een heel eind. En natuurlijk de documentatie lezen.