Sonoff GK-200MP2-B IP Camera

@MikeF9 I have ran into the exact same issue. PTZ buttons arent working :frowning: Feel like I’ve tried everything at this point. Created services through the UI, config.yaml and scripts.yaml. Nothing I do appears to work. I have also noticed my device id dropping to 123456 from ‘123456’.

Are you able to share you scripts & button code with me so I can give it a try?

Hi @apomper

So I’ve got my cameras finally working. They don’t always respond every time I try move them but a reboot of the camera seems to work.

Firstly, I’m using a Picture Elements Card Configuration which I had to setup with the code editor as the visual editor won’t allow it. The coding, for the one camera, is as follows:

type: picture-elements
camera_view: live
camera_image: camera.sonoff_main_camera
elements:
  - type: icon
    icon: 'mdi:arrow-left-drop-circle'
    tap_action:
      action: call-service
      service: script.main_camera_left
    style:
      bottom: 45%
      left: 5%
      color: white
      opacity: 0.5
      transform: 'scale(1.5, 1.5)'
  - type: icon
    icon: 'mdi:arrow-right-drop-circle'
    tap_action:
      action: call-service
      service: script.main_camera_right
    style:
      bottom: 45%
      right: 5%
      color: white
      opacity: 0.5
      transform: 'scale(1.5, 1.5)'
  - type: icon
    icon: 'mdi:arrow-up-drop-circle'
    tap_action:
      action: call-service
      service: script.main_camera_up
    style:
      top: 10%
      left: 46%
      color: white
      opacity: 0.5
      transform: 'scale(1.5, 1.5)'
  - type: icon
    icon: 'mdi:arrow-down-drop-circle'
    tap_action:
      action: call-service
      service: script.main_camera_down
    style:
      bottom: 10%
      left: 46%
      color: white
      opacity: 0.5
      transform: 'scale(1.5, 1.5)'
  - type: icon
    icon: 'mdi:arrow-expand-all'
    tap_action:
      action: more-info
    entity: camera.sonoff_main_camera
    style:
      top: 5%
      right: 5%
      color: white
      opacity: 0.5
      transform: 'scale(1.5, 1.5)'

My configuration.yaml file has the following:

camera:
  - platform: ffmpeg
    name: Sonoff Main Camera
    input: -rtsp_transport tcp -i rtsp://rtsp:[email protected]:554/av_stream/ch0

The scripts I have for the PTZ buttons are up, down, left and right. Example below…

main_camera_up:
  alias: Main Camera Up
  sequence:
  - service: sonoff.send_command
    data:
      device: *input your 6 digit camera number here including the ZERO if it's starts with a ZERO*
      cmd: up
  mode: single

To answer the issue with the dropping from ‘123456’ to 123456, I configured it in my scripts.yaml with the ’ and ’ and it also dropped it again, after saving the file and restarting HA, but itworks. In my visual editor of my script it looks like this.

image

The device number shows in a pinky red colour.

Let me know if you don’t come right.

And if anyone knows how to get rid of the, roughly, 7 second delay between pressing the up, down, left or right arrows, before you see the picture actually move, please share.

So the final product looks like this…

image

Thank you for the very detailed guide @MikeF9. I will give it a try shortly.
You can get rid of the delay by running WebRTC (also from AlexxIT). Link here

Edit.
I have used your exact script & button code and still nothing appears to work :frowning: Even with debug logging enabled for Sonoff & HA, no errors appear anywhere. Tried running the scripts directly from the scripts page also with no success.

My scripts.yaml has kept the ‘’ through restarts. The GUI version of the scripts has dropped the ‘’ but device ID is red just like yours.

service

I’m about to give up lol

Edit2:
Fire up my test VM and set everything up the same there. And, IT WORKED!. So it looks like I have something causing issues on my main HA server :frowning: At least I know where to troubleshoot now.
Thank you very much for your help.

Great to hear, and not so great that you can’t get it to work on your production server.

Hope you figure it out.

Question, are you using the picture elements card now? Are you not using the WebRTC card with PTZ?
I’m playing around with it and it’s working, just would prefer the PTZ buttons on the WebRTC card to display the same way as they do on the Picture Elements Card

