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时需要向我展示哪些信息?

masakotsubuku1 commented 1 year ago

Seems like there is no solution for this problem involving stream url update from miot... HA won't integrate the new url without re-integrating the device again... and it's every 5 minutes...

qubourse commented 1 year ago

Hi everyone !

Camera device model: chuangmi.camera.046a01 camera-stream-for-google-home is present : https://home.miot-spec.com/spec/chuangmi.camera.046a01

I encounter some problems with the integration of my camera:

miot_action_error: '-704220025 The number of action parameters does not match'
stream_address.error: '-704030013 Property is not readable'
video_codec_type.error: '-704030013 Property is not readable'
video_attribute.error: '-704030013 Property is not readable'
audio_codec_type.error: '-704030013 Property is not readable'
audio_attribute.error: '-704030013 Property is not readable'
stream_receiver_id.error: '-704030013 Property is not readable'
stream_auth_token.error: '-704030013 Property is not readable'
expiration_time.error: '-704030013 Property is not readable'

Full state :

model_name: chuangmi.camera.046a01
brand: chuangmi
frontend_stream_type: hls
model: chuangmi.camera.046a01
lan_ip: 192.168.1.39
mac_address: XXXXXXXXXXX
entity_class: MiotCameraEntity
home_room: Maison Salle de séjour
miot_type: urn:miot-spec-v2:device:camera:0000A01C:chuangmi-046a01:1
miot_action_result:
  did: '1028970298'
  miid: 0
  siid: 7
  aiid: 1
  code: -704220025
  exe_time: 0
  withLatency: 0
camera_control.on: true
camera_control.image_rollover: 0
camera_control.night_shot: 1
camera_control.wdr_mode: false
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: true
motion_detection.alarm_interval: 20
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:
  - motion_detection-5.motion_detection-1
  - indicator_light-3
  - camera_control-2.on-1
  - motion_event
motion_video_time: '2022-10-16 23:00:33'
motion_video_type: ObjectMotion:PeopleMotion
stream_address: >-
  https://de.business.smartcamera.api.io.mi.com/common/app/XXXXX
image_address: >-
  https://de.processor.smartcamera.api.io.mi.com/miot/camera/app/v1/img?dataXXXX
miot_action_error: '-704220025 The number of action parameters does not match'
stream_address.error: '-704030013 Property is not readable'
video_codec_type.error: '-704030013 Property is not readable'
video_attribute.error: '-704030013 Property is not readable'
audio_codec_type.error: '-704030013 Property is not readable'
audio_attribute.error: '-704030013 Property is not readable'
stream_receiver_id.error: '-704030013 Property is not readable'
stream_auth_token.error: '-704030013 Property is not readable'
expiration_time.error: '-704030013 Property is not readable'
motion_video_latest:
  startDuration: 0
  cut: false
  offset: 0
  isCloud: false
  isRead: true
  videoStoreId: >-
    XXXX
  eventType: ObjectMotion:PeopleMotion
  expireTime: 1666558840067
  isAlarm: true
  isShowImg: true
  imgStoreId: >-
    XXXX
  fileId: '81469860987013248'
  extraInfo: '{"ver":"1.0.0","alarmStart":true,"eventType":"ObjectMotion"}'
entity_picture: >-
  /api/camera_proxy/camera.chuangmi_046a01_XXXX_camera_control?token=XXXXXX
friendly_name: Camera Salon Camera Control
supported_features: 3
qubourse commented 1 year ago

Update :

I finally have a working stream address BUT :

It's progressing a bit, but it's still not that

CagoBHuK commented 1 year ago

Camera device model (Like: brand.camera.abc): chuangmi.camera.ipc009, link: https://home.miot-spec.com/spec?type=urn:miot-spec-v2:device:camera: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.

CagoBHuK commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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?

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

FilipeOS commented 8 months ago

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