hass-xiaomi-miot icon indicating copy to clipboard operation
hass-xiaomi-miot copied to clipboard

Camera issues

Open al-one opened this issue 2 years ago • 83 comments

This component supports Xiaomi cameras, but if you need to be able to play video streams in HA, the device needs to meet the following conditions:

  • [x] Service camera-stream-for-google-home needs to be defined in camera device miot-spec (find your camera spec here)
  • [x] The stream address can be obtained after the device is integrated (stream_address attribute in entity state)
  • [x] The stream address can be accessed normally within the validity period (stream_http_status and stream_http_reason attributes in entity state)
  • [x] The stream address can be transcoded normally by ffmpeg, test via shell command:
    ffmpeg -v warning -y -protocol_whitelist file,http,https,rtp,udp,tcp,tls,crypto -i 'https://cn.livestreaming.io.mi.com/hlstranscoder/XXXXXX_H265transH264/playlist.m3u8' -an -c:v mjpeg -f mpjpeg xiaomi_camera_video
    

What information do you need to show me when report a bug for camera ?

  • Camera device model (Like: brand.camera.abc) Required
  • Masked stream_address
  • stream_http_status and stream_http_reason attributes in entity state
  • ffmpeg test results

本组件支持小米摄像机,但是如果需要能在HA中播放视频流,需要设备满足以下条件:

  • 相机设备miot-spec中需定义流服务 (在这里找到你的相机规格)
  • 集成设备后能够获取到流地址 (实体状态的属性stream_address)
  • 流地址在有效期内能够正常访问 (实体状态的属性stream_http_statusstream_http_reason)
  • 流地址能被ffmpeg能够正常转码,通过shell命令测试:
    ffmpeg -v warning -y -protocol_whitelist file,http,https,rtp,udp,tcp,tls,crypto -i 'https://cn.livestreaming.io.mi.com/hlstranscoder/XXXXXX_H265transH264/playlist.m3u8' -an -c:v mjpeg -f mpjpeg xiaomi_camera_video
    

报告Bug时需要向我展示哪些信息?

  • 相机设备型号 (如:brand.camera.abc) 必填
  • 掩码的流地址
  • 实体状态的属性stream_http_statusstream_http_reason
  • ffmpeg测试结果

al-one avatar Aug 17 '21 11:08 al-one

Camera device model: chuangmi.camera.021a04 camera-stream-for-google-home is present https://home.miot-spec.com/spec?type=urn%3Amiot-spec-v2%3Adevice%3Acamera%3A0000A01C%3Achuangmi-021a04%3A2 Masked stream_address: https://de21.livestreaming.io.mi.com/hlstranscoder/(63...chars)_H265transH264/playlist.m3u8 stream_http_status and stream_http_reason attributes in entity state: not present ffmpeg test results:

ffmpeg -v warning -y -protocol_whitelist file,http,https,rtp,udp,tcp,tls,crypto -i 'https://de21.livestreaming.io.mi.com/hlstranscoder/(63...chars)_H265transH264/playlist.m3u8' -an -c:v mjpeg -f mpjpeg xiaomi_camera_video

[https @ 0x7f8077511c40] HTTP error 403 Forbidden
https://de21.livestreaming.io.mi.com/hlstranscoder/(63...chars)_H265transH264/playlist.m3u8: Server returned 403 Forbidden (access denied)

Full entity:

access_token: xxxx
brand: chuangmi
model: chuangmi.camera.021a04
lan_ip: <IP>
mac_address: <MAC>
firmware_version: 4.1.6_0309
hardware_version: ''
entity_class: MiotCameraEntity
miot_type: urn:miot-spec-v2:device:camera:0000A01C:chuangmi-021a04:3
camera_control.on: true
camera_control.image_rollover: 0
camera_control.night_shot: 2
camera_control.wdr_mode: true
glimmer_full_color-2-6: true
camera_control.recording_mode: 0
camera_control.motion_tracking: false
camera_control.time_watermark: true
bluetooth.bluetooth_switch.error: '-704040002 Service does not exist'
stream_status-8-9: 1
stream_status-7-9: 1
motion_detection: false
motion_detection.alarm_interval: 5
detection_sensitivity-5-3: 1
motion_detection_start_time-5-4: '00:00:00'
motion_detection_end_time-5-5: '23:59:59'
memory_card_management.status: 0
storage_total_space-4-2: 15138816
storage_free_space-4-3: 40960
storage_used_space-4-4: 15097856
indicator_light.on: true
state_updater: cloud
miot_action_result:
  did: 'xxxxx'
  miid: 0
  siid: 7
  aiid: 1
  code: 0
  out:
    - >-
      https://de01.livestreaming.io.mi.com/hlstranscoder/XXXXXX/playlist.m3u8
  exe_time: 0
  net_cost: 0
  ot_cost: 0
  otlocalts: 0
  oa_cost: 0
  _oa_rpc_cost: 0
stream_address: ''
expire_at: '2021-08-17 16:24:07.122040'
sub_entities:
  - camera_control.on
  - motion_detection-5.motion_detection-1
  - indicator_light-3
friendly_name: Mi 360° Home Security Camera 2K Pro Camera Control
entity_picture: >-
  /api/camera_proxy/camera.mi_360deg_home_security_camera_2k_pro_camera_control?token=XXXXXX
supported_features: 3
video_attribute: 2