Hi @MikeF9. Your setup made me interested in this camera. Also saw your comment on the WebRTC thread. A few questions before I order this:

  1. Were you able to expose the motion detection binary sensor entity of the camera to HA?
  2. Have you tried adding the camera to HA using the ONVIF integration? (I have another camera and the motion detection binary sensor was automatically exposed to HA using the ONVIF integration; PT (not Z) controls are also managed using the integration.
  3. Using the WebRTC custom card, do you get audio as well from the camera on HA?
  4. Can you please share your WebRTC custom card config with the PTZ controls?

Hi there

As of yet I haven’t been able to expose the motion sensor to HA. It would be great it we could because then I’ d setup a script to record and forward myself the video via my Telegram Bot.

I haven’t used the ONVIF Integration. Please let me know if you’ve tried and if it worked.

The WebRTC card allows one way audio for now, I did mention it on @AlexxIT WebRTC forum. Realtime camera streaming without any delay - WebRTC, that it would be great to have two way audio.

If you go to the link above, @AlexxIT has all the details you need to set the card up.

My card looks as follows:

type: 'custom:webrtc-camera'
url: 'rtsp://rtsp:[email protected]:554/av_stream/ch0'
intersection: 0.75
ui: true
webrtc: true
ptz:
  opacity: 0.8
  service: sonoff.send_command
  data_left:
    device: "Your cameras 6 digit Unique Number"
    cmd: left
  data_right:
    device: "Your cameras 6 digit Unique Number"
    cmd: right
  data_up:
    device: "Your cameras 6 digit Unique Number"
    cmd: up
  data_down:
    device: "Your cameras 6 digit Unique Number"
    cmd: down

Hope this helps

Thanks, @MikeF9. I just ordered the camera on Ali and it will arrive first week of June. Been researching on how to expose the camera’s motion sensor to HA and found this:

Have you tried this? Looks like a possible solution with no risk of bricking the camera.

Same problem here, any luck directly connecting it to motioneye?

I did, yes. From memory it was something to do with the trailing slash - also it didn’t show up a preview straight away. So leave it a few minutes when you change something to check if it actually works.

Hi Mike,
my I bother you with a quick question?
I followed the setup that you described, using @alexxIT 's awesome integration as seen on github.
When I click on the control buttons in the card, I get Failed to call service sonoff/send_command. Service not found.
I assume I need to define the sonoff/send_command somewhere?
Thoughts ?
thanks,
chrisV

Hi Chris

Are you referring to the WebRTC integration or just using the picture element card?

I no longer use the picture element card and am using @AlexxIT ’s WebRTC HASS integration.

Hi @MikeF9
yes, I am using AlexxIT’s WebRTC HASS integration as well.
The reaction of the camera is a lot better.
The Picture Element Card has too long delays on my camera (close to 10 seconds)

So, the video part of the WebRTC HASS integration works, but I can’t get the controls to work (see screenshot below)

Do I need to install a separate service that you know of?
thank you
chrisV

BTW, this is how my scripts.yaml looks like
(and it is “included” in configuration.yaml")

left:
  sequence:
    - service: sonoff.send_command
      data:
        device: 'my 6 digit device id'  # use quotes, this is important
        cmd: left

right:
  sequence:
    - service: sonoff.send_command
      data:
        device: 'my 6 digit device id'  # use quotes, this is important
        cmd: right

up:
  sequence:
    - service: sonoff.send_command
      data:
        device: 'my 6 digit device id'  # use quotes, this is important
        cmd: up

down:
  sequence:
    - service: sonoff.send_command
      data:
        device: 'my 6 digit device id'  # use quotes, this is important
        cmd: down

You have installed the Sonoff LAN integration from @AlexxIT hey?

The sonoff.send_command is a service that’s built into that integration on HACS

ah… I need to install that one as well?
No I haven’t… I thought that was for something else
thanks !
I will take a look at it
chrisV

yes, that was it !
It was not clear to me that you need to install 2 HACS repos from AlexxIT’s store. (webRTC Camera and Sonoff Lan)

It all works beautifully now
1AM… time to bed
chrisV

Hi, but the PTZ controls of webrtc lovelace card are for sonorr LAN component, right? how to have controls with the cxamera running sonoff-hack firm? thanks (my only idea is accomodate that calls to the restAPI calls to the webportal of sonoff-hack like http://192.168.1.XX/cgi-bin/ptz.sh?dir=down

Hi - I found 2 different approaches to do pan/tilt with the sonoff camera that work with the sonoff-hack firmware:

Approach 1 - First Install the yi-camera-custom component @ https://github.com/robtesch/home-assistant-yi-camera-custom
Second- Use the yi-camera-custom ptz service call in your love lace card of choice.

service: yi_hack.ptz
service_data:
  entity_id: camera.yi_hack_s_b44dd9_cam #auto generated
  movement: left
  travel_time: 0.3

Approach 2- Enable the ONVIF integration in the sonoff-hack web UI.
Next add the ONVIF integration for your camera in the home assistant integrations UI.
Finally- replace the pan/tilt service call in your love lace card of choice with the ONVIF service call data model for your camera.

Onvif service call:

service: onvif.ptz
service_data:
  pan: LEFT # or tilt: UP
  distance: 0.31
  speed: 1  
  move_mode: RelativeMove
  entity_id: camera.backdoor_profile_0

Bonus: you can set the speed and other variables in both the yi-camera-custom as well as the ONVIF integration that I don’t believe is in the https://github.com/AlexxIT/SonoffLAN integration.

Here is my card for reference:

Here is the lovelace yaml for my card using the yi-camera-custom component and the frigate NVR card.

type: vertical-stack
cards:
  - type: custom:frigate-card
    frigate_camera_name: backdoor
    view_timeout: '30'
    autoplay_clip: true
    controls: {}
    webrtc:
      entity: camera.yi_hack_s_b44dd9_cam # Backdoor camera created by yi-camera-custom
    menu_mode: below
    camera_entity: camera.yi_hack_s_b44dd9_cam
    view_default: live
    live_provider: webrtc
  - type: horizontal-stack
    cards:
      - type: custom:button-card
        color_type: card
        color: rgb(223, 255, 97)
        icon: mdi:arrow-collapse-left
        tap_action:
          action: call-service
          service: yi_hack.ptz
          service_data:
            entity_id: camera.yi_hack_s_b44dd9_cam
            movement: left
            travel_time: 0.3
      - type: custom:button-card
        color_type: card
        color: rgb(223, 255, 97)
        icon: mdi:arrow-collapse-right
        tap_action:
          action: call-service
          service: yi_hack.ptz
          service_data:
            entity_id: camera.yi_hack_s_b44dd9_cam
            movement: right
            travel_time: 0.3
      - type: custom:button-card
        color_type: card
        color: rgb(223, 255, 97)
        icon: mdi:arrow-collapse-up
        tap_action:
          action: call-service
          service: yi_hack.ptz
          service_data:
            entity_id: camera.yi_hack_s_b44dd9_cam
            movement: up
            travel_time: 0.3
      - type: custom:button-card
        color_type: card
        color: rgb(223, 255, 97)
        icon: mdi:arrow-collapse-down
        tap_action:
          action: call-service
          service: yi_hack.ptz
          service_data:
            entity_id: camera.yi_hack_s_b44dd9_cam
            movement: down
            travel_time: 0.3
      - type: custom:button-card
        color_type: blank-card
      - type: custom:button-card
        color_type: blank-card

Please let me know if I can provide any additional detail.

1 Like

thanks @ninjasstudio , i managed to add PTZ Yi Hack service to the card :slight_smile: , thanks for sharing your info.

Here is mine, with the camera running sonoff-hack, and added to HA with yi-hack:

type: custom:webrtc-camera
url: rtsp://USER:[email protected]:554/av_stream/ch0
intersection: 0.75
ui: true
webrtc: true
ptz:
  service: yi_hack.ptz
  data_left:
    entity_id: camera.yi_hack_s_XXXXX_cam
    movement: left
    travel_time: 0.3
  data_right:
    entity_id: camera.yi_hack_s_XXXXX_cam
    movement: right
    travel_time: 0.3
  data_up:
    entity_id: camera.yi_hack_s_XXXXX_cam
    movement: up
    travel_time: 0.3
  data_down:
    entity_id: camera.yi_hack_s_XXXXX_cam
    movement: down
    travel_time: 0.3

Between using Yi Hack or ONVIF… any advantages or disaadvantages? Im using only YiHack and deactivated the ONVIF server on the camera with sonoff-hack (and deactivated cloud also). But im not sure what I’m missing :smiley:

Thanks

Yes I’m just coming to this and seems like the two options are YiHack/SonoffHack or the webRTC/SonoffLAN combo. Would appreciate any pros/cons from those who have tried both?