Hikvision Still Image - Telegram

Maybe niedejb has a good point I hadn’t thought of.
I create users for HA in my cameras and give them simple passwords.
Maybe make a new user and try that.
Focus on getting it to work with the browser again and then come back to this.
Might have to do a factory reset on the cam and try again.

Almost sounds like things are happening too fast. Maybe a 1 sec delay in your automation?

Okay this sat on my phone for a few mins of me being distracted so I’m shotgunning a few ideas at once here.
Let us know how it goes.

After some research, apparently Chrome stopped basic authentication in one of the older versions of Chrome.

I still cannot wrap my head around why all my camera automation work when triggered manually, I am able to trigger them any number of times in rapid succession and it works each and every time. :weary:

Could you please post your entire automation?
Maybe there is something in there we can find??

Sure, I will post all the automation’s i have tried.

- id: '1573838226495'
  alias: Line Crossed
  description: ''
  trigger:
  - entity_id: binary_sensor.study_camera_line_crossing
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      caption: Motion Detected
      disable_notification: false
      target: '[Telegram Group ID]'
      url: http://user:[email protected]/ISAPI/Streaming/channels/101/picture
    service: telegram_bot.send_photo
- id: '1574335919858'
  alias: Line Crossed 02
  description: ''
  trigger:
  - entity_id: binary_sensor.study_camera_line_crossing
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: camera.study_camera
      filename: /share/security/studyCam/studycam_{{ now ().year }}_{{ now().month}}_{{now().day
        }}_{{ now ().hour }}_{{ now ().minute }}.jpg
    service: camera.snapshot
  - data:
      caption: Motion Detected
      disable_notification: false
      file: /share/security/studyCam/studycam_{{ now ().year }}_{{ now ().month}}_{{now().day
        }}_{{ now ().hour }}_{{ now ().minute }}.jpg
      target: '[Telegram Group ID]'
    service: telegram_bot.send_photo
- id: '1574356580433'
  alias: Line Crossing 3
  description: ''
  trigger:
  - entity_id: binary_sensor.study_camera_line_crossing
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      data:
        photo:
        - caption: Motion Detected
          url: http://user:[email protected]/ISAPI/Streaming/channels/101/picture
      message: Motion Detected
    service: notify.telegram_notifications

Below is the setup of the components.

Notifications:

telegram_bot:
  - platform: webhooks
    api_key: [API Key]
    parse_mode: html
    allowed_chat_ids:
      - '[Telegram Group ID]'
      
notify:
  - name: telegram_notifications
    platform: telegram
    chat_id: '[Telegram Group ID]'

Motion Sensor

binary_sensor:
  - platform: hikvision
    host: 10.0.0.21
    username: user
    password: pass
    name: Study Camera
    customize:
      field_detection:
        delay: 10
      line_crossing:
        delay: 10

Camera (This is the current config, but i have tried many variations)

camera:
    - platform: generic
      name: Study Camera
      still_image_url: http://user:pass10.0.0.21/ISAPI/Streaming/channels/101/picture
      stream_source: "rtsp://user:[email protected]:554/Streaming/Channels/102"
      authentication: digest
      username: user
      password: pass
      verify_ssl: false
      content_type: image/png

I also have the current setup in NodeRed