Also sometimes in logs (UPD Fixed in master):

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 197, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 78, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 144, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 135, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 517, in get
    return await self.handle(request, camera)
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 534, in handle
    image = await camera.async_camera_image()
  File "/config/custom_components/xiaomi_miot/camera.py", line 245, in async_camera_image
    url = await self.stream_source()
  File "/config/custom_components/xiaomi_miot/camera.py", line 188, in stream_source
    odt = self._act_start_stream.out_results(result.get('out')) or {
AttributeError: 'bool' object has no attribute 'get'

UPD Looks like the stream are working few minutes (via URL), but not in HA

I was able to open the stream with VLC and it's working fine

https://de09.livestreaming.io.mi.com/hlstranscoder/xxxxxx_H265transH264/playlist.m3u8

With FFmpeg

ffmpeg -v warning -y -protocol_whitelist file,http,https,rtp,udp,tcp,tls,crypto -i 'https://de09.livestreaming.io.mi.com/hlstranscoder/xxxxx_H265transH264/playlist.m3u8' -an -c:v mjpeg -f mpjpeg xiaomi_camera_video

[swscaler @ 0x7fe980108000] deprecated pixel format used, make sure you did set range correctly

... working 1-2 mins ...

then 

[tcp @ 0x7fe9ee808900] Connection to tcp://de09.livestreaming.io.mi.com:443 failed: Connection refused
[hls @ 0x7fe9ed816c00] Failed to reload playlist 0

vitaliy-sk avatar Aug 17 '21 13:08 vitaliy-sk

AttributeError: 'bool' object has no attribute 'get'

AttributeError fixed in commit: https://github.com/al-one/hass-xiaomi-miot/commit/7c55e5c56bcfbdbf37dcf3a5c4e633f95a880584, Please upgrade to master branch.

al-one avatar Aug 17 '21 13:08 al-one

@al-one thanks, updated from master, error is fixed, but stream still not work (same 403 from ffmpeg)

vitaliy-sk avatar Aug 17 '21 13:08 vitaliy-sk

Please excuse my ignorance, but how do I define the service? I cannot find "camera-stream-for-google-home" in Developer Tools > Services > Service dropdown list.

camera-stream-for-google-home is not a service of HA, it is a service defined in the miot-spec of device.

al-one avatar Aug 17 '21 14:08 al-one

Camera device model: chuangmi.camera.ipc019

camera-stream-for-google-home is present https://home.miot-spec.com/spec?type=urn%3Amiot-spec-v2%3Adevice%3Acamera%3A0000A01C%3Achuangmi-ipc019%3A1 Masked stream_address: https://de25.livestreaming.io.mi.com/hlstranscoder/************_H265transH264/playlist.m3u8

stream_http_status and stream_http_reason attributes in entity state: not present

ffmpeg test results:

ffmpeg -v warning -y -protocol_whitelist file,http,https,rtp,udp,tcp,tls,crypto -i https://de25.livestreaming.io.mi.com/hlstranscoder/_H265transH264/playlist.m3u8 -an -c:v mjpeg -f mpjpeg xiaomi_camera_video [https @ 000002807bc4dd40] HTTP error 403 Forbidden https://de25.livestreaming.io.mi.com/hlstranscoder/_H265transH264/playlist.m3u8: Server returned 403 Forbidden (access denied)

full entity:

access_token: ***** brand: chuangmi model: chuangmi.camera.ipc019 lan_ip: ***** mac_address: ***** firmware_version: 4.0.9_0426 hardware_version: Linux entity_class: MiotCameraEntity miot_type: urn:miot-spec-v2:device:camera:0000A01C:chuangmi-ipc019:1 miot_action_result: did: '369190958' miid: 0 siid: 4 aiid: 1 code: 0 out: - >- https://de.livestreaming.io.mi.com/hlstranscoder/*_H265transH264/playlist.m3u8 exe_time: 0 net_cost: 0 ot_cost: 0 otlocalts: 0 oa_cost: 0 _oa_rpc_cost: 0 stream_address: '' expire_at: '2021-08-18 00:11:34.440764' camera_control.on: true camera_control.image_rollover: 0 camera_control.night_shot: 0 camera_control.time_watermark: true camera_control.wdr_mode: true glimmer_full_color-2-6: true camera_control.recording_mode: 3 camera_control.motion_tracking: false stream_status-3-1: 1 state_updater: cloud sub_entities: camera_control.on friendly_name: Living Room Camera Camera Control entity_picture: >- /api/camera_proxy/camera.living_room_camera_camera_control?token= supported_features: 3 video_attribute: 1 keep_streaming: 'true' check_lan: 'true'`

I usually get this in the logs:

2021-08-17` 23:57:57 ERROR (MainThread) [homeassistant.components.camera] Error requesting stream: camera.living_room_camera_camera_control does not support play stream service

thermosiphonas avatar Aug 17 '21 21:08 thermosiphonas

  1. Obtain the stream address via HA service:
service: xiaomi_miot.call_action
data:
  entity_id: camera.mi_jia_xiao_zhi_camera_control
  siid: ? # Get from https://home.miot-spec.com/spec?model=brand.camera.your
  aiid: 1
  params:
    - 0
  throw: true
  1. Find the stream address from the notification in the left sidebar.
  2. Test the stream address through ffmpeg:
ffmpeg -v warning -y -protocol_whitelist file,http,https,rtp,udp,tcp,tls,crypto -i 'https://cn.livestreaming.io.mi.com/hlstranscoder/XXXXXX_H265transH264/playlist.m3u8' -an -c:v mjpeg -f mpjpeg xiaomi_camera_video

al-one avatar Aug 18 '21 02:08 al-one

@deneraraujo Thanks! But unfortunately,403 said that you did not have the right to access. There is another way, get service_token value from file .storage/xiaomi_miot/auth-xxxxxx-xx.json, splice it behind a newly obtained stream address, and test it with ffmpeg:

ffmpeg -v warning -y -protocol_whitelist file,http,https,rtp,udp,tcp,tls,crypto -i 'https://cn.livestreaming.io.mi.com/hlstranscoder/XXXXXX_H265transH264/playlist.m3u8?yetAnotherServiceToken=YourServiceTokenHere' -an -c:v mjpeg -f mpjpeg xiaomi_camera_video

al-one avatar Aug 18 '21 03:08 al-one

@al-one I update my comment about chuangmi.camera.021a04

UPD Looks like the stream are working few minutes (via URL), but not in HA

I was able to open the stream with VLC and it's working fine

https://de09.livestreaming.io.mi.com/hlstranscoder/xxxxxx_H265transH264/playlist.m3u8

With FFmpeg

ffmpeg -v warning -y -protocol_whitelist file,http,https,rtp,udp,tcp,tls,crypto -i 'https://de09.livestreaming.io.mi.com/hlstranscoder/xxxxx_H265transH264/playlist.m3u8' -an -c:v mjpeg -f mpjpeg xiaomi_camera_video

[swscaler @ 0x7fe980108000] deprecated pixel format used, make sure you did set range correctly

... working 1-2 mins ...

then 

[tcp @ 0x7fe9ee808900] Connection to tcp://de09.livestreaming.io.mi.com:443 failed: Connection refused
[hls @ 0x7fe9ed816c00] Failed to reload playlist 0

the result file xiaomi_camera_video has > 37 Mb

there are multiple images in it starting from the header

--ffmpeg
Content-type: image/jpeg
Content-length: 27999

UPD2 After few success attempts it starts giving 403 again, so it seems that there's some protection

> GET /hlstranscoder/xxxxxx_H265transH264/playlist.m3u8 HTTP/1.1
> Host: de15.livestreaming.io.mi.com
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 403 Forbidden
< Accept-Ranges: bytes
< Access-Control-Expose-Headers: Date, Server, Content-Type, Content-Length
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Methods: OPTIONS, GET, POST, HEAD
< Connection: Keep-Alive
< Access-Control-Allow-Headers: Content-Type, User-Agent, If-Modified-Since, Cache-Control, Range
< Content-Length: 0

vitaliy-sk avatar Aug 18 '21 12:08 vitaliy-sk

@al-one I update my comment about chuangmi.camera.021a04

UPD Looks like the stream are working few minutes (via URL), but not in HA

I was able to open the stream with VLC and it's working fine

https://de09.livestreaming.io.mi.com/hlstranscoder/xxxxxx_H265transH264/playlist.m3u8

With FFmpeg

ffmpeg -v warning -y -protocol_whitelist file,http,https,rtp,udp,tcp,tls,crypto -i 'https://de09.livestreaming.io.mi.com/hlstranscoder/xxxxx_H265transH264/playlist.m3u8' -an -c:v mjpeg -f mpjpeg xiaomi_camera_video

[swscaler @ 0x7fe980108000] deprecated pixel format used, make sure you did set range correctly

... working 1-2 mins ...

then 

[tcp @ 0x7fe9ee808900] Connection to tcp://de09.livestreaming.io.mi.com:443 failed: Connection refused
[hls @ 0x7fe9ed816c00] Failed to reload playlist 0

the result file xiaomi_camera_video has > 37 Mb

there are multiple images in it starting from the header

--ffmpeg
Content-type: image/jpeg
Content-length: 27999

UPD2 After few success attempts it starts giving 403 again, so it seems that there's some protection

> GET /hlstranscoder/xxxxxx_H265transH264/playlist.m3u8 HTTP/1.1
> Host: de15.livestreaming.io.mi.com
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 403 Forbidden
< Accept-Ranges: bytes
< Access-Control-Expose-Headers: Date, Server, Content-Type, Content-Length
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Methods: OPTIONS, GET, POST, HEAD
< Connection: Keep-Alive
< Access-Control-Allow-Headers: Content-Type, User-Agent, If-Modified-Since, Cache-Control, Range
< Content-Length: 0

Agree with this comment. I can't see the camera stream but I have set up a notification on motion with picture and that is working (returning a notification with a picture), which hints to the fact that the stream works for a few seconds/minutes not long enough for HA to capture the stream but enough to capture a snapshot.

Has mentioned on other comments version 0.3.8 is working fine, unfortunately it stopped working on subsequent versions.

Zeunas avatar Aug 18 '21 12:08 Zeunas

@al-one I think I found the root cause, def miot_action(self, siid, aiid, params=None, did=None, **kwargs) is returning boolean instead of the response object.

Reverted custom_components/xiaomi_miot/init.py to state before this commit https://github.com/al-one/hass-xiaomi-miot/commit/da0f954a2d7566f75ecc7b38f5ceec777a6db903 make my camera works and now I see a stream in HA

vitaliy-sk avatar Aug 19 '21 09:08 vitaliy-sk

I think I found the root cause, def miot_action(self, siid, aiid, params=None, did=None, **kwargs) is returning boolean instead of the response object.

@vitaliy-sk Thank you very much ! This is the reason why the Xiaomi api request is successful but the camera entity cannot obtain the stream address. I fixed it in the latest commit: https://github.com/al-one/hass-xiaomi-miot/commit/1f96a67ddcba3e592069ef25d1a3fc010059c599

al-one avatar Aug 19 '21 10:08 al-one

🎉 Support motion video for camera and cateye !

Upgrade to v0.4.x.

# customize.yaml
camera.your_entity_id:
  use_motion_stream: true # 在主实体开启回放,猫眼默认已开启
  sub_motion_stream: true # 为回放视频单独生成一个camera实体
  motion_stream_slice: -1 # 视频切片文件索引,-1表示最后一个切片文件,0表示第一个

How to enable ? (Please use Google Translate)

al-one avatar Aug 21 '21 08:08 al-one

🎉 Support motion video for camera and cateye !

Upgrade to v0.4.0b0.

# customize.yaml
camera.your_entity_id:
  use_motion_stream: true # 在主实体开启回放,猫眼默认已开启
  sub_motion_stream: true # 为回放视频单独生成一个camera实体
  motion_stream_slice: -1 # 视频切片文件索引,-1表示最后一个切片文件,0表示第一个

How to enable ? (Please use Google Translate)

After the update, I got this on log:

Logger: homeassistant.helpers.entity
Source: custom_components/xiaomi_miot/core/miot_spec.py:515
First occurred: 4:54:19 PM (2 occurrences)
Last logged: 4:55:19 PM
Update for camera.isa_hlc6_f32c_camera_control fails

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 278, in async_update_ha_state
    await self.async_device_update()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 474, in async_device_update
    raise exc
  File "/home/homeassistant/.homeassistant/custom_components/xiaomi_miot/camera.py", line 241, in async_update
    self._subs[pnm] = MiotSwitchSubEntity(self, self._prop_power)
  File "/home/homeassistant/.homeassistant/custom_components/xiaomi_miot/switch.py", line 148, in __init__
    super().__init__(parent, miot_property, option)
  File "/home/homeassistant/.homeassistant/custom_components/xiaomi_miot/__init__.py", line 1741, in __init__
    self._option['device_class'] = miot_property.device_class
  File "/home/homeassistant/.homeassistant/custom_components/xiaomi_miot/core/miot_spec.py", line 515, in device_class
    'co2': DEVICE_CLASS_CO2,
NameError: name 'DEVICE_CLASS_CO2' is not defined

Edit: In this version, when I try to call the service xiaomi_miot.call_action, I have a "BrokenPipeError". (Previous version I could call this service).

Logger: custom_components.xiaomi_miot.camera
Source: custom_components/xiaomi_miot/camera.py:162
Integration: Xiaomi Miot Auto (documentation, issues)
First occurred: 6:36:12 PM (1 occurrences)
Last logged: 6:36:12 PM
Câmera de Segurança Residencial 1080p Mi (Suporte Magnético) Camera Control: Got BrokenPipeError when close stream: -i "https://cn01.livestreaming.io.mi.com/hlstranscoder/GCBkNWZmMGQ4N2MwMTU0YWZlODU2NDE2MmNmNTA2OWY2NxgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8"

deneraraujo avatar Aug 21 '21 19:08 deneraraujo

@deneraraujo

NameError: name 'DEVICE_CLASS_CO2' is not defined

Upgrade HA to v2021.4.0+.

Câmera de Segurança Residencial 1080p Mi (Suporte Magnético) Camera Control: Got BrokenPipeError when close stream: -i "https://cn01.livestreaming.io.mi.com/hlstranscoder/GCBkNWZmMGQ4N2MwMTU0YWZlODU2NDE2MmNmNTA2OWY2NxgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8"

Test the stream address via ffmpeg.

al-one avatar Aug 22 '21 00:08 al-one

I'm using the version v0.4.0b0. The DEVICE_CLASS_CO2 error is in the latest release.

Upgrade Home Assistant Core !

al-one avatar Aug 22 '21 01:08 al-one

I'm using the version v0.4.0b0. The DEVICE_CLASS_CO2 error is in the latest release.

Upgrade Home Assistant Core !

@al-one Sorry, my mistake. I'm currently using Home Assistant 2021.1.5.

deneraraujo avatar Aug 22 '21 01:08 deneraraujo

Are there other changes in the API that could have affected this integration? this new version v0.4.0b0 is a bit buggy for me, so I reverted to the version 0.3.8 that has always been working for me but even after a fresh install the stream is no longer working as before, for the 1st few minutes it works fine with a live video but once it detects a motion it plays that motion detection indefinitely.

Zeunas avatar Aug 23 '21 12:08 Zeunas

@Zeunas This new version of v0.4.0b0 should not affect the previous live stream without adding the custom attribute use_motion_stream: true. If it does not work, please test the stream address through ffmpeg. The features added in the new version is to get the last video playback in the cloud (motion detected by the camera). You can add a custom attribute sub_motion_stream: true, which will create a new entity for video playback.

al-one avatar Aug 23 '21 12:08 al-one

So technically if I don't add the use_motion_stream under camera customisation I should get the live stream from the camera? As I'm afraid that's not working for me, basically what happens is once home assistant restarts it captures the 1st stream address and it plays it live, once it expires, it just plays the last minute in a loop.

This is what is on my log:

Logger: homeassistant.components.stream.worker
Source: components/stream/worker.py:323
Integration: Stream (documentation, issues)
First occurred: 9:08:18 pm (6 occurrences)
Last logged: 9:11:40 pm

Error opening stream https://de22.livestreaming.io.mi.com/hlstranscoder/GCBmNTRkMmYwNzUwOGU0NWRhYjdkNTU3N2NmZGRjYzIwOBgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8

And this is on the debugging log

2021-08-23 21:12:35 DEBUG (SyncWorker_0) [custom_components.xiaomi_miot.camera] Office cam Camera Control: camera stream: None expired: 1629749555.0582354
2021-08-23 21:12:35 DEBUG (SyncWorker_0) [custom_components.xiaomi_miot.core.xiaomi_cloud] Request miot api: miotspec/action {'params': {'did': '76304307', 'siid': 4, 'aiid': 2, 'in': []}} result: {"code":0,"message":"","result":{"did":"76304307","miid":0,"siid":4,"aiid":2,"code":0,"exe_time":0,"net_cost":0,"ot_cost":0,"otlocalts":0,"oa_cost":0,"_oa_rpc_cost":0}}
2021-08-23 21:12:35 DEBUG (SyncWorker_0) [custom_components.xiaomi_miot] Call miot action to Office cam Camera Control ({'did': '76304307', 'siid': 4, 'aiid': 2, 'in': []}), result: {'did': '76304307', 'miid': 0, 'siid': 4, 'aiid': 2, 'code': 0, 'exe_time': 0, 'net_cost': 0, 'ot_cost': 0, 'otlocalts': 0, 'oa_cost': 0, '_oa_rpc_cost': 0}
2021-08-23 21:12:35 DEBUG (SyncWorker_0) [custom_components.xiaomi_miot.core.xiaomi_cloud] Request miot api: miotspec/action {'params': {'did': '76304307', 'siid': 4, 'aiid': 1, 'in': [1]}} result: {"code":0,"message":"","result":{"did":"76304307","miid":0,"siid":4,"aiid":1,"code":0,"out":["https://de23.livestreaming.io.mi.com/hlstranscoder/GCA1MTczZjZjZTQ1NGI0YWM5OGRjY2UwNmM3ZGZkNmViNhgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8"],"exe_time":0,"net_cost":0,"ot_cost":0,"otlocalts":0,"oa_cost":0,"_oa_rpc_cost":0}}
2021-08-23 21:12:35 DEBUG (SyncWorker_0) [custom_components.xiaomi_miot] Call miot action to Office cam Camera Control ({'did': '76304307', 'siid': 4, 'aiid': 1, 'in': [1]}), result: {'did': '76304307', 'miid': 0, 'siid': 4, 'aiid': 1, 'code': 0, 'out': ['https://de23.livestreaming.io.mi.com/hlstranscoder/GCA1MTczZjZjZTQ1NGI0YWM5OGRjY2UwNmM3ZGZkNmViNhgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8'], 'exe_time': 0, 'net_cost': 0, 'ot_cost': 0, 'otlocalts': 0, 'oa_cost': 0, '_oa_rpc_cost': 0}
2021-08-23 21:12:35 DEBUG (SyncWorker_0) [custom_components.xiaomi_miot.camera] Office cam Camera Control: Get miot camera stream from cloud: {'did': '76304307', 'miid': 0, 'siid': 4, 'aiid': 1, 'code': 0, 'out': ['https://de23.livestreaming.io.mi.com/hlstranscoder/GCA1MTczZjZjZTQ1NGI0YWM5OGRjY2UwNmM3ZGZkNmViNhgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8'], 'exe_time': 0, 'net_cost': 0, 'ot_cost': 0, 'otlocalts': 0, 'oa_cost': 0, '_oa_rpc_cost': 0}

2021-08-23 21:12:50 ERROR (stream_worker) [homeassistant.components.stream.worker] Error opening stream https://de22.livestreaming.io.mi.com/hlstranscoder/GCBmNTRkMmYwNzUwOGU0NWRhYjdkNTU3N2NmZGRjYzIwOBgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8`

Divorce state is "streaming" and attribute state is
`access_token: 
brand: chuangmi
model: chuangmi.camera.ipc009
lan_ip: 192.168.1.205
mac_address: 78:11:DC:9E:0F:ED
firmware_version: 4.0.9_0409
hardware_version: ''
entity_class: MiotCameraEntity
miot_type: urn:miot-spec-v2:device:camera:0000A01C:chuangmi-ipc009:1
miot_action_result:
  did: '76304307'
  miid: 0
  siid: 4
  aiid: 1
  code: 0
  out:
    - >-
      https://de16.livestreaming.io.mi.com/hlstranscoder/GCA3ZTFhYTY4YTljODg0NTNlOTVjYTNhMGUyNzBiMmJhOBgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8
  exe_time: 0
  net_cost: 0
  ot_cost: 0
  otlocalts: 0
  oa_cost: 0
  _oa_rpc_cost: 0
stream_url-4-5: >-
   https://de16.livestreaming.io.mi.com/hlstranscoder/GCA3ZTFhYTY4YTljODg0NTNlOTVjYTNhMGUyNzBiMmJhOBgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8
expire_at: '2021-08-23 21:21:35.063014'
miot_error: null
camera_control.on: true
camera_control.image_rollover: 0
camera_control.night_shot: 0
camera_control.time_watermark: true
camera_control.wdr_mode: true
glimmer_full_color-2-6: true
camera_control.recording_mode: 3
camera_control.motion_tracking: false
stream_status-3-1: 1
state_updater: cloud
sub_entities:
  - camera_control.on
friendly_name: Office cam
entity_picture: >-
  /api/camera_proxy/camera.office_cam_stream?token=45372d5f6c108e767264fde89bc5538532e6c1a0afc546db6eea8748029e4bf2
supported_features: 3
keep_streaming: true
video_attribute: 1
miot_cloud: true

As you can see there's no stream address and no snapshot link, which on version 0.3.8 I've been able to capture. Since this new release even if I downgraid to 0.3.8 the stream address works for a couple of minutes and I'm able to capture it on VLC but not using FFMPEG, I can also see the snapshot link. It's quite bizarre as downgrading to a version that has always been working for me should do the trick but it doesn't. That's why I was asking if was there any changes in the API, as it seems that also is giving me a error that HA can't open the stream link.

configuration.yaml is as follows:

ffmpeg:
stream:

customisation.yaml is as follows:

camera.office_cam_stream:
    video_attribute: 1
    keep_streaming: true
    check_lan: true
    miot_clpue: true

Device info:

chuangmi.camera.ipc009
by chuangmi
Firmware: 4.0.9_0409

Really love this integration specially because I can use a camera I've never been able to integrate with HA, this new version of the integration also sounds brilliant but now it's a bit frustrating I can't seem to make it work...

Zeunas avatar Aug 23 '21 20:08 Zeunas

Just to add to the below, is it possible that the HA systems stores temporary files somewhere that could somehow affect the downgrade from any version to the 0.3.8 version? Seems bizarre that a version that was perfectly working for me is not working anymore and every time I do a fresh install it just doesn't give me the same result as before. Not knowledgeable enough to even be close to understand this, so if you need anything else from me to solve this issue by all means just let me know.

Zeunas avatar Aug 24 '21 13:08 Zeunas

@al-one couldn't find the exact route cause but read somewhere that removing stream: integration could help and it did! Not sure why it was working before but not anymore, however just in case someone has a similar issue, perhaps they could try this fix.

Zeunas avatar Aug 25 '21 21:08 Zeunas

@Zeunas Thanks for your hard testing! I checked the v0.3.8 and v0.4.0 versions of the code, and there is no difference when they get the live stream. If you can get the live stream address in both versions, it means that the component works well for your camera. The main function of the camera integration of this component is to obtain the stream address and process it through HA. If it cannot be played, you can test the stream address through the method in https://github.com/al-one/hass-xiaomi-miot/issues/166#issue-972598869. The test results may have the following situations that the component cannot solve:

  • Streaming address cannot be accessed
  • Streaming address is forbidden (403)
  • ffmpeg reports errors

al-one avatar Aug 26 '21 11:08 al-one

  • camera-stream-for-google-home: I can confirm this is OK
  • stream_address attribute: not present, however there is a stream_url-4-5 attribute with an address which is where the camera is taking the stream from as I can see it on HA (if I remove stream component from configuration.yaml)
  • stream_http_status and stream_http_reason attributes: not present, I have a expire_at instead
  • The stream address can be transcoded normally by ffmpeg, test via shell command: No, it returns HTTP error 403 Forbidden and Server returned 403 Forbidden (access denied). I can't open the stream with VLC either

I've done so many fresh installs, downgrades to v0.3.8 and upgrades to v0.4.0 that I am a bit lost but at some point I could see the below attributes:

  • camera-stream-for-google-home or camera-stream-for-alexa (can't remember)
  • stream_address
  • stream_http_status
  • stream_http_reason

I can see the live stream and also the second camera with the motion image perfectly, only if I remove stream component from configuration.yaml. See example of partial device state below:

state_updater: cloud
motion_video_time: '2021-08-27 21:45:48'
sub_entities:
  - camera_control.on
  - motion_event
miot_action_result:
  did: '76304307'
  miid: 0
  siid: 4
  aiid: 1
  code: 0
  out:
    - >-
      https://de10.livestreaming.io.mi.com/hlstranscoder/xxxxxxxxxx_H265transH264/playlist.m3u8
  exe_time: 0
  net_cost: 0
  ot_cost: 0
  otlocalts: 0
  oa_cost: 0
  _oa_rpc_cost: 0
miot_error: null
stream_url-4-5: >-
  https://de10.livestreaming.io.mi.com/hlstranscoder/xxxxxxxxxx_H265transH264/playlist.m3u8
expire_at: '2021-08-27 21:50:24.975069'
motion_video_latest:
  startDuration: 0
  cut: false
  offset: 0
  isCloud: false
  isRead: false
  videoStoreId: >-
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  eventType: ObjectMotion
  expireTime: 1630701952466
  isAlarm: true
  imgStoreId: >-
    xxxxxxxxxxxxxx
  fileId: '62670526200417792'
  extraInfo: ''
friendly_name: Office cam
entity_picture: >-
  /api/camera_proxy/camera.office_cam?token=xxxxxxxxxxxxxxxxxxxxxxxxxx
supported_features: 3
motion_stream_slice: -1
sub_motion_stream: true
use_motion_stream: false
keep_streaming: true
video_attribute: 1
check_lan: true
miot_cloud: true

With the stream component active all of the below still applies but the main camera stream doesn't work (status is streaming but I can't see it) and this is the log:

Logger: libav.tcp
Source: components/stream/worker.py:223
First occurred: 9:50:25 pm (4 occurrences)
Last logged: 9:50:28 pm

Connection to tcp://de10.livestreaming.io.mi.com:443 failed: Connection refuse
Logger: homeassistant.components.stream.worker
Source: components/stream/worker.py:323
Integration: stream (documentation, issues)
First occurred: 9:50:37 pm (5 occurrences)
Last logged: 9:52:58 pm

Error opening stream https://de10.livestreaming.io.mi.com/hlstranscoder/xxxxxxxx_H265transH264/playlist.m3u8
Logger: homeassistant.components.stream.worker
Source: components/stream/worker.py:396
Integration: stream (documentation, issues)
First occurred: 9:50:25 pm (2 occurrences)
Last logged: 9:50:28 pm

Error demuxing stream:

2021-08-27 21:52:58 ERROR (stream_worker) [homeassistant.components.stream.worker] Error opening stream https://de10.livestreaming.io.mi.com/hlstranscoder/xxxxxxxxxxx_H265transH264/playlist.m3u8

Not sure if this helps in any way since it has worked for me before but just thought I could leave it here for the record, just in case someone bumps into the same issue. As my workaround for the time being is to disable stream component for this to work. Not sure if the latest version of HA corrupted the stream component or if it just sopped working properly.

In any case, thanks a lot @al-one keep up with your great work ;)

Zeunas avatar Aug 27 '21 21:08 Zeunas

I have a camera issue, the cam does not show video, it is broken somewhere in a upgrade last month. HA: core-2021.8.8 Miot-Auto version: v0.3.13 (also tested it wth the beta 0.4x) Camera model: isa.camera.hlc6 It is supporting the service camera-stream-for-google-home the ffmpeg is also returning a 404 error.

access_token: yyy
brand: isa
model: isa.camera.hlc6
lan_ip: 192.168.178.98
mac_address: E4:AA:EC:2A:7A:BE
firmware_version: 4.0.5_0105
hardware_version: ''
entity_class: MiotCameraEntity
miot_type: urn:miot-spec-v2:device:camera:0000A01C:isa-hlc6:1
camera_control.on: true
camera_control.image_rollover: 0
camera_control.night_shot: 0
camera_control.time_watermark: true
camera_control.recording_mode: 2
stream_status-4-1: 1
state_updater: cloud
sub_entities:
  - camera_control.on
miot_action_result:
  did: '373670075'
  miid: 0
  siid: 5
  aiid: 1
  code: 0
  out:
    - >-
      https://de01.livestreaming.io.mi.com/hlstranscoder/xxx_H265transH264/playlist.m3u8
  exe_time: 0
  net_cost: 0
  ot_cost: 0
  otlocalts: 0
  oa_cost: 0
  _oa_rpc_cost: 0
miot_error: null
stream_http_status: 404
stream_http_reason: Not Found
stream_url-5-5: >-
 https://de01.livestreaming.io.mi.com/hlstranscoder/xxx_H265transH264/playlist.m3u8
expire_at: '2021-08-29 21:22:43.851828' (these states are shown before the expire time)
friendly_name: bol Camera Control
entity_picture: >-
  /api/camera_proxy/camera.isa_hlc6_7abe_camera_control_3?token=yyy
supported_features: 3

rojong avatar Aug 29 '21 19:08 rojong

Have you added any of these to your camera customization?

motion_stream_slice: -1
sub_motion_stream: true
use_motion_stream: false
keep_streaming: true
video_attribute: 1
check_lan: true
miot_cloud: true

Zeunas avatar Aug 29 '21 20:08 Zeunas

motion_stream_slice: -1 sub_motion_stream: true use_motion_stream: false

HI, thanks for the fast reply, I added the customizations you mentioned, and added the integration again and restarted HA. Now some other errors are appearing:

2021-08-29 22:35:19 WARNING (MainThread) [custom_components.xiaomi_miot.camera] Get miot camera stream error from cloud for bol Camera Control: True 2021-08-29 22:35:19 ERROR (MainThread) [homeassistant.components.camera] Error requesting stream: camera.isa_hlc6_7abe_camera_control_3 does not support play stream service 2021-08-29 22:35:20 WARNING (MainThread) [custom_components.xiaomi_miot.camera] Get miot camera stream error from cloud for bol Camera Control: True 2021-08-29 22:36:12 WARNING (MainThread) [homeassistant.helpers.entity] Update of camera.isa_hlc6_7abe_camera_control_3 is taking over 10 seconds

rojong avatar Aug 29 '21 20:08 rojong

And do you see any stream now? Do you see a new camera? If you do and can only see an image (no stream) then the camera does not support motion video, only snapshot (mine also only supports snapshot).

You main camera however should have a stream but I believe it's quite important you also add the below to your camera customization, it only works with these at least for me:

keep_streaming: true video_attribute: 1 check_lan: true miot_cloud: true

If you read my comments above I've been having issues with the stream component, so maybe you can try to remove that from your configuration.yaml as well, just to test if it could be that.

Apart from that, not sure if I can be much of help...

Zeunas avatar Aug 29 '21 20:08 Zeunas

Thanks again! - a added all the 7 customization you mentioned, I do not see an image, also i dot not see a streaming-video. I do not have a stream component in my configuration.yaml. I will wait until it runs again. ;-) Maybe i can revert to the old miot-auto version where it worked (but this version is not selectable in HACS any more)

rojong avatar Aug 29 '21 21:08 rojong

Thanks again! - a added all the 7 customization you mentioned, I do not see an image, also i dot not see a streaming-video. I do not have a stream component in my configuration.yaml. I will wait until it runs again. ;-) Maybe i can revert to the old miot-auto version where it worked (but this version is not selectable in HACS any more)

Was there a version that worked for you? I have a isa.camera.hlc6 too, and I never got it to work.

deneraraujo avatar Aug 29 '21 21:08 deneraraujo

yes, the isa.camera.hlc6 worked nicely, streaming. Until some releases ago...

rojong avatar Aug 29 '21 21:08 rojong

yes, the isa.camera.hlc6 worked nicely, streaming. Until some releases ago...

Do you remember the version number?

deneraraujo avatar Aug 29 '21 21:08 deneraraujo

Thanks again! - a added all the 7 customization you mentioned, I do not see an image, also i dot not see a streaming-video. I do not have a stream component in my configuration.yaml. I will wait until it runs again. ;-) Maybe i can revert to the old miot-auto version where it worked (but this version is not selectable in HACS any more)

Bah...sorry couldn't be much of help...

yes, the isa.camera.hlc6 worked nicely, streaming. Until some releases ago...

Do you remember the version number?

For me the best last working version was v0.3.8 be even if I install that one (by downloading the files and installing manually) is not working properly anymore... All the other versions after that until 0.4.0 are not working for cameras.

Zeunas avatar Aug 29 '21 22:08 Zeunas

Same problem with isa.camera.hlc6

I receive a notification that someone is watching in Mi Home but stream does not work in HA.

stream_http_status: 404 stream_http_reason: Not Found

ffmpeg returns 404 as well.

chaplyk avatar Aug 31 '21 12:08 chaplyk

@Tao173 对于流地址状态码404的问题,很抱歉我也无能为力。你可以升级到v0.4.x版本,该版本支持获取摄像头的最后一个录像的封面图片,部分型号可以观看最后一个录像。

al-one avatar Aug 31 '21 13:08 al-one

@Tao173 对于流地址状态码404的问题,很抱歉我也无能为力。你可以升级到v0.4.x版本,该版本支持获取摄像头的最后一个录像的封面图片,部分型号可以观看最后一个录像。

好的,我现在试试,感谢回复!

Tao173 avatar Sep 01 '21 06:09 Tao173

⚠️⚠️⚠️ yetAnotherServiceToken must be masked !!! ⚠️⚠️⚠️

⚠️⚠️⚠️流地址中的yetAnotherServiceToken必须打码 !!! ⚠️⚠️⚠️

al-one avatar Sep 06 '21 09:09 al-one

@ocerot Please modify your Xiaomi account password. 请修改你的小米账号密码!

al-one avatar Sep 06 '21 09:09 al-one

好吧,谢谢了,第一次用github回复,实在没搞明白

At 2021-09-06 17:50:10, "Alone" @.***> wrote:

@ocerot Please modify your Xiaomi account password. 请修改你的小米账号密码!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

ocerot avatar Sep 06 '21 11:09 ocerot

@al-one following up on our previous discussion (above) in regards the stream component. I've enabled it again and one thing I notice is that it the stream component is able to handle the 1st stream address supplied by the camera perfectly, it's only when the stream address expires and is replaced with a new address I have the below error.

Logger: homeassistant.components.stream.worker
Source: components/stream/worker.py:323
Integration: Stream (documentation, issues)
First occurred: 9:08:18 pm (6 occurrences)
Last logged: 9:11:40 pm

Error opening stream https://de22.livestreaming.io.mi.com/hlstranscoder/GCBmNTRkMmYwNzUwOGU0NWRhYjdkNTU3N2NmZGRjYzIwOBgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8

Do you have any ideas of what might be happening? Or any other tests I can do to find what may be happening?

Thanks!

Zeunas avatar Sep 09 '21 18:09 Zeunas

@Zeunas Error opening stream still seems that HA cannot access the stream address. Please confirm the http status of the stream address when the error occurred.

al-one avatar Sep 11 '21 08:09 al-one

Camera stream address is OK, see below:

access_token: xxx
brand: chuangmi
model: chuangmi.camera.ipc009
lan_ip: 192.168.1.205
mac_address: 78:11:DC:9E:0F:ED
firmware_version: 4.0.9_0409
hardware_version: ''
entity_class: MiotCameraEntity
miot_type: urn:miot-spec-v2:device:camera:0000A01C:chuangmi-ipc009:1
miot_action_result:
  did: '76304307'
  miid: 0
  siid: 4
  aiid: 1
  code: 0
  out:
    - >-
      https://de06.livestreaming.io.mi.com/hlstranscoder/xxx_H265transH264/playlist.m3u8
stream_address: >-
  https://de06.livestreaming.io.mi.com/hlstranscoder/xxx_H265transH264/playlist.m3u8
expire_at: '2021-09-11 14:31:08.405560'
miot_error: null
camera_control.on: true
camera_control.image_rollover: 0
camera_control.night_shot: 0
camera_control.time_watermark: true
camera_control.wdr_mode: true
glimmer_full_color-2-6: true
camera_control.recording_mode: 3
camera_control.motion_tracking: false
stream_status-3-1: 1
state_updater: cloud
motion_video_time: '2021-09-11 07:28:42'
motion_video_type: ObjectMotion
sub_entities:
  - camera_control.on
  - motion_event
motion_video_latest:
  startDuration: 0
  cut: false
  offset: 0
  isCloud: false
  isRead: false
  videoStoreId: >-
    Xxx
  eventType: ObjectMotion
  expireTime: 1631946526469
  isAlarm: true
  imgStoreId: >-
    Xxx
  fileId: '63323041415304960'
  extraInfo: ''
friendly_name: Office cam
entity_picture: >-
  /api/camera_proxy/camera.office_cam?token=xxx
supported_features: 3
motion_stream_slice: -1
sub_motion_stream: true
keep_streaming: true
video_attribute: 1

However I get these errors from the log:

Logger: libav.tcp
Source: components/stream/worker.py:223
First occurred: 3:26:40 pm (2 occurrences)
Last logged: 3:26:40 pm

Connection to tcp://de24.livestreaming.io.mi.com:443 failed: Connection refused
Logger: homeassistant.components.stream.worker
Source: components/stream/worker.py:396
Integration: Stream (documentation, issues)
First occurred: 3:26:40 pm (1 occurrences)
Last logged: 3:26:40 pm

Error demuxing stream:
Logger: homeassistant.components.stream.worker
Source: components/stream/worker.py:323
Integration: Stream (documentation, issues)
First occurred: 3:26:52 pm (7 occurrences)
Last logged: 3:31:24 pm

Error opening stream https://de24.livestreaming.io.mi.com/hlstranscoder/xxx_H265transH264/playlist.m3u8

Note that the above is only after the stream address refreshes. As mentioned when I restart HA the 1st stream address works fine, only the subsequent ones have the above errors even thou camera attributes are ok.

Zeunas avatar Sep 11 '21 13:09 Zeunas

@al-one I update my comment about chuangmi.camera.021a04 UPD Looks like the stream are working few minutes (via URL), but not in HA I was able to open the stream with VLC and it's working fine https://de09.livestreaming.io.mi.com/hlstranscoder/xxxxxx_H265transH264/playlist.m3u8 With FFmpeg

ffmpeg -v warning -y -protocol_whitelist file,http,https,rtp,udp,tcp,tls,crypto -i 'https://de09.livestreaming.io.mi.com/hlstranscoder/xxxxx_H265transH264/playlist.m3u8' -an -c:v mjpeg -f mpjpeg xiaomi_camera_video

[swscaler @ 0x7fe980108000] deprecated pixel format used, make sure you did set range correctly

... working 1-2 mins ...

then 

[tcp @ 0x7fe9ee808900] Connection to tcp://de09.livestreaming.io.mi.com:443 failed: Connection refused
[hls @ 0x7fe9ed816c00] Failed to reload playlist 0

the result file xiaomi_camera_video has > 37 Mb there are multiple images in it starting from the header

--ffmpeg
Content-type: image/jpeg
Content-length: 27999

UPD2 After few success attempts it starts giving 403 again, so it seems that there's some protection

> GET /hlstranscoder/xxxxxx_H265transH264/playlist.m3u8 HTTP/1.1
> Host: de15.livestreaming.io.mi.com
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 403 Forbidden
< Accept-Ranges: bytes
< Access-Control-Expose-Headers: Date, Server, Content-Type, Content-Length
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Methods: OPTIONS, GET, POST, HEAD
< Connection: Keep-Alive
< Access-Control-Allow-Headers: Content-Type, User-Agent, If-Modified-Since, Cache-Control, Range
< Content-Length: 0

Agree with this comment. I can't see the camera stream but I have set up a notification on motion with picture and that is working (returning a notification with a picture), which hints to the fact that the stream works for a few seconds/minutes not long enough for HA to capture the stream but enough to capture a snapshot.

Has mentioned on other comments version 0.3.8 is working fine, unfortunately it stopped working on subsequent versions.

@Zeunas, Do you mind to share your notification with picture? I am trying to use motion object and it's attributes stream and image addresses, but it does not work for me

new-kirte avatar Sep 15 '21 18:09 new-kirte

@al-one I update my comment about chuangmi.camera.021a04 UPD Looks like the stream are working few minutes (via URL), but not in HA I was able to open the stream with VLC and it's working fine https://de09.livestreaming.io.mi.com/hlstranscoder/xxxxxx_H265transH264/playlist.m3u8 With FFmpeg

ffmpeg -v warning -y -protocol_whitelist file,http,https,rtp,udp,tcp,tls,crypto -i 'https://de09.livestreaming.io.mi.com/hlstranscoder/xxxxx_H265transH264/playlist.m3u8' -an -c:v mjpeg -f mpjpeg xiaomi_camera_video

[swscaler @ 0x7fe980108000] deprecated pixel format used, make sure you did set range correctly

... working 1-2 mins ...

then 

[tcp @ 0x7fe9ee808900] Connection to tcp://de09.livestreaming.io.mi.com:443 failed: Connection refused
[hls @ 0x7fe9ed816c00] Failed to reload playlist 0

the result file xiaomi_camera_video has > 37 Mb there are multiple images in it starting from the header

--ffmpeg
Content-type: image/jpeg
Content-length: 27999

UPD2 After few success attempts it starts giving 403 again, so it seems that there's some protection

> GET /hlstranscoder/xxxxxx_H265transH264/playlist.m3u8 HTTP/1.1
> Host: de15.livestreaming.io.mi.com
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 403 Forbidden
< Accept-Ranges: bytes
< Access-Control-Expose-Headers: Date, Server, Content-Type, Content-Length
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Methods: OPTIONS, GET, POST, HEAD
< Connection: Keep-Alive
< Access-Control-Allow-Headers: Content-Type, User-Agent, If-Modified-Since, Cache-Control, Range
< Content-Length: 0

Agree with this comment. I can't see the camera stream but I have set up a notification on motion with picture and that is working (returning a notification with a picture), which hints to the fact that the stream works for a few seconds/minutes not long enough for HA to capture the stream but enough to capture a snapshot. Has mentioned on other comments version 0.3.8 is working fine, unfortunately it stopped working on subsequent versions.

@Zeunas, Do you mind to share your notification with picture? I am trying to use motion object and it's attributes stream and image addresses, but it does not work for me

Are you referring to my comment on issue #56 ?

I need to understand what is your customization for your main camera. Have you added the option to have a sub camera with the motion detection snapshot?

For phone notification with picture I use this blueprint Notification with picture.

Zeunas avatar Sep 15 '21 18:09 Zeunas

Camera stream address is OK, see below:

access_token: xxx
brand: chuangmi
model: chuangmi.camera.ipc009
lan_ip: 192.168.1.205
mac_address: 78:11:DC:9E:0F:ED
firmware_version: 4.0.9_0409
hardware_version: ''
entity_class: MiotCameraEntity
miot_type: urn:miot-spec-v2:device:camera:0000A01C:chuangmi-ipc009:1
miot_action_result:
  did: '76304307'
  miid: 0
  siid: 4
  aiid: 1
  code: 0
  out:
    - >-
      https://de06.livestreaming.io.mi.com/hlstranscoder/xxx_H265transH264/playlist.m3u8
stream_address: >-
  https://de06.livestreaming.io.mi.com/hlstranscoder/xxx_H265transH264/playlist.m3u8
expire_at: '2021-09-11 14:31:08.405560'
miot_error: null
camera_control.on: true
camera_control.image_rollover: 0
camera_control.night_shot: 0
camera_control.time_watermark: true
camera_control.wdr_mode: true
glimmer_full_color-2-6: true
camera_control.recording_mode: 3
camera_control.motion_tracking: false
stream_status-3-1: 1
state_updater: cloud
motion_video_time: '2021-09-11 07:28:42'
motion_video_type: ObjectMotion
sub_entities:
  - camera_control.on
  - motion_event
motion_video_latest:
  startDuration: 0
  cut: false
  offset: 0
  isCloud: false
  isRead: false
  videoStoreId: >-
    Xxx
  eventType: ObjectMotion
  expireTime: 1631946526469
  isAlarm: true
  imgStoreId: >-
    Xxx
  fileId: '63323041415304960'
  extraInfo: ''
friendly_name: Office cam
entity_picture: >-
  /api/camera_proxy/camera.office_cam?token=xxx
supported_features: 3
motion_stream_slice: -1
sub_motion_stream: true
keep_streaming: true
video_attribute: 1

However I get these errors from the log:

Logger: libav.tcp
Source: components/stream/worker.py:223
First occurred: 3:26:40 pm (2 occurrences)
Last logged: 3:26:40 pm

Connection to tcp://de24.livestreaming.io.mi.com:443 failed: Connection refused
Logger: homeassistant.components.stream.worker
Source: components/stream/worker.py:396
Integration: Stream (documentation, issues)
First occurred: 3:26:40 pm (1 occurrences)
Last logged: 3:26:40 pm

Error demuxing stream:
Logger: homeassistant.components.stream.worker
Source: components/stream/worker.py:323
Integration: Stream (documentation, issues)
First occurred: 3:26:52 pm (7 occurrences)
Last logged: 3:31:24 pm

Error opening stream https://de24.livestreaming.io.mi.com/hlstranscoder/xxx_H265transH264/playlist.m3u8

Note that the above is only after the stream address refreshes. As mentioned when I restart HA the 1st stream address works fine, only the subsequent ones have the above errors even thou camera attributes are ok.

I can confirm that I am having the exact same problem and have set video_attribute: 1

thermosiphonas avatar Sep 21 '21 08:09 thermosiphonas

Camera stream address is OK,I can play in player。 bug in HomeAssistant,the Camera Entity can not play: this is logger:

`logger: aiohttp.server Source: components/stream/hls.py:50 First occurred: 17:59:23 (3 occurrences) Last logged: 17:59:25

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request resp = await self._request_handler(request) File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 499, in _handle resp = await handler(request) File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 119, in impl return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 211, in forwarded_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 24, in request_context_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 78, in ban_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 144, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 135, in handle result = await result File "/usr/src/homeassistant/homeassistant/components/stream/core.py", line 216, in get return await self.handle(request, stream, sequence) File "/usr/src/homeassistant/homeassistant/components/stream/hls.py", line 75, in handle return web.Response(body=self.render(track).encode("utf-8"), headers=headers) File "/usr/src/homeassistant/homeassistant/components/stream/hls.py", line 50, in render (len(segment.init) + sum(len(part.data) for part in segment.parts)) ZeroDivisionError: division by zero `

nesror avatar Sep 27 '21 10:09 nesror

  • What can we do if the camera update is slow? E.g. it's like getting a picture every ~5-10 seconds.
  • Also when I open the camera, the stream is just loading and loading without any image

model: isa.camera.hlc6

Maybe can we reduce the quality to make it more "realtime"?

gaborvecsei avatar Nov 29 '21 20:11 gaborvecsei

Please help:

access_token: xxxxxxxxxxxxxxxxxbe33148e151dc249c6854b219048455d4 brand: chuangmi frontend_stream_type: hls model: chuangmi.camera.029a02 lan_ip: 192.168.1.31 mac_address: xx:7E:A4:xx:A1:xx entity_class: MiotCameraEntity home_room: 4204997626 miot_type: urn:miot-spec-v2:device:camera:0000A01C:chuangmi-029a02:1 camera_control.on: true camera_control.image_rollover: 0 camera_control.night_shot: 2 camera_control.wdr_mode: true glimmer_full_color-2-6: true camera_control.recording_mode: 0 camera_control.motion_tracking: false camera_control.time_watermark: true stream_status-8-9: 1 stream_status-7-9: 1 motion_detection: false motion_detection.alarm_interval: 5 detection_sensitivity-5-3: 1 motion_detection_start_time-5-4: 00:00:00 motion_detection_end_time-5-5: 23:59:00 memory_card_management.status: 1 storage_total_space-4-2: 0 storage_free_space-4-3: 0 storage_used_space-4-4: 0 indicator_light.on: true state_updater: cloud sub_entities: camera_control.on, motion_event, motion_detection-5.motion_detection-1, indicator_light-3 miot_action_error: -704220035 Action parameter error miot_action_result: did: '451081381' miid: 0 siid: 7 aiid: 1 code: -704220035 exe_time: 0 withLatency: 0

entity_picture: /api/camera_proxy/camera.chuangmi_029a02_a139_camera_control?token=xxxxxxxxxxxxxxxxxxxx846be33148e151dc249c6854b219048455d4

I can't see video URL, cos always "Action parameter error"

After experiments:

access_token: 7e2512751d11a8eb0e65907aeca502d9562625291a0c1737934a043f4a86c153
brand: chuangmi
frontend_stream_type: hls
model: chuangmi.camera.029a02
lan_ip: 192.168.1.31
mac_address: 60:7E:A4:4D:A1:39
entity_class: MiotCameraEntity
home_room: Дом пользователя 4204997626 Гостиная
miot_type: urn:miot-spec-v2:device:camera:0000A01C:chuangmi-029a02:1
camera_control.on: true
camera_control.image_rollover: 0
camera_control.night_shot: 2
camera_control.wdr_mode: true
glimmer_full_color-2-6: true
camera_control.recording_mode: 0
camera_control.motion_tracking: false
camera_control.time_watermark: true
stream_status-8-9: 1
stream_status-7-9: 1
motion_detection: false
motion_detection.alarm_interval: 5
detection_sensitivity-5-3: 1
motion_detection_start_time-5-4: 00:00:00
motion_detection_end_time-5-5: 23:59:00
memory_card_management.status: 1
storage_total_space-4-2: 0
storage_free_space-4-3: 0
storage_used_space-4-4: 0
indicator_light.on: true
state_updater: cloud
sub_entities: camera_control.on, motion_event, motion_detection-5.motion_detection-1, indicator_light-3
miot_action_error: -704220035 Action parameter error
miot_action_result: 
did: '451081381'
miid: 0
siid: 7
aiid: 1
code: 0
out:
  - >-
    https://cn01.livestreaming.io.mi.com/hlstranscoder/xxxxxxxx1ODJkOGFhMzgzMxxxxxxxxxxKX191bnVzZWRfXwA_H265transH264/playlist.m3u8
exe_time: 0
withLatency: 0

stream_http_status: 403
stream_http_reason: Forbidden
stream_address: https://cn01.livestreaming.io.mi.com/hlstranscoder/xxxxxxxxxxxxxxxxxxOWxxxxxxxxgzMTQ0YmMxMhgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8
expire_at: 2022-02-01 21:31:06.896954
miot_error: null
entity_picture: /api/camera_proxy/camera.chuangmi_029a02_a139_camera_control?
```token=xxxxxxxxxxxxxxxa502d9562625291a0c1xxxxxxxxxxxxx43f4a86c153

But not open. Help plz

geldelo avatar Feb 01 '22 16:02 geldelo

Hello. I'm trying to connect chuangmi.camera.ipc013d. The camera does not want to give a direct stream, only if you flash the left buggy firmware.

access_token: *** brand: chuangmi model: chuangmi.camera.ipc013d lan_ip: 192.168.100.229 mac_address: *** entity_class: MiotCameraEntity home_room: *** miot_type: urn:miot-spec-v2:device:camera:0000A01C:chuangmi-ipc013d:1 camera_control.on: true camera_control.image_rollover: 0 camera_control.night_shot: 0 camera_control.time_watermark: true camera_control.wdr_mode: true glimmer_full_color-2-6: true camera_control.recording_mode: 3 camera_control.motion_tracking: false state_updater: cloud sub_entities: camera_control.on miot_action_error: -704040005 Action does not exist miot_action_result: did: '311620968' miid: 0 siid: 2 aiid: 1 code: -704040005 exe_time: 0 withLatency: 0

entity_picture: /api/camera_proxy/camera.chuangmi_ipc013d_17fc_camera_control?token=*** friendly_name: Видеокамера Camera Control supported_features: 1

Executed the script I saw above

service: xiaomi_miot.call_action data: entity_id: camera.mi_jia_xiao_zhi_camera_control siid: ? # Get from https://home.miot-spec.com/spec?model=brand.camera.your aiid: 1 params: - 0 throw: true

and got this answer

Miot action result {'did': '311620968', 'miid': 0, 'siid': 2, 'aiid': 1, 'code': -704040005, 'exe_time': 0, 'withLatency': 0}

anti-spy avatar Feb 09 '22 21:02 anti-spy

image 我應該怎麼做,在terminal裡面顯示沒有這個指令

a000a498 avatar Jun 10 '22 06:06 a000a498