Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera issues #166

Open
4 tasks done
al-one opened this issue Aug 17, 2021 · 83 comments
Open
4 tasks done

Camera issues #166

al-one opened this issue Aug 17, 2021 · 83 comments

Comments

@al-one
Copy link
Owner

al-one commented Aug 17, 2021

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:

  • Service camera-stream-for-google-home needs to be defined in camera device miot-spec (find your camera spec here)
  • The stream address can be obtained after the device is integrated (stream_address attribute in entity state)
  • The stream address can be accessed normally within the validity period (stream_http_status and stream_http_reason attributes in entity state)
  • 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测试结果
@vitaliy-sk
Copy link

vitaliy-sk commented Aug 17, 2021

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
Copy link
Owner Author

al-one commented Aug 17, 2021

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

AttributeError fixed in commit: 7c55e5c, Please upgrade to master branch.

@vitaliy-sk
Copy link

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

@al-one
Copy link
Owner Author

al-one commented Aug 17, 2021

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
Copy link

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
Copy link
Owner Author

al-one commented Aug 18, 2021

  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
Copy link
Owner Author

al-one commented Aug 18, 2021

@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
Copy link

vitaliy-sk commented Aug 18, 2021

@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
Copy link

Zeunas commented Aug 18, 2021

@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
Copy link

@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 da0f954 make my camera works and now I see a stream in HA

@al-one
Copy link
Owner Author

al-one commented Aug 19, 2021

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: 1f96a67

@al-one
Copy link
Owner Author

al-one commented Aug 21, 2021

🎉 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
Copy link

deneraraujo commented Aug 21, 2021

🎉 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
Copy link
Owner Author

al-one commented Aug 22, 2021

@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
Copy link
Owner Author

al-one commented Aug 22, 2021

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

Upgrade Home Assistant Core !

@deneraraujo
Copy link

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
Copy link

Zeunas commented Aug 23, 2021

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
Copy link
Owner Author

al-one commented Aug 23, 2021

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

@CagoBHuK
Copy link

Camera device model (Like: brand.camera.abc): chuangmi.camera.ipc009, link: https://home.miot-spec.com/spec?type=urn:miot-spec-v2:device📷0000A01C:chuangmi-ipc009:1 Masked stream_address: https://cn02.livestreaming.io.mi.com/hlstranscoder/xxx_H265transH264/playlist.m3u8 stream_http_status and stream_http_reason attributes in entity state: 403, Forbidden ffmpeg test results: [https @ 0x7fa72f546e40] HTTP error 403 Forbidden

I can get the stream URL by calling the service: {'did': '284027945', 'miid': 0, 'siid': 4, 'aiid': 1, 'code': 0, 'out': ['https://cn02.livestreaming.io.mi.com/hlstranscoder/xxx_H265transH264/playlist.m3u8'], 'exe_time': 0, 'withLatency': 0} but the URL is not working. It looks like there's some authentification issue. The camera stream works itself through Mihome, but won't work with HA.

Every request to MiCloud goes with the cookie, as I can see in Fiddler from my mobile MiHome. Looks like there's some problem with this.

@Zeunas
Copy link

Zeunas commented Feb 14, 2023

I may have found a workaround using @qubourse suggestion. It's in a very draft form and has it's flaws, although with a failsafe option! I have worked on this based on some assumptions, not sure if they are right but it works.

Follow these steps:

  1. Create an input_text helper to handle the stream address
    image

  2. Add a new Generic camera integration with the below options (note that the template for the stream source needs to be changed based on the above input_text name)