[{"id":"d58d235f.601db","type":"chatbot-telegram-send","z":"47b53e8c.3fa31","bot":"3a5b5d6b.5c5192","botProduction":"","track":false,"passThrough":false,"outputs":0,"x":1010,"y":200,"wires":[]},{"id":"2c674204.4ba82e","type":"chatbot-conversation","z":"47b53e8c.3fa31","name":"Start Conversation","botDevelopment":"3a5b5d6b.5c5192","botProduction":"","chatId":"xxxxxxx","userId":"","transport":"telegram","store":"","x":350,"y":200,"wires":[["ae30f562.9a97f8","c78bb7fd.805768","bdfad32b.66c2a"]]},{"id":"ae30f562.9a97f8","type":"http request","z":"47b53e8c.3fa31","name":"","method":"GET","ret":"bin","paytoqs":false,"url":"http://10.0.0.21/ISAPI/Streaming/channels/101/picture","tls":"","persist":false,"proxy":"","authType":"digest","x":590,"y":200,"wires":[["6dc6ab5e.b079f4"]]},{"id":"6dc6ab5e.b079f4","type":"chatbot-image","z":"47b53e8c.3fa31","name":"","filename":"","image":"","caption":"","x":790,"y":200,"wires":[["d58d235f.601db"]]},{"id":"c78bb7fd.805768","type":"chatbot-waiting","z":"47b53e8c.3fa31","waitingType":"upload_photo","x":680,"y":280,"wires":[["d58d235f.601db"]]},{"id":"bdfad32b.66c2a","type":"debug","z":"47b53e8c.3fa31","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":450,"y":300,"wires":[]},{"id":"85ce3687.490308","type":"server-state-changed","z":"47b53e8c.3fa31","name":"Line Crossing","server":"5fe5263.a1c9fd8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.study_camera_line_crossing","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"x":90,"y":200,"wires":[["bdfad32b.66c2a","2c674204.4ba82e"],[]]},{"id":"6b1f46b4.84ebb8","type":"inject","z":"47b53e8c.3fa31","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":300,"wires":[["2c674204.4ba82e"]]},{"id":"3a5b5d6b.5c5192","type":"chatbot-telegram-node","z":"","botname":"DEV","usernames":"xxxxxxx","providerToken":"","polling":"300","store":"","log":"","parseMode":"","debug":false,"webHook":"","connectMode":"polling"},{"id":"5fe5263.a1c9fd8","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]

Each one of these work 100% when I trigger them manually. It is only when actual motion is detected that it fails about 80% of the time. Below is a screenshot of the motion triggers in HA, a total of 36 triggers in the passed 30 minutes. (Thanks to the spider making a web around the camera). Out of these 36 triggers I received 4 notifications on telegram.

On my system, the still image comes from /channels/1/picture and I have authentication: basic on every one of the camera configs.

Maybe your pi isn’t able to process them fast enough?

I will switch to basic authentication and give it a shot.

It is currently running on an i3 NUC, I think it should have enough grunt for the notifications.

mine too. definitely enough.

Just updating the firmware on the camera and will give it a factory reset and see if that helps.

Well if you trigger manually you are just running the action part of it so that makes sense that it always works.
So the state change seems like it isn’t behaving.
I noticed the 10 second delay in your motion sensor.
Could that be something causing issues?


This says it will wait until after the sensor event ends to notify, but then it doesn’t make sense that you have 36 detected there, but only 4 notifications. Is it too rapid for telegram?
I personally have a delay in mine sending notifications, but that came about before I had my current setup and wasn’t for telegram. I have an outdoor motion sensor hooked to my alarm so it will trigger very quickly. Made the house seem like a rave with some flashing lights to let us know something is out there. Now mine will only send me a pic if it hasn’t triggered for 30 seconds.

What is that last screenshot of all the triggers? I don’t think I’ve seen that one before.

I’ve sent thousands of messages to telegram in a row. I doubt it’s a problem on telegram

Yeah, i agree with this. As i test i hit the trigger button maybe 20 times in rapid succession, each notification came through successfully.

I am going to try remove the delay on the sensor and shift the delay onto the automation.

Trying all the automations with your recommended settings and i get the below errors.

Line Crossing 2 Automation:

Log Details (ERROR)
Sun Dec 22 2019 10:49:03 GMT+0200 (South Africa Standard Time)
Error sending file: Image_process_failed. Args: (Telegram Group ID, <_io.BufferedReader name='/share/security/studyCam/studycam_2019_12_22_10_49.jpg'>), kwargs: {'caption': 'Motion Detected', 'parse_mode': 'Markdown', 'disable_notification': False, 'disable_web_page_preview': None, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}

Log Details (ERROR)
Sun Dec 22 2019 14:38:19 GMT+0200 (South Africa Standard Time)
Error sending file: Image_process_failed. Args: (Telegram Group ID, <_io.BufferedReader name='/share/security/studyCam/studycam_2019_12_22_14_38.jpg'>), kwargs: {'caption': 'Motion Detected', 'parse_mode': 'Markdown', 'disable_notification': False, 'disable_web_page_preview': None, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}


Line Crossing 3 Automation:

Sun Dec 22 2019 21:34:16 GMT+0200 (South Africa Standard Time)
Can't send file with kwargs: {'message': 'Motion Detected', 'caption': 'Motion Detected', 'url': 'http://user:[email protected]/ISAPI/Streaming/channels/101/picture'}

Can I ask a silly question
Why do you have it in node red as well.

OH! This is actually an excellent question, because it could be the cause for the sporadic messages.

Your bot can’t be accessed by 2 different methods like this. I had issues when trying to use 2 different node-red telegram bot implementations (telegram and chat-bot). The errors indicated that one of them couldn’t login because it was already logged in.

I didn’t even notice this earlier in the thread. Good catch.

disconnect one of the bot notifications (HA or Node Red) and try again.

I know it wasn’t a silly question
i was trying to be as polite as possible

sometimes the answer is right in front of you
and i still can’t see it

I added it to NodeRed when the HA automation stopped working. During testing i make sure to remove the Telegram integrations on the one or the other that i wasn’t testing at the time.

If both run at the same time the HA logs fill up with the below error.

ERROR (updater) [telegram.ext.updater] Error while getting Updates: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running (409)

I am losing steam trying to resolve this issue. It all worked flawlessly for over a month and now nothing.

Can i suggest something
break it up into 2 parts

  1. use the downloader to download the snapshot to the local file
  2. send the file to telegram

Giving this a shot now. I will just let the automation run for a day downloading the file to the directory, if that works fine i will then tie it into Telegram. Thanks for the suggestion.

Let me know how you go
I may want to pinch your code for the telegram.
Once i get the person detection implemented. I have too many trees blowing in the wind to use motion detect as a reliable trigger

It seems like my issue is 95% the camera’s fault.

I get the below 503 when using the downloader.

downloading 'http://user:[email protected]/ISAPI/Streaming/channels/101/picture' failed, status_code=503

So i will tinker around with the camera a bit more. Thanks for all the suggestions.