diff --git a/deepstack/stacks/compose.yml b/deepstack/stacks/compose.yml new file mode 100644 index 0000000..a9405ab --- /dev/null +++ b/deepstack/stacks/compose.yml @@ -0,0 +1,25 @@ +services: + deepstack: + container_name: deepstack + restart: unless-stopped + image: deepquestai/deepstack + ports: + - '5000:5000' + environment: + - VISION-DETECTION=True + - API-KEY="" + volumes: + - /Users/robin/Data/pytorch-models:/modelstore/detection + deepstack_ui: + container_name: deepstack_ui + restart: unless-stopped + image: robmarkcole/deepstack-ui:latest + environment: + - DEEPSTACK_IP=deepstack + - DEEPSTACK_PORT=5000 + - DEEPSTACK_API_KEY="" + - DEEPSTACK_TIMEOUT=20 + - DEEPSTACK_CUSTOM_MODEL=fire + - DEEPSTACK_UI_DEBUG_MODE=True + ports: + - '8501:8501' \ No newline at end of file diff --git a/home-assistant/home-automation2.txt b/home-assistant/home-automation2.txt new file mode 100644 index 0000000..7f72b1d --- /dev/null +++ b/home-assistant/home-automation2.txt @@ -0,0 +1,171 @@ +https://www.youtube.com/watch?v=gA67NCcTwms&t=621s + +# Automation yaml file +--- snip --- +alias: "FRIGATE: Notify driveway zone1 person detection" +description: FRIGATE notify - driveway +triggers: + - topic: homeassistant/events + trigger: mqtt +conditions: + - condition: template + value_template: "{{ trigger.payload_json['after']['label'] == 'person' }}" + - condition: template + value_template: "{{ 'driveway_z1' in trigger.payload_json['after']['entered_zones']}}" +actions: + - action: notify.mobile_app_sm_n986b + data_template: + message: A {{trigger.payload_json["after"]["label"]}} was detected. + title: Frigate + data: + image: >- + https://home-assistant.sthome.org/api/frigate/notifications/{{trigger.payload_json["after"]["id"]}}/thumbnail.jpg?format=android + tag: "{{trigger.payload_json[\"after\"][\"id\"]}}" + when: "{{trigger.payload_json[\"after\"][\"start_time\"]|int}}" + actions: + - action: URI + title: Open Image + uri: >- + https://home-assistant.sthome.org/api/frigate/notifications/{{trigger.payload_json["after"]["id"]}}/thumbnail.jpg?format=android + enabled: true +mode: single +--- snip --- + +# Install home-assistant app on your android phone from the play store +# After installation and connection to you home-assistant server, on home-assistant server (on computer), navigate to Settings -> Devices & services -> Integrations. Look for your Mobile App in the list of integrations. +# To change the name of the device, click on the 3 dot menu next to the device name under Integration Entities and select Rename. + +# open app on phone and from the Overview screen, click on hamburger menu -> Settings -> Companion app -> Notification channels + +# With the device name now known, edit the yaml file above to reflect the device name, e.g. +# if device name is SM-N986B, then +- action: notify.mobile_app_samsung_sm_n986b + + +To create a script using GUI +---------------------------- +Navigate to Settings -> Automations & Scenes -> Scripts +Click "+ CREATE SCRIPT" +Click Create New Script + +To create script directly using yaml +------------------------------------ +In truenas shell, go to config/scripts folder +# Create custom scripts folder to keep scripts organised +mkdir custom_scripts +# Create script file using nano editor, for example: +nano custom_scripts/send_dynamic_notification_to_all_devices.yaml +# Then edit scripts.yaml to include newly created script file +nano scripts.yaml +# Enter following line in scripts.yaml file, save and exit +script: !include_dir_merge_named custom_scripts/ + + + +------------------------- +alias: Outside - Driveway & Front Yard - Frigate Event - Cat / Dog / Person Seen +description: '' +# The trigger is mqtt and will fire whenever an object is detected by YOUR_CAMERA_NAME +trigger: + - platform: mqtt + topic: frigate/events + id: frigate-event + payload: YOUR_CAMERA_NAME + value_template: "{{ value_json['after']['camera'] }}" + variables: + after_zones: "{{ trigger.payload_json['after']['entered_zones'] }}" + before_zones: "{{ trigger.payload_json['before']['entered_zones'] }}" + camera: "{{ trigger.payload_json['after']['camera'] }}" + id: "{{ trigger.payload_json['after']['id'] }}" + label: "{{ trigger.payload_json['after']['label'] }}" + score: "{{ trigger.payload_json['after']['score'] }}" + time_clip_start: "{{ trigger.payload_json['after']['start_time'] - 10.0 }}" +# Conditions must be used to filter out objects / detections that are not of interest +condition: + # This condition is used to ensure that I am only notified of objects that are new or only just entered a zone. This is to avoid getting loads of updated notifications for the same dog in my backyard (as an example). + - condition: or + conditions: + - condition: template + value_template: "{{ trigger.payload_json['type'] == 'new' }}" + - condition: template + value_template: "{{ before_zones | length == 0 }}" + # This ensures that the object at least has one zone, this can be removed if you don't care about zones + - condition: template + value_template: '{{ trigger.payload_json["after"]["entered_zones"]|length > 0 }}' + # This specifically checks for the object to be in the driveway or front_yard zone. This can be removed or those names changed to fit your use case. +for example: + - condition: template + value_template: >- + {{ ["driveway", "front_yard"] | select("in", + after_zones) | list | length > 0 }} + alias: Object is in Driveway or Front Yard + # This filters out any car objects as I have a separate automation with different behavior for car. This can be removed if not applicable to your use case. + - condition: template + value_template: '{{ trigger.payload_json["after"]["label"] != "car" }}' +action: + - choose: + - conditions: + - condition: trigger + id: frigate-event + sequence: + # Send the initial notification with snapshot and info. + - service: script.send_dynamic_notification_to_all_devices + data: + id: "{{ id }}" + title: >- + {{ label }} was + detected on {{ camera | + replace("_", " ") | title }} + message: >- + {{ label }} detected in + the {{ after_zones[0] | + replace("_", " ") | title }} + notifTag: "{{ id }}" + notifIcon: mdi:doorbell-video + group: >- + frigate-notification-{{ camera }} + importance: max + image: >- + /api/frigate/notifications/{{ id }}/snapshot.jpg + clickAction: '' + # Wait until the end of the notification has occurred. + - repeat: + until: + - condition: template + value_template: '{{ wait.trigger.payload_json["type"] == "end" }}' + sequence: + - wait_for_trigger: + - platform: mqtt + topic: frigate/events + payload: "{{ trigger.payload_json[\"after\"][\"id\"] }}" + value_template: "{{ value_json[\"after\"][\"id\"] }}" + continue_on_timeout: false + timeout: '00:02:00' + - condition: template + value_template: '{{ wait.trigger.payload_json[''type''] == ''end'' }}' + - service: script.send_dynamic_notification_to_all_devices + data: + id: '{{ id }}' + # Uses double take for title and message to include face info if a match is detected. + title: >- + {% if (wait.trigger.payload_json["after"]["sub_label"] != + None) -%} {{ (wait.trigger.payload_json["after"]["sub_label"]) + | title }} {%- else -%} {{ label | replace("_", " ") | title + }} {%- endif %} was detected in the {{ after_zones[0] | + replace("_", " ") | title }} + message: Detected with {{ int(score | round(2) * 100) }}% confidence + notifTag: '{{ id }}' + notifIcon: mdi:doorbell-video + group: >- + frigate-notification-{{ + trigger.payload_json["after"]["camera"] }} + importance: default + image: >- + /api/frigate/notifications/{{ id }}/snapshot.jpg + video: >- + HASS_URL_BASE/api/{{id}}/{{camera}}/clip.mp4 + clickAction: >- + http://HASS_URL_BASE/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4 + default: [] +mode: parallel +max: 10 diff --git a/home-assistant/home-automation3.yml b/home-assistant/home-automation3.yml new file mode 100644 index 0000000..0ca1138 --- /dev/null +++ b/home-assistant/home-automation3.yml @@ -0,0 +1,106 @@ +alias: Outside - Driveway & Front Yard - Frigate Event - Cat / Dog / Person Seen +description: '' +# The trigger is mqtt and will fire whenever an object is detected by YOUR_CAMERA_NAME +trigger: + - platform: mqtt + topic: frigate/events + id: frigate-event + payload: YOUR_CAMERA_NAME + value_template: "{{ value_json['after']['camera'] }}" + variables: + after_zones: "{{ trigger.payload_json['after']['entered_zones'] }}" + before_zones: "{{ trigger.payload_json['before']['entered_zones'] }}" + camera: "{{ trigger.payload_json['after']['camera'] }}" + id: "{{ trigger.payload_json['after']['id'] }}" + label: "{{ trigger.payload_json['after']['label'] }}" + score: "{{ trigger.payload_json['after']['score'] }}" + time_clip_start: "{{ trigger.payload_json['after']['start_time'] - 10.0 }}" +# Conditions must be used to filter out objects / detections that are not of interest +condition: + # This condition is used to ensure that I am only notified of objects that are new or only just entered a zone. This is to avoid getting loads of updated notifications for the same dog in my backyard (as an example). + - condition: or + conditions: + - condition: template + value_template: "{{ trigger.payload_json['type'] == 'new' }}" + - condition: template + value_template: "{{ before_zones | length == 0 }}" + # This ensures that the object at least has one zone, this can be removed if you don't care about zones + - condition: template + value_template: '{{ trigger.payload_json["after"]["entered_zones"]|length > 0 }}' + # This specifically checks for the object to be in the driveway or front_yard zone. This can be removed or those names changed to fit your use case. +for example: + - condition: template + value_template: >- + {{ ["driveway", "front_yard"] | select("in", + after_zones) | list | length > 0 }} + alias: Object is in Driveway or Front Yard + # This filters out any car objects as I have a separate automation with different behavior for car. This can be removed if not applicable to your use case. + - condition: template + value_template: '{{ trigger.payload_json["after"]["label"] != "car" }}' +action: + - choose: + - conditions: + - condition: trigger + id: frigate-event + sequence: + # Send the initial notification with snapshot and info. + - service: script.send_dynamic_notification_to_all_devices + data: + id: "{{ id }}" + title: >- + {{ label }} was + detected on {{ camera | + replace("_", " ") | title }} + message: >- + {{ label }} detected in + the {{ after_zones[0] | + replace("_", " ") | title }} + notifTag: "{{ id }}" + notifIcon: mdi:doorbell-video + group: >- + frigate-notification-{{ camera }} + importance: max + image: >- + /api/frigate/notifications/{{ id }}/snapshot.jpg + clickAction: '' + # Wait until the end of the notification has occurred. + - repeat: + until: + - condition: template + value_template: '{{ wait.trigger.payload_json["type"] == "end" }}' + sequence: + - wait_for_trigger: + - platform: mqtt + topic: frigate/events + payload: "{{ trigger.payload_json[\"after\"][\"id\"] }}" + value_template: "{{ value_json[\"after\"][\"id\"] }}" + continue_on_timeout: false + timeout: '00:02:00' + - condition: template + value_template: '{{ wait.trigger.payload_json[''type''] == ''end'' }}' + - service: script.send_dynamic_notification_to_all_devices + data: + id: '{{ id }}' + # Uses double take for title and message to include face info if a match is detected. + title: >- + {% if (wait.trigger.payload_json["after"]["sub_label"] != + None) -%} {{ (wait.trigger.payload_json["after"]["sub_label"]) + | title }} {%- else -%} {{ label | replace("_", " ") | title + }} {%- endif %} was detected in the {{ after_zones[0] | + replace("_", " ") | title }} + message: Detected with {{ int(score | round(2) * 100) }}% confidence + notifTag: '{{ id }}' + notifIcon: mdi:doorbell-video + group: >- + frigate-notification-{{ + trigger.payload_json["after"]["camera"] }} + importance: default + image: >- + /api/frigate/notifications/{{ id }}/snapshot.jpg + video: >- + HASS_URL_BASE/api/{{id}}/{{camera}}/clip.mp4 + clickAction: >- + http://HASS_URL_BASE/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4 + default: [] +mode: parallel +max: 10 diff --git a/mosquitto/mosquitto_jm.txt b/mosquitto/mosquitto_jm.txt index 7a8c44f..73edc43 100644 --- a/mosquitto/mosquitto_jm.txt +++ b/mosquitto/mosquitto_jm.txt @@ -63,6 +63,16 @@ cp -pr /mnt/stpool1/apps/mosquitto/* /mnt/SSD1/docker/data/mosquitto/config/conf chown -R mosquitt:mosquitt /mnt/SSD1/docker/data/mosquitto/ chmod -R 700 /mnt/SSD1/docker/data/mosquitto/ +Creating mosquitto user +----------------------- +# start mosquitto app with Dockge or issuing "docker compose up -d" in stacks/mosquitto folder +# open shell on mosquitto +docker exec -it mosquitto-mosquitto-1 sh +# enter following line in mosquitto app shell, replacing with the appropriate mosquitto username +mosquitto_passwd -c /mosquitto/config/password.txt +# enter and confirm the password +# exit mosquitto shell + Test mosquitto -------------- # TODO diff --git a/mosquitto/stacks/compose.yml b/mosquitto/stacks/compose.yml index f9dd0d6..10f85ed 100644 --- a/mosquitto/stacks/compose.yml +++ b/mosquitto/stacks/compose.yml @@ -28,7 +28,7 @@ services: # tcp services # ------------- - "traefik.tcp.services.${APPLICATION_NAME}-svc.loadbalancer.server.port=${SERVICE_PORT}" - - "traefik.tcp.services.${APPLICATION_NAME}-secure-svc.loadbalancer.server.port=${SECURE_SERVICE_PORT}" + #- "traefik.tcp.services.${APPLICATION_NAME}-secure-svc.loadbalancer.server.port=${SECURE_SERVICE_PORT}" # # tcp routers # ------------ @@ -48,6 +48,7 @@ services: # passthrough tls - "traefik.tcp.routers.${APPLICATION_NAME}-secure-rtr.tls.passthrough=true" # generate certificates using following certresolver - - "traefik.tcp.routers.${APPLICATION_NAME}-secure-rtr.tls.certresolver=sthomeresolver" + - "traefik.tcp.routers.${APPLICATION_NAME}-secure-rtr.tls.certresolver=solver-dns" # assign svc target to routers - - "traefik.tcp.routers.${APPLICATION_NAME}-secure-rtr.service=${APPLICATION_NAME}-secure-svc" + #- "traefik.tcp.routers.${APPLICATION_NAME}-secure-rtr.service=${APPLICATION_NAME}-secure-svc" + - "traefik.tcp.routers.${APPLICATION_NAME}-secure-rtr.service=${APPLICATION_NAME}-svc" # use same svc as non-secure router to avoid issues with certificates on mosquitto diff --git a/traefik/stacks/compose.yml b/traefik/stacks/compose.yml index 941b50a..ddb101d 100644 --- a/traefik/stacks/compose.yml +++ b/traefik/stacks/compose.yml @@ -70,6 +70,10 @@ services: published: "8883" protocol: tcp mode: host + - target: 9001 # mosquitto websocket port + published: "9001" + protocol: tcp + mode: host - target: 19132 # minecraft-bedrock port published: "19132" protocol: udp diff --git a/traefik/stacks/config/traefik.yml b/traefik/stacks/config/traefik.yml index 5bf58d9..d55e399 100644 --- a/traefik/stacks/config/traefik.yml +++ b/traefik/stacks/config/traefik.yml @@ -52,45 +52,30 @@ entryPoints: - "10.0.0.0/24" - "192.168.2.0/24" - "172.16.0.0/12" - wireguard: address: ":51820/udp" - plex: address: ":32400" - http: - redirections: - entrypoint: - to: websecure - scheme: https - metrics: address: ":8082" - ping: address: ":8083" - mariadb: address: ":8306" - mysql: address: ":9306" - mqtt: address: ":1883" - mqttsecure: address: ":8883" - + mqttwebsocket: + address: ":9001" mc-bedrock: address: ":19132/udp" - mc-java: address: ":25565/udp" - mc-java-rcon: address: ":25575" - sftp1: address: ":2022" sftp2: