1. Introduction
A Home Assistant Dahua webcam dashboard card is created to show the life stream of our backyard camera within Home Assistant. We use the Dahua webcam to monitor our fish ponds so we can see which animals steal our fish and how, so we can bring counter measures in place. So far a blue heron, magpie and cats have managed in the past years to grab some fish from our pond. It turned out that the blue heron was the hungriest and smartest thief.
Our Dahua webcam is a so called PTZ camera (Dahua DH-SD22204T-GN-W) which makes it possible to move and zoom the lens. By creating PTZ presets in the camera it is possible to switch to predefined views via the web or mobile apps. Our Dahua webcam dashboard card includes buttons to switch the PTZ presets.
The next sections explain how to setup this Dahua webcam dashboard card for our situation, but can easily be adapted to suit your own webcam & situation (even if your webcam brand is not Dahua as most webcams use similar commands to switch the presets).
Note: We are still finetuning our dashboard card and will update this article accordingly.
2. Requirements
The following is required to reproduce the Dahua webcam dashboard card:
- A Dahua webcam
- Home Assistant Dahua integration
- Home Assistant Lovelace Custom button card
It is a prerequisite to have this card already installed. - Home Assistant Lovelace Vertical stack card
- Home Assistant Lovelace Grid card
Optionally:
- Philips Hue lights
We use these around our pond and when dark can be used to put the pond in bright light.
2. Configure the Dahua webcam
Before setting up the dashboard the webcam itself is configured.
- Login into the Dahua Webcam and create PTZ presets via settings > PTZ.
- Setup a user to be used from Home Assistant with only the rights needed. In our case a user HomeAssistant & password was created.
3. Integrate the Dahua webcam within Home Assistant
To make the life feed from the Dahua webcam available within Home Assistant we use the Dahua integration. This integration needs to be used for every Dahua webcam you want to add to Home Assistant.
- Within Home Assistant go to Settings and click the “Add integration” button. In the search field enter dahua.
- Enter the webcam connection details and click the submit button.
- The Dahua integration will show the added webcam(s).
For our camera 3 entities have been added for the live feeds; the main stream and 2 substreams.Additionally several other entities for the camera have been added depending on the selected and supported options such as motion detection, video loss, cross line alarm etc.Note: Achtertuin is Dutch for backyard.
4. Create the Dahua webcam dashboard card
Creating the Home Assistant dashboard card involves adding the webcam commands for the PZT presets switch to the configuration.yaml so these become available as a Home Assistant entity which can be executed from a button, which will be part of the custom button card.
4.1 Update configuration.yaml
- Open configuration.yaml in the Home Assistant file editor.
- For our situation the following is added:
12345678910111213141516171819shell_command:#DAHUA WEBCAM PTZ PRESET COMMANDS - ACHTERTUINwebcam_achtertuin_1_normaal: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=1&arg3=0"'webcam_achtertuin_2_vijver1: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=2&arg3=0"'webcam_achtertuin_3_vijver2: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=3&arg3=0"'webcam_achtertuin_4_border_zithoek: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=4&arg3=0"'webcam_achtertuin_5_compostbak: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=5&arg3=0"'webcam_achtertuin_6_vijver2_midden: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=6&arg3=0"'webcam_achtertuin_7_vijver2_links: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=7&arg3=0"'webcam_achtertuin_8_vijver2: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=8&arg3=0"'webcam_achtertuin_9_vijver2_rechts: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=9&arg3=0"'webcam_achtertuin_10_vijver3_overloop: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=10&arg3=0"'webcam_achtertuin_11_vijver1_midden: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=11&arg3=0"'webcam_achtertuin_12_vijver2_waterval: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=12&arg3=0"'webcam_achtertuin_13_preset13: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=13&arg3=0"'webcam_achtertuin_15_vijver1_niveau: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=15&arg3=0"'webcam_achtertuin_18_preset18: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=18&arg3=0"'webcam_achtertuin_19_preset19: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=19&arg3=0"'webcam_achtertuin_20_vijver1_rechts: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=20&arg3=0"'
Syntax of the PTZ preset command:
SHELL_COMMAND_NAME: ‘curl –digest -u “USERNAME:PASSWORD” -g “http://IP_ADDRESS:PORT/cgi-bin/ptz.cgi?action=start&channel=1&code=GotoPreset&arg1=0&arg2=PTZ_PRESET_NR&arg3=0″‘SHELL_COMMAND_NAME : the name the command will get in Home Assistant, for example "Shell Command: webcam_achtertuin_1_normaal". USERNAME : user as defined in the webcam (see section 2, step 2) PASSWORD : password as defined in the webcam (see section 2, step 2) IP_ADDRESS : IP address of the webcam PORT : port number of the webcam PTZ_PRESET_NR : number of the defined PTZ preset in section 2, step 1.
4.2 Configure the Dahua webcam dashboard card
The Dahua webcam card is based on the Lovelace vertical stack card which contains the Dahua camera stream in a picture entity and a Lovelace grid containing custom button cards for each button setting a specific PTZ camera preset. The whole configuration of the Dahua webcam dashboard card is shown below. Adapt the yaml code to your situation.
Note: In a later state detailed instruction will be posted how to create the dashboard card for people just starting with Home Assistant.
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
type: vertical-stack title: Achtertuin cards: - show_state: false show_name: false camera_view: auto type: picture-entity entity: camera.achtertuin_main name: Achtertuin tap_action: action: more-info hold_action: action: none camera_image: camera.achtertuin_main - square: false columns: 4 type: grid cards: - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_1_normaal name: Normaal icon: mdi:eye hold_action: action: none template: butonnav styles: icon: - color: green - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_2_vijver1 name: Vijver 1 icon: mdi:fish hold_action: action: none template: butonnav styles: icon: - color: blue - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_3_vijver2 name: Vijver 2 icon: mdi:fish hold_action: action: none template: butonnav styles: icon: - color: blue - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_4_border_zithoek name: Border / zithoek icon: mdi:eye hold_action: action: none template: butonnav styles: icon: - color: black - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_5_compostbak name: Compostbak icon: mdi:compost hold_action: action: none template: butonnav styles: icon: - color: lightgreen - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_6_vijver2_midden name: Vijver 2 midden icon: mdi:fish hold_action: action: none template: butonnav styles: icon: - color: blue - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_7_vijver2_links name: Vijver 2 links icon: mdi:fish hold_action: action: none template: butonnav styles: icon: - color: blue - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_8_vijver2 name: Vijver 2 icon: mdi:fish hold_action: action: none template: butonnav styles: icon: - color: blue - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_9_vijver2_rechts name: Vijver 2 rechts icon: mdi:fish hold_action: action: none template: butonnav styles: icon: - color: blue - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_10_vijver3_overloop name: Vijver 3 overloop icon: mdi:waterfall hold_action: action: none template: butonnav styles: icon: - color: lightblue - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_11_vijver1_midden name: Vijver 1 midden icon: mdi:fish hold_action: action: none template: butonnav styles: icon: - color: blue - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_12_vijver2_waterval name: Vijver 2 waterval icon: mdi:waterfall hold_action: action: none template: butonnav styles: icon: - color: lightblue - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_13_preset13 name: 13 icon: mdi:eye hold_action: action: none template: butonnav styles: icon: - color: black - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_15_vijver1_niveau name: Vijver 1 niveau icon: mdi:eye hold_action: action: none template: butonnav styles: icon: - color: black - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_18_preset18 name: 18 icon: mdi:eye hold_action: action: none template: butonnav styles: icon: - color: black - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_19_preset19 name: 19 icon: mdi:eye hold_action: action: none template: butonnav styles: icon: - color: black - show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: shell_command.webcam_achtertuin_20_vijver1_rechts name: 18 icon: mdi:eye hold_action: action: none template: butonnav styles: icon: - color: black - square: false columns: 4 type: grid title: Verlichting cards: - show_name: true show_icon: true type: custom:button-card tap_action: action: toggle entity: scene.achtertuin_vijver_1_fel name: Vijver 1 fel show_state: false hold_action: action: more-info icon: mdi:palette template: butonnav styles: icon: - color: yellow - show_name: true show_icon: true type: custom:button-card tap_action: action: toggle entity: scene.achtertuin_vijver_1_normaal name: Vijver 1 normaal show_state: false hold_action: action: more-info icon: mdi:palette template: butonnav styles: icon: - color: brown |
The custom button cards make use of the template “buttonnav”, which is as follows:
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 |
button_card_templates: butonnav: styles: card: - border-radius: 8px - height: 80px icon: - color: rgb(66, 134, 244) name: - height: 28px - font-weight: normal - color: black - font-size: 13px - padding: 0px 0px - justify-self: center - white-space: initial - text-overflow: initial - overflow: initial header: styles: card: - padding: 5px 15px - background-color: var(--paper-item-icon-active-color) name: - text-transform: uppercase - color: var(--primary-background-color) - justify-self: start - font-weight: bold label: - text-transform: uppercase - color: var(--primary-background-color) - justify-self: start - font-weight: bold header_red: template: header styles: card: - background-color: '#FF0000' |
To add this template to Home Assistant select edit dashboard and select again from the menu “raw configuration editor”. Add the template script at the top.
5. Finally
The Dahua webcam dashboard card should now look similar as shown in the introduction of this article. We are not finished with fine tuning our card, so more updates to come.
0 Comments