al-one / hass-xiaomi-miot

Automatic integrate all Xiaomi devices to HomeAssistant via miot-spec, support Wi-Fi, BLE, ZigBee devices. 小米米家智能家居设备接入Hass集成
https://miot-spec.com
Apache License 2.0
4.45k stars 626 forks source link

Camera issues #166

Open al-one opened 3 years ago

al-one commented 3 years ago

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:

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


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

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

vitaliy-sk commented 3 years ago

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
al-one commented 3 years ago

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.

vitaliy-sk commented 3 years ago

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

al-one commented 3 years ago

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.

thermosiphonas commented 3 years ago

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

al-one commented 3 years ago
  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
  2. Find the stream address from the notification in the left sidebar.
  3. 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 commented 3 years ago

@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
vitaliy-sk commented 3 years ago

@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
Zeunas commented 3 years ago

@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.

vitaliy-sk commented 3 years ago

@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

al-one commented 3 years ago

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 commented 3 years ago

🎉 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)

deneraraujo commented 3 years ago

🎉 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"
al-one commented 3 years ago

@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 commented 3 years ago

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

Upgrade Home Assistant Core !

deneraraujo commented 3 years ago

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.

Zeunas commented 3 years ago

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.

al-one commented 3 years ago

@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.

Zeunas commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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.

al-one commented 3 years ago

@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:

Zeunas commented 3 years ago

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:

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 ;)

rojong commented 3 years ago

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
Zeunas commented 3 years ago

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
rojong commented 3 years ago

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

Zeunas commented 3 years ago

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...

rojong commented 3 years ago

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)

deneraraujo commented 3 years ago

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.

rojong commented 3 years ago

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

deneraraujo commented 3 years ago

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

Do you remember the version number?

Zeunas commented 3 years ago

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.

chaplyk commented 3 years ago

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.

al-one commented 3 years ago

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

Tao173 commented 3 years ago

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

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

al-one commented 3 years ago

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

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

al-one commented 3 years ago

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

ocerot commented 3 years ago

好吧,谢谢了,第一次用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.

Zeunas commented 3 years ago

@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!

al-one commented 3 years ago

@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.

Zeunas commented 3 years ago

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.

new-kirte commented 3 years ago

@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

Zeunas commented 3 years ago

@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.

thermosiphonas commented 3 years ago

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

nesror commented 3 years ago

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 `

gaborvecsei commented 2 years ago

model: isa.camera.hlc6

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

geldelo commented 2 years ago

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
anti-spy commented 2 years ago

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:

and got this answer

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

a000a498 commented 2 years ago

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

kuduacz commented 2 years ago

so what is the status? i have ipc019 and stram start to loop after few seconds. is there a way to fix that?