Here you have my configuration. https://github.com/hokus15/home-assistant-config
Feel free to ask me questions or make suggestions.
Here you have my configuration. https://github.com/hokus15/home-assistant-config
Feel free to ask me questions or make suggestions.
Screenshots in your README.md would be useful - that way people can take a look at the screenshots to see what you’ve got, then go to the appropriate yaml to steal it.
Yes idd, i want ask the same think
Screenshots added!
Fantastic project. I’ve a question. How can camera send alarm through mqtt protocol?
Hi,
I’ll try to explain step by step.
I have an automation in the automation.yaml to check the motion detection sensor from the cam (this example works for a C1 Foscam cam) if the motion detection is enabled:
- alias: 'Check swimming pool motion detection' trigger: platform: time seconds: '/15' condition: condition: state entity_id: switch.cam_swimmingpool_motion_detection state: 'on' action: service: shell_command.check_cam_swimmingpool_alarm
If the mnotion detection is enabled, this automation fires every 15 seconds the following command:
'mosquitto_pub --cafile /etc/ssl/certs/ca-certificates.crt -h <mqtt_broker> -p <mqtt_broker_port> -u <mqtt_user> -P <mqtt_password> -t "<topic>" -r -m 'curl -k --silent "https://<camera_host>:<camera_port>/cgi-bin/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=<camera_user>&pwd=<camera_password>" | grep -oP "(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)"''
Which checks the status of the alarm in the camera, and publish the result to mqtt.
I have a sensor in sensors.yaml:
`- platform: mqtt
state_topic: ‘home/camera/swimmingpool/alarm’
name: ‘cam_swimmingpool_alarm’
value_template: >-
{%- if value == “2” %}
Movimiento detectado
{% else %}
Normal
{%- endif %}`
That consumes the status of the alarm from mqtt.
The following automation in automation.yaml to notify to Telegram (including an snapshot of the camera) the alarm (if the sensor changes from ‘Normal’ to ‘Movimento detectado’ (Motion detected)):
- alias: 'Notify motion detection in swimming pool camera' trigger: platform: state entity_id: sensor.cam_swimmingpool_alarm from: 'Normal' to: 'Movimiento detectado' for: seconds: 30 action: service: notify.telegram data: title: 'Cámara' message: 'Movimiento detectado en la piscina.' data: photo: #URL: http://<cam_host>:<cam_port>/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=<username>&pwd=<password> - url: !secret cam_swimmingpool_snapPicture_url
To avoid false positive alarms I have configure my cam to mantain the alarm status for 15 seconds so the alarm only triggers if 2 consecutive alarms were detected.
I don’t know if it’s the most beautiful way to do it but it works.
Please, let me know if it’s clear enough.
it’s all very clear. I followed part of your configuration (camera motion mostly) and running from some days with no problems. I added an automation part to control motion detection switch state. If switch is off then “alarm” (for example sensor.cam_swimmingpool_alarm in your configuration) change in “Inactive”!
I’ve a question. The ink level´s work with HP envy 4500?
Congratulations for your project.
can you please help in setting up script for camera which i available in github. I am trying to get the image from foscam f8910w. I can upload the pics on ftp but if i try to run the script manually i get error - “ERROR:homeassistant.components.notify.telegram:Can’t load photo into ByteIO: [Errno 2] No such file or directo
Jan 10 10:06:42 homeserver hass[767]: ERROR:homeassistant.components.notify.telegram:Error sending photo”
i am trying to test the script -
curl -s -X POST -H “x-ha-access: xxx” “Content-Type: application/json” -d ‘{“message”: “text”, “data”: {“photo”: {“file”: "’$1’", “caption”: “Movement detected in ‘$2’”}}}’“192.168.xx.xx:8123/api/services/notify/telegram”
how to put mqtt - mosquitto_pub --cafile /etc/ssl/certs/ca-certificates.crt -h 192.168.XX.XX -p 8123 -u username -P password -t “home/camera/$2/alarm” -r -m 1
whats the use of ssl certs.
It seems that the printer is supported by CUPS and HPLIP, so it should work.
To get this working you need:
Regarding the mosquitto_pub I need the ssl certs because I use a cloudmqtt.com account and I want to use secure connection. This is not mandatory if your mqtt is local.
Hope that helps.
I am stuck in the script part. If i try to trigger script “curl -s -X POST -H “x-ha-access: xxx” “Content-Type: application/json” -d ‘{“message”: “text”, “data”: {“photo”: {“file”: "’$1’”, “caption”: “Movement detected in ‘$2’”}}}’“192.168.xx.xx:8123/api/services/notify/telegram” manually i can see error in the logs - “ERROR:homeassistant.components.notify.telegram:Can’t load photo into ByteIO: [Errno 2] No such file or directo
Jan 10 10:06:42 homeserver hass[767]: ERROR:homeassistant.components.notify.telegram:Error sending photo”
Thank you.
If you have everything installed, incrontab would call your script with a call similar to this:
sudo bash /home/pi/motion_detected.sh /home/camera/WVC54CGA/snap/170114113350001.jpg caseta
Keep in mind that the image file /home/camera/WVC54CGA/snap/170114113350001.jpg
MUST exist in the same file system where your hass server is running and the user running the hass server MUST have permission to read the file.
Let me know if that helps.
I will check. I have HA All in one installed and ftp folder is in pi.Had to find a way to check if hass user have access to the ftp folder
Also be sure you call the script passing 2 parameters
sudo bash /home/pi/motion_detected.sh /home/camera/WVC54CGA/snap/170114113350001.jpg caseta
Found another temporary way to get the image on telegram using script and i get instant image with this-
#!/bin/sh
SnapFile="/var/tmp/camsnapshot.jpg"
# Get snapshot
wget -O $SnapFile “http://192.168.xx.xx:80/snapshot.cgi?user=xxx&pwd=xxxx&count=0”
curl -s -X POST “https://api.telegram.org/bot123456789abcdefdorkbveee/sendPhoto” -F chat_id=xx -F photo="@$SnapFile"
# Remove Image
/bin/rm $SnapFile
mosquitto_pub -h 192.168.XX.XXX -p 1883 -u xxxx -P xxxx -t “home/camera/outside/alarm” -r -m 1
but i am not able to change status in binary script -
- platform: mqtt
state_topic: “home/camera/outside/alarm”
name: “cam_outdoor_alarm”
sensor_class: motion
# 0: No alarm
# 1: Alarm triggered
value_template: >-
{%- if value != “0” %}
ON
{% else %}
OFF
{%- endif %}
I can received the mqtt message when i run the bash file -
Any ideas what i can be doing wrong.
Hi all,
I also have a bash file and want to execute this when my doorbell rings. When I execute the .sh file in Putty it works perfect. But I don’t exactly know how to get this done. Any help is welcome!
What do you mean? Is the binary sensor working or not?
If the binary sensor is working and you want to disable it after some time you have to create an automation that triggers when the binary sensor goes to “ON” (in this example it tourns off after 15 seconds):
# Disable alarm for recibidor after 15 seconds of detection
- alias: 'Disable alarm for recibidor'
trigger:
platform: state
entity_id: binary_sensor.cam_hall_alarm
state: 'on'
action:
- delay:
seconds: 15
- service: mqtt.publish
data:
payload: 0
retain: true
topic: 'home/camera/recibidor/alarm'
Do you have your door bell somehow connected to Home-Assistant? if so you have to create an automation that triggers when your door bell rings that executes a shell command.