image

  1. Create an automation to be triggered every 4 minutes (just one minute before the stream address expires)

    • to call a service to get the stream address
    • as it generates a persistent notification the automation then extracts the stream address and adds it to the input text created on step 1
    • finally it reloads the Generic camera config to handle the new stream address (this is a must as whenever there's a new stream address, the Generic camera crashes and you can only make it work by reloading it)
alias: Office - Office cam url ping
description: ""
trigger:
  - platform: time_pattern
    minutes: /4
    id: time
condition: []
action:
  - service: xiaomi_miot.call_action
    data:
      entity_id: camera.office_cam
      siid: 4
      aiid: 1
      params:
        - 2
      throw: true
  - service: input_text.set_value
    data:
      value: >-
        {{
        (states.persistent_notification.xiaomi_miot_debug.attributes.message.split("
        ").11.strip("'],")).strip("['") }}
    target:
      entity_id: input_text.office_cam_url
  - service: persistent_notification.dismiss
    data:
      notification_id: xiaomi_miot_debug
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id: camera.office_cam
mode: single
  1. Disable the camera that is created by this integration. I believe that if it's not disabled it will request a different stream address every five minutes which will create a conflict with the above automation - This is an assumption as the above automation started to work much better when I disabled the camera.

A few suggestions:

  1. If you turn on the camera only when you need it like me just create another automation to turn on/off the above automation based on the camera switch state (on/off) and add an automation trigger service to be called as soon as you turn on the camera, otherwise you will need to wait 4 minutes until the above automation is triggered.
  2. I believe that whenever the camera detects motion it also creates a separate stream address, however I haven't yet been able to make the above automation work properly after motion is detected. Therefore either you wait for it to trigger again after a certain time passes or you can create a button on your lovelace to trigger the above automation (this would work as a failsafe in case the camera stream crashes somehow)

@dragosdmc
Copy link

dragosdmc commented Feb 14, 2023

@Zeunas > Add a new Generic camera integration with the below options (note that the template for the stream source needs to be changed based on the above input_text name

This doesn't work for me; step 2 return this error when trying to add the template in the "Stream Source URL" field: "Relative URLs are not allowed"

@Zeunas
Copy link

Zeunas commented Feb 15, 2023

You need to have an active stream address on your input_text helper to make it work, have you try adding just the stream address you get from the xuaomi_miot.call_acrion service?. If that doesn't work try adding it to your configuration.yaml as per below

camera:
    - platform: generic
      stream_source: {{ states(input_text.YOUR_INPUT_TEXT) }}

Just to force HA to create the integration, it will then flag that the configuration yaml is deprecated but you will see the camera created on you integration section. Then you can remove it fr your configuration yaml.

@mackbeth11
Copy link

mackbeth11 commented Feb 16, 2023

Hi,

Could you prepare a simple instruction how to make Xiaomi camera to work with live stream? Step by step? :) As I see, I need to create dummy generic camera, pass via automation some stream URl.. but I don;t see any reference to my real camera entity,

Could you explain used parameters in service call?

  • service: xiaomi_miot.call_action
    data:
    entity_id: camera.office_cam
    siid: 4
    aiid: 1
    params:
    - 2
    throw: true
    In this example this entity ID is real camera from Miot Auto or this generic camera?

This is example state of my camera when it plays stream:

friendly_name: Kamera tył Camera Control
supported_features: 3
entity_picture: >-
  /api/camera_proxy/camera.isa_hlc6_1fbe_camera_control?token=ca8875ebffgh57d67d0947a9018e163f2e8a79e3be13fd
access_token: ca8875ebf75cbfe318972f60fgfhfghfhd67d0947a9018e163f2e8a79e3be13fd
model_name: isa.camera.hlc6
brand: isa
frontend_stream_type: hls
model: isa.camera.hlc6
lan_ip: 192.168.1.108
mac_address: E4:AA:EC:25:1F:BE
entity_class: MiotCameraEntity
home_room: Domek Podwórko
miot_type: urn:miot-spec-v2:device:camera:0000A01C:isa-hlc6:1
camera_control.on: true
camera_control.image_rollover: 180
camera_control.night_shot: 0
camera_control.time_watermark: true
camera_control.recording_mode: 2
stream_status-4-1: 1
state_updater: cloud
motion_video_time: '2023-02-16 20:53:35'
motion_video_type: ObjectMotion
miot_action_result:
  did: '373319099'
  miid: 0
  siid: 5
  aiid: 1
  code: 0
  out:
    - >-
      https://de09.livestreaming.io.mi.com/hlstranscoder/GCBlYjVhNmExZWJkNjg0ZDBmYmI5MWUyMmFkYTE2MzE5MxgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8
  exe_time: 0
  withLatency: 0
stream_address: >-
  https://de09.livestreaming.io.mi.com/hlstranscoder/GCBlYjVhNujlmExZWJkNjg0ZDBmYmI5MWUyMmFkYTE2MzE5MxgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8
expire_at: '2023-02-16 23:27:35.410399'
sub_entities:
  - camera_control-2.on-1
  - motion_event
motion_video_latest:
  startDuration: 0
  cut: false
  offset: 0
  isCloud: false
  isRead: false
  videoStoreId: >-
    CAMERA_VIDEO_GLACoEfZ9-Gh0sZ0-GPzfc_ceatOw_GTElI_KC5720Qh1c-DKKQ84Pu5mXkFShh0g-pXm6ocb5Otp4b6SsWvfzdMv-_ufBfAdytpnXo73-X2DY5d2lBJOTV7dgKOS_2XJt9fi9dhtrnhbqWrTpIZYCVcQ4ddf9rlbOM7kOUyYvfmaLmj8IqdkpkeQYfd5eH4QbYAqb0I4fum3Ow5gf6iNfaE-TzPhjtaGk5W_Laojbqzn_uzTZ93WTK3iBZfPjvVP68xSgp_dgpeKeMNzWqsHzK0nay4yhf1BSj7ZD1uCfybgKxvNcQoipHJUaQqUZuql3rs6WtMQNy8qKWyZuf0XpZkWIXq5qM4aT7Tgy4mLBZdNRIf8RW9cidcc2AR6xDScXsYnRFpNCF-5_WHRrSaljRvLxgSeQlneWbWRIWICzPWOnqvXG4BGBA7MBzxqwmF46nahLORKwBiGBT_HC2-X6O-PE5YUvpSix3dGN6HLwA
  eventType: ObjectMotion
  expireTime: 1677182026758
  isAlarm: true
  isShowImg: true
  imgStoreId: >-
    CAMERA_IMG_GLACoEfZ9-Gh0sZ0-GPzfc_ceatOw_GTElI_KC5720Qh1c-DKKQ84Pu5mXkFShh0g-pXm6ocb5Otp4b6SsWvfzdMv-_ufBfAdytpnXo73-X2DY5d2lBJOTV7dgKOS_2XJt9fi9dhtrnhbqWrTpIZYCVcQ4ddf9rlbOM7kOUyYvfmaLmj8IqdkpkeQYfd5eH4QbYAqb0I4fum3Ow5gf6iNfaE-TzPhjtaGk5W_Laojbqzn_uzTZ93WTK3iBZfPjvVP68xSgp_dgpeKeMNzWqsHzK0nay4yhf1BSj7ZD1uCfybgKxvNcQoipHJUaQqUZuql3rs6WtMQNy8qKWyZuf0XpZkWIXq5qM4aT7Tgy4mLBZdNRIf8RW9cidcc2AR6xDScXsYnRFpNCF-5_WHRrSaljRvLxgSeQlneWbWRIWICzPWOnqvXG4BGBA7MBzxqwmF46nahLORKwBiGBT_HC2-X6O-PE5YUvpSix3dGN6HLwA
  fileId: '87038571416395392'
  extraInfo: '{"timezonenum":"3600"}'

@Zeunas
Copy link

Zeunas commented Feb 16, 2023

Replace the entity on the service call for your camera and the siid to 5, which seems to be your camera siid. Let me know if it works.

@mackbeth11
Copy link

Oo, so generic camera may have any entity. Ok tommorow inwill try, as in Poland there is midnight and smart home issues take roo much time :) morning need to go work with at least couple hours of sleep :) thanks for fast reply...

@mackbeth11
Copy link

Hmm...Stream was working live around 1:52

Now when I try to execute autmation even manually to get freshed stream

Logger: homeassistant.components.automation.office_office_cam_url_ping
Source: components/homeassistant/init.py:262
Integration: Automation (documentation, issues)
First occurred: 08:54:14 (16 occurrences)
Last logged: 09:07:41

Office - Office cam url ping: Error executing script. Unexpected error for call_service at pos 4: There were no matching config entries to reload
While executing automation automation.office_office_cam_url_ping
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 684, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1787, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1824, in _execute_service
await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 757, in admin_handler
await result
File "/usr/src/homeassistant/homeassistant/components/homeassistant/init.py", line 262, in async_handle_reload_config_entry
raise ValueError("There were no matching config entries to reload")
ValueError: There were no matching config entries to reload

@mackbeth11
Copy link

mackbeth11 commented Feb 17, 2023

Ok, I reload Kamera integration, after that I manually trigger automation te get URL, and stream is working only exactly 1:52. :(

I got such errors:

Logger: libav.https
Source: components/stream/worker.py:504
First occurred: February 16, 2023 at 22:40:56 (168 occurrences)
Last logged: 09:16:12

HTTP error 403 Forbidden
HTTP error 404 Not Found


and 

Logger: homeassistant.components.stream.stream.camera.isa_hlc6_3517_camera_control
Source: components/stream/__init__.py:434
Integration: Stream (documentation, issues)
First occurred: 08:50:10 (28 occurrences)
Last logged: 09:17:03

Error from stream worker: Error opening stream (HTTP_NOT_FOUND, Server returned 404 Not Found) https://de13.livestreaming.io.mi.com/hlstranscoder/GCA3N2VhOWZjNzM2ZTg0NGQzYmMwZWJiYzVhNjNhNWVlORgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8
Error from stream worker: Stream ended; no additional packets
Error from stream worker: Error opening stream (HTTP_FORBIDDEN, Server returned 403 Forbidden (access denied)) https://de13.livestreaming.io.mi.com/hlstranscoder/GCA3N2VhOWZjNzM2ZTg0NGQzYmMwZWJiYzVhNjNhNWVlORgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8
Error from stream worker: Error opening stream (HTTP_FORBIDDEN, Server returned 403 Forbidden (access denied)) https://de04.livestreaming.io.mi.com/hlstranscoder/GCA1MTZlNDY0NGU5N2I0ZWU3YjIwMDlhMWU5ZDc1Yjg4MBgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8
Error from stream worker: Error opening stream (HTTP_FORBIDDEN, Server returned 403 Forbidden (access denied)) https://de30.livestreaming.io.mi.com/hlstranscoder/GCAwNmUxODZhMDM4ZWM0ZDJkOTZkNjQ3NTFkNzE5NzM0NRgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8


Also preloading stream will help to keep stream URL properly?
image

What also I noticed:

Automation get URL form parameter Miot_out,
where actual stream_adress is different, see picture:
image

@mackbeth11
Copy link

Ok.. my mistake... i didn't change reload entity in automation... But still witohut any sucess - stream stopeed after 1:52 ... and also this reloading make problem.
I have to reload config of my real camera, this generic one is disabled, right?

@Zeunas
Copy link

Zeunas commented Feb 17, 2023

No, you have to disable the "real camera" (ie. the camera generated by the xioami miot integration), the generic camera will be your new camera, which will have a working stream address. I have explained this on my post below and that may be the reason why your stream stops at 1:52.

I may have found a workaround using @qubourse suggestion. It's in a very draft form and has it's flaws, although with a failsafe option! I have worked on this based on some assumptions, not sure if they are right but it works.

Follow these steps:

  1. Create an input_text helper to handle the stream address
    image
  2. Add a new Generic camera integration with the below options (note that the template for the stream source needs to be changed based on the above input_text name)

image

  1. Create an automation to be triggered every 4 minutes (just one minute before the stream address expires)

    • to call a service to get the stream address
    • as it generates a persistent notification the automation then extracts the stream address and adds it to the input text created on step 1
    • finally it reloads the Generic camera config to handle the new stream address (this is a must as whenever there's a new stream address, the Generic camera crashes and you can only make it work by reloading it)
alias: Office - Office cam url ping
description: ""
trigger:
  - platform: time_pattern
    minutes: /4
    id: time
condition: []
action:
  - service: xiaomi_miot.call_action
    data:
      entity_id: camera.office_cam
      siid: 4
      aiid: 1
      params:
        - 2
      throw: true
  - service: input_text.set_value
    data:
      value: >-
        {{
        (states.persistent_notification.xiaomi_miot_debug.attributes.message.split("
        ").11.strip("'],")).strip("['") }}
    target:
      entity_id: input_text.office_cam_url
  - service: persistent_notification.dismiss
    data:
      notification_id: xiaomi_miot_debug
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id: camera.office_cam
mode: single
  1. Disable the camera that is created by this integration. I believe that if it's not disabled it will request a different stream address every five minutes which will create a conflict with the above automation - This is an assumption as the above automation started to work much better when I disabled the camera.

A few suggestions:

  1. If you turn on the camera only when you need it like me just create another automation to turn on/off the above automation based on the camera switch state (on/off) and add an automation trigger service to be called as soon as you turn on the camera, otherwise you will need to wait 4 minutes until the above automation is triggered.
  2. I believe that whenever the camera detects motion it also creates a separate stream address, however I haven't yet been able to make the above automation work properly after motion is detected. Therefore either you wait for it to trigger again after a certain time passes or you can create a button on your lovelace to trigger the above automation (this would work as a failsafe in case the camera stream crashes somehow)

@Zeunas
Copy link

Zeunas commented Feb 17, 2023

Hi,

Could you prepare a simple instruction how to make Xiaomi camera to work with live stream? Step by step? :) As I see, I need to create dummy generic camera, pass via automation some stream URl.. but I don;t see any reference to my real camera entity,

Could you explain used parameters in service call?

  • service: xiaomi_miot.call_action
    data:
    entity_id: camera.office_cam
    siid: 4
    aiid: 1
    params:
    • 2
      throw: true
      In this example this entity ID is real camera from Miot Auto or this generic camera?

This is example state of my camera when it plays stream:

friendly_name: Kamera tył Camera Control
supported_features: 3
entity_picture: >-
  /api/camera_proxy/camera.isa_hlc6_1fbe_camera_control?token=ca8875ebffgh57d67d0947a9018e163f2e8a79e3be13fd
access_token: ca8875ebf75cbfe318972f60fgfhfghfhd67d0947a9018e163f2e8a79e3be13fd
model_name: isa.camera.hlc6
brand: isa
frontend_stream_type: hls
model: isa.camera.hlc6
lan_ip: 192.168.1.108
mac_address: E4:AA:EC:25:1F:BE
entity_class: MiotCameraEntity
home_room: Domek Podwórko
miot_type: urn:miot-spec-v2:device:camera:0000A01C:isa-hlc6:1
camera_control.on: true
camera_control.image_rollover: 180
camera_control.night_shot: 0
camera_control.time_watermark: true
camera_control.recording_mode: 2
stream_status-4-1: 1
state_updater: cloud
motion_video_time: '2023-02-16 20:53:35'
motion_video_type: ObjectMotion
miot_action_result:
  did: '373319099'
  miid: 0
  siid: 5
  aiid: 1
  code: 0
  out:
    - >-
      https://de09.livestreaming.io.mi.com/hlstranscoder/GCBlYjVhNmExZWJkNjg0ZDBmYmI5MWUyMmFkYTE2MzE5MxgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8
  exe_time: 0
  withLatency: 0
stream_address: >-
  https://de09.livestreaming.io.mi.com/hlstranscoder/GCBlYjVhNujlmExZWJkNjg0ZDBmYmI5MWUyMmFkYTE2MzE5MxgKX191bnVzZWRfXwA_H265transH264/playlist.m3u8
expire_at: '2023-02-16 23:27:35.410399'
sub_entities:
  - camera_control-2.on-1
  - motion_event
motion_video_latest:
  startDuration: 0
  cut: false
  offset: 0
  isCloud: false
  isRead: false
  videoStoreId: >-
    CAMERA_VIDEO_GLACoEfZ9-Gh0sZ0-GPzfc_ceatOw_GTElI_KC5720Qh1c-DKKQ84Pu5mXkFShh0g-pXm6ocb5Otp4b6SsWvfzdMv-_ufBfAdytpnXo73-X2DY5d2lBJOTV7dgKOS_2XJt9fi9dhtrnhbqWrTpIZYCVcQ4ddf9rlbOM7kOUyYvfmaLmj8IqdkpkeQYfd5eH4QbYAqb0I4fum3Ow5gf6iNfaE-TzPhjtaGk5W_Laojbqzn_uzTZ93WTK3iBZfPjvVP68xSgp_dgpeKeMNzWqsHzK0nay4yhf1BSj7ZD1uCfybgKxvNcQoipHJUaQqUZuql3rs6WtMQNy8qKWyZuf0XpZkWIXq5qM4aT7Tgy4mLBZdNRIf8RW9cidcc2AR6xDScXsYnRFpNCF-5_WHRrSaljRvLxgSeQlneWbWRIWICzPWOnqvXG4BGBA7MBzxqwmF46nahLORKwBiGBT_HC2-X6O-PE5YUvpSix3dGN6HLwA
  eventType: ObjectMotion
  expireTime: 1677182026758
  isAlarm: true
  isShowImg: true
  imgStoreId: >-
    CAMERA_IMG_GLACoEfZ9-Gh0sZ0-GPzfc_ceatOw_GTElI_KC5720Qh1c-DKKQ84Pu5mXkFShh0g-pXm6ocb5Otp4b6SsWvfzdMv-_ufBfAdytpnXo73-X2DY5d2lBJOTV7dgKOS_2XJt9fi9dhtrnhbqWrTpIZYCVcQ4ddf9rlbOM7kOUyYvfmaLmj8IqdkpkeQYfd5eH4QbYAqb0I4fum3Ow5gf6iNfaE-TzPhjtaGk5W_Laojbqzn_uzTZ93WTK3iBZfPjvVP68xSgp_dgpeKeMNzWqsHzK0nay4yhf1BSj7ZD1uCfybgKxvNcQoipHJUaQqUZuql3rs6WtMQNy8qKWyZuf0XpZkWIXq5qM4aT7Tgy4mLBZdNRIf8RW9cidcc2AR6xDScXsYnRFpNCF-5_WHRrSaljRvLxgSeQlneWbWRIWICzPWOnqvXG4BGBA7MBzxqwmF46nahLORKwBiGBT_HC2-X6O-PE5YUvpSix3dGN6HLwA
  fileId: '87038571416395392'
  extraInfo: '{"timezonenum":"3600"}'

@mackbeth11 Btw, careful with the information you share. On this post you're sharing your camera's access token and stream address. Make sure you edit this post right away and remove such references.

@mackbeth11
Copy link

Yes, I change tokens :)
Ok, so to summ upp..
In automation here

action:
  - service: xiaomi_miot.call_action
    data:
      entity_id: camera.office_cam
      siid: 4
      aiid: 1
      params:
        - 2
      throw: true

there is entity of generic camera, right?

I thought that service call took stream form REAL camera this from MIOT auto) and later in last step of automtaion reload GENERIC camera to play "fresh stream"
In your example I see that you use only entity of GNEREIC camera, right?

@mackbeth11
Copy link

Now i have config exactly as you, and automation throw error:
image

Automation:

 alias: OKamera przod URL
description: ""
trigger:
  - platform: time_pattern
    minutes: /4
    id: time
condition: []
action:
  - service: xiaomi_miot.call_action
    data:
      entity_id: camera.generic
      siid: 5
      aiid: 1
      params:
        - 2
      throw: true
  - service: input_text.set_value
    data:
      value: >-
        {{
        (states.persistent_notification.xiaomi_miot_debug.attributes.message.split("
        ").11.strip("'],")).strip("['") }}
    target:
      entity_id: input_text.podworko_kamera_url
  - service: persistent_notification.dismiss
    data:
      notification_id: xiaomi_miot_debug
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id: camera.generic
mode: single

Generic camera config:
image

image

@Zeunas
Copy link

Zeunas commented Feb 17, 2023

Hmm... you're right, something doesn't seem right although it was working for me... On the below service you should use the camera generated by this integration but on my post I used the Generic Camera which doesn't make sense... Give me a moment to look at this...

action:
  - service: xiaomi_miot.call_action
    data:
      entity_id: camera.generic
      siid: 5
      aiid: 1
      params:
        - 2

@mackbeth11
Copy link

mackbeth11 commented Feb 17, 2023

Yep, and if it will be done like that, I cannot delete/disable MIOT Auto "REAL" camera, as entity will be not available and I will be not able to fetch fresh stream
Also I noticed that timing of firts refresh URL is very impotent, so after get new stream address, need to check when it will expire, and automation have to get new stream adress just after expiration? or just after, because in REAL camera there will be now one?

@Zeunas
Copy link

Zeunas commented Feb 17, 2023

Ok, try then replacing it with the real camera entity_id and disabling the "preload camera stream" on the real camera (you can have it enabled on the Generic camera). Just did it and it seems to be working (don't know what I did to make it work the first time with the real camera disabled...).

@mackbeth11
Copy link

mackbeth11 commented Feb 17, 2023

Ok... now stream is playing until reload.. and after relood last 5 sec played in a loop. I think timning of get new stream is an issue, I"m not expert in HA,
may automation have to be triggered based on this

stream_address: ''
expire_at: '2023-02-17 11:23:41.352521'

What is logix of stream address change? Do you know? New one is available just before this expiration, 1 minute befor or just after? this is working immediately? In MI home app each 5 minutes I See that probably stream is changing (small timestamp lag) so probably new stream is prepared just after old one expire, so we need to find proper timing in HA to get new one and switch. What do you think?

@mackbeth11
Copy link

Ok.. finally looks like it works quite nice..

So what I did, I trigger this automation when generic camera became unavalaible - this mean, that it lost stream.
Then I call for new stream, it is inserted to helper. I added 3 sec delay, as Irelised that sometimes generic camera is not get this and later reload generic camera. In dashboard I added auto reloading card to have constantly live viwe.
What I;m wondring to have smoother transition - do you know when new sterma vai this service can be get from device? it is jus tbefor 5 minutes?

@mackbeth11
Copy link

What I observe, stera is broken sometimes after 5 minutes and sometimes after around @, see log picture when camera was unavailable and when I got new stream URL:

@Zeunas
Copy link

Zeunas commented Feb 17, 2023

Ah that's a good idea, didn't think of that because I thought it could take longer to load a new stream then having it generated every 4 minutes. Do you think it's smoother that way?

Yes the stream address is only valid for 5 minutes, after that a new one needs to be generated. The real camera also generates links every 5 minutes, that's why everyone is complaining on this post that HA has issues dealing with the new stream addresses on the real camera.

@mackbeth11
Copy link

mackbeth11 commented Feb 17, 2023

What I observed, strema is changed sometimes aftre 2 minutes (more or less) and sometimes after 5 minutes,it is inconsistent.. see log when it gone and when I got new stream URL:
image)

BTW:
MIOT AUto have such oiption:

And unfortunately reloading Generic camera took a lot of time :)

@Zeunas
Copy link

Zeunas commented Feb 17, 2023

Unfortunately that's a limitation of the system but at least we got something working now.

Also not sure if it's worth to have the below box ticked on your generic camera configuration to avoid it pining for a new stream address:

image

@mackbeth11
Copy link

mackbeth11 commented Feb 17, 2023

I already added this.

I have some idea - create 2 generic cameras, use conditional card, in automation start timer to fetch new stream, push to second camera, later do the same but set to first generic.. on dashboard it will be impression, that this is continuous playing.. but here is issue with timing, I need to know when new stream dress is available : ) What do you think?

Ok, after a little longer period: very inconsistent
image

@Vasa211
Copy link

Vasa211 commented May 10, 2023

How i can parsing link if i dont have parametr out?

value: "{{ states.persistent_notification.xiaomi_miot_debug.attributes.message }}"
Give me:
{'did': 'some_digits', 'miid': 0, 'siid': 9, 'aiid': 1, 'code': -some_digits, 'description': 'action arguments error', 'exe_time': 0, 'withLatency': 0}

But i have link here (little bottom):
stream_address: ************** expire_at: 2023-05-10 14:57:35.118767

@danielsitnik
Copy link

My chuangmi.camera.ipc009 camera used to work fine with HA and this component, but now I can no longer see the video stream on HA. :(

Test with ffmpeg returns this:

[tls @ 0x600003a901b0] Error in the pull function.
[tls @ 0x600003a901b0] IO error: Connection reset by peer
https://us.livestreaming.io.mi.com/hlstranscoder/xxx_H265transH264/playlist.m3u8: Connection reset by peer

Is this no longer supported?

@OrhayBenaim
Copy link

OrhayBenaim commented Aug 30, 2023

not getting stream_address
the error when running service action to get stream_address

Logger: homeassistant.helpers.script.websocket_api_script
Source: custom_components/xiaomi_miot/__init__.py:1943
Integration: Xiaomi Miot Auto ([documentation](https://github.com/al-one/hass-xiaomi-miot), [issues](https://github.com/al-one/hass-xiaomi-miot/issues))
First occurred: 4:39:49 PM (3 occurrences)
Last logged: 4:41:32 PM

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 'NoneType' object has no attribute 'in_params'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 703, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 665, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 1974, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2011, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/xiaomi_miot/__init__.py", line 421, in async_service_handler
    result = await getattr(ent, fun)(**params)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/xiaomi_miot/__init__.py", line 1977, in async_miot_action
    return await self.hass.async_add_executor_job(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/xiaomi_miot/__init__.py", line 1943, in miot_action
    pms['in'] = action.in_params(params or [])
                ^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'in_params'

the state

entity_picture: /api/camera_proxy/camera.chuangmi_ipc019_c3ae_camera_control?token=e3fe1706119ece8c1b05bf3ec8abeaf6de36773d6f7f5ca16df74e0ffda6ab4b
friendly_name: Xiaomi Miot Camera Control
supported_features: 3
sub_motion_stream: true
keep_streaming: true
video_attribute: 1
miot_local: true
access_token: e3fe1706119ece8c1b05bf3ec8abeaf6de36773d6f7f5ca16df74e0ffda6ab4b
model_name: chuangmi.camera.ipc019
brand: chuangmi
frontend_stream_type: hls
model: chuangmi.camera.ipc019
lan_ip: 192.168.X.X
mac_address: 78:8B:2A:C6:C3:AE
entity_class: MiotCameraEntity
miot_type: urn:miot-spec-v2:device:camera:0000A01C:chuangmi-ipc019:1
stream_address: 
expire_at: 2023-08-30 16:45:08.346096
camera_control.on: true
camera_control.image_rollover: 0
camera_control.night_shot: 0
camera_control.time_watermark: true
camera_control.wdr_mode: false
glimmer_full_color-2-6: true
camera_control.recording_mode: 2
state_updater: lan
sub_entities: camera_control-2.on-1, motion_event

@Tunminkhaing
Copy link

https://www.facebook.com/stories/116451483275702/UzpfSVNDOjY2Nzg5MzM1NTQwNjEyNg==/?view_single=1&source=shared_permalink&mibextid=Nif5oz

@FilipeOS
Copy link

FilipeOS commented Jan 19, 2024

I may have found a workaround using @qubourse suggestion. It's in a very draft form and has it's flaws, although with a failsafe option! I have worked on this based on some assumptions, not sure if they are right but it works.

Follow these steps:

  1. Create an input_text helper to handle the stream address
    image
  2. Add a new Generic camera integration with the below options (note that the template for the stream source needs to be changed based on the above input_text name)

image

  1. Create an automation to be triggered every 4 minutes (just one minute before the stream address expires)

    • to call a service to get the stream address
    • as it generates a persistent notification the automation then extracts the stream address and adds it to the input text created on step 1
    • finally it reloads the Generic camera config to handle the new stream address (this is a must as whenever there's a new stream address, the Generic camera crashes and you can only make it work by reloading it)
alias: Office - Office cam url ping
description: ""
trigger:
  - platform: time_pattern
    minutes: /4
    id: time
condition: []
action:
  - service: xiaomi_miot.call_action
    data:
      entity_id: camera.office_cam
      siid: 4
      aiid: 1
      params:
        - 2
      throw: true
  - service: input_text.set_value
    data:
      value: >-
        {{
        (states.persistent_notification.xiaomi_miot_debug.attributes.message.split("
        ").11.strip("'],")).strip("['") }}
    target:
      entity_id: input_text.office_cam_url
  - service: persistent_notification.dismiss
    data:
      notification_id: xiaomi_miot_debug
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id: camera.office_cam
mode: single
  1. Disable the camera that is created by this integration. I believe that if it's not disabled it will request a different stream address every five minutes which will create a conflict with the above automation - This is an assumption as the above automation started to work much better when I disabled the camera.

A few suggestions:

  1. If you turn on the camera only when you need it like me just create another automation to turn on/off the above automation based on the camera switch state (on/off) and add an automation trigger service to be called as soon as you turn on the camera, otherwise you will need to wait 4 minutes until the above automation is triggered.
  2. I believe that whenever the camera detects motion it also creates a separate stream address, however I haven't yet been able to make the above automation work properly after motion is detected. Therefore either you wait for it to trigger again after a certain time passes or you can create a button on your lovelace to trigger the above automation (this would work as a failsafe in case the camera stream crashes somehow)

Is this still working? Do you have better approach?
Creating the generic camera say don't allow relative url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests