Hacking the XiaomiFang Wifi camera

I had this in my mind H/W codec I would have thought the pi would have been enabled for H/W playback, the hardware is there, guess it’s because hassio is some kind of VM. Still my pentium quad in the NAS should be more man enough (it can transcode 1080p) but guessing not. Thanks for confirming my thoughts

How do I hack the rtsp script file to output video 640x360@15FPS

check here more detail:

Hi Guys , need help with mqtt configuration
get message from HA from info “Invalid config for [camera.mqtt]: required key not provided @ data[‘topic’]. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/camera.mqtt/

attaching my mqtt.conf and configuration.yaml file :slight_smile:

HA

mqtt:
broker: 10.0.0.201
port: 1883
client_id: home-assistant-1
username: username
password: password
discovery: true
discovery_prefix: homeassistant

  • platform: ffmpeg
    name: Cam
    input: -rtsp_transport tcp -i rtsp://10.0.0.90:8554/unicast

  • platform: mqtt
    name: “dafang3”
    state_topic: “myhome/dafang/status”
    command_topic: “myhome/dafang/set”
    payload_on: “motor_down”
    optimistic: false

mqtt.conf :

############################################################

edit this file and move it to /system/sdcard/config/mqtt.conf

############################################################

export LD_LIBRARY_PATH=’/thirdlib:/system/lib:/system/sdcard/lib’

Options for mosquitto_sub & mosquitto_pub

USER=username
PASS=password
HOST=10.0.0.201
PORT=1883

Define a location

LOCATION=“myhome”

Define device name

DEVICE_NAME=“dafang”

Define the base topic used by the camera

send a message to myhome/dafang/set with the payload help for help.

Results will be placed in myhome/dafang/${command} or topic/dafang/error - so please subscribe topic/dafang/# for testing purposes

TOPIC="$LOCATION/$DEVICE_NAME"

Define an autodiscovery prefix, if autodiscovery is desired:

AUTODISCOVERY_PREFIX=“homeassistant”

Define additional options for Mosquitto here.

For example --cafile /system/sdcard/config/DST_Root_CA_X3.pem --tls-version tlsv1

or use a special id to connect to brokers like azure

MOSQUITTOOPTS=""

Add options for mosquitto_pub like -r for retaining messages

MOSQUITTOPUBOPTS=""

Add options for curl here e.g --user user:password

CURLOPTS="–-user root:ismart12"

Send a mqtt statusupdate every n seconds

STATUSINTERVAL=30

please help …

Hoping someone can help me out with a problem I am experiencing. I have a Wyze V2 camera that has been successfully updated with V0.26 of the OpenIPC firmware. I have been able to successfully integrate the camera into home assistant with MQTT and can display a video feed from VLC using rtsp://192.168.1.219:8554/unicast. I also get snapshots displayed every 10 seconds or so when I add the camera into one of my groups in home assistant. The problem is that I cannot create a snapshot from a script or automation - I always end up with a zero length file and the following error information in the log file:

2018-05-22 16:25:41 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall camera.snapshot: entity_id=[‘camera.dafang_1_motion_snapshot’], filename=<homeassistant.helpers.template.Template object at 0x6fb5ea30>>
Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/core.py”, line 1002, in _event_to_service_call
await service_handler.func(service_call)
File “/usr/lib/python3.6/site-packages/homeassistant/components/camera/init.py”, line 202, in async_handle_snapshot_service
_write_image, snapshot_file, image)
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/lib/python3.6/site-packages/homeassistant/components/camera/init.py”, line 198, in _write_image
img_file.write(image_data)
TypeError: a bytes-like object is required, not ‘NoneType’

Pertinent config info is:

homeassistant:
  whitelist_external_dirs:
    - '/config/tmp'

camera:
  - platform: ffmpeg
    name: Test
    input: -rtsp_transport tcp -i rtsp://192.168.1.219:8554/unicast

mqtt:
  broker: core-mosquitto
  username: !secret mosquitto_user
  password: !secret mosquitto_password
  discovery: true
  discovery_prefix: homeassistant

Script for snapshot:
take_snapshot:
alias: Take snapshot from dafang1
sequence:
- service: camera.snapshot
data:
entity_id: camera.dafang_1_motion_snapshot
filename: ‘/config/tmp/dafang1_{{ now().strftime(“%Y%m%d-%H%M%S”) }}.jpg’

Anyone have a good Aliexpress or other website link to buy these that are hackabale? Looks very cool. US based here.

You can buy the Wyzecam directly from the manufacturer (https://www.wyzecam.com/) or from Amazon (https://smile.amazon.com/Wyze-Indoor-Wireless-Camera-Vision/dp/B076H3SRXG/ref=sr_1_1?s=electronics&ie=UTF8&qid=1527080262&sr=1-1&keywords=wyzecam+v2). They are hackable by following the instructions on the OpenIPC website:

Hi does tracking work? as in enable/disable tracking?

Hi,

Can’t star the mqtt-control. Changed the mqtt.conf but mqtt-control allways shows “nok”.
Is there anyone that could help?
Thanks.

did you start the mqtt-status BEFORE starting mqtt-control? I had the same issue but after looking at the PID of the example webpage screenshots I realized the mqtt-status should be started first.

For the last days I am trying to send the currentpic.cgi picture with telegram. Not successful yet.
Was someone successful to save the picture to the hassio SD Card or send it directly with telegram at: https://[IP-Address]/cgi-bin/currentpic.cgi ?

At the moment I take a snapshot from the video stream, save it to the hassio SD card and send it with telegram, but the picture quality is not very high.
This is my setup at the moment:

camera:
  - platform: ffmpeg
    name: dafang_stream
    input: -rtsp_transport tcp -i rtsp://192.168.1.249:8554/unicast

Thats the automation which takes the snapshot and sends it with telegram:

- alias: notify_1_xiaomi_dafang_1_send_picture
  initial_state: True
  hide_entity: False
  trigger:
    - platform: state
      entity_id: 
        - sensor.front_door_node_1_pir_motion_status 
        - sensor.r433_mhz_random_code
  action:
    - service: camera.snapshot
      data:
        entity_id: camera.dafang_stream
        filename: '/config/www/xiaomi_dafang_1/dafang_snapshot_1.jpg'
    - service: notify.notify_1
      data:
        title: Send an image
        message: That's an example that sends an image.
        data:
          photo:
            - file: '/config/www/xiaomi_dafang_1/dafang_snapshot_1.jpg'
              caption: >
                Front Door Snapshot 1
                {{ states.sensor.current_date_time.state }}

My cameras are shipped and I am looking forward to making this work. Cheers for a very informative thread.

Telegram apparently compresses images (google ‘telegram image quality’).

What is the status of this issue : Log Details (WARNING)
Sat Jun 09 2018 10:40:48 GMT+0200 (CEST)

Payload is not True, False, or integer (0-100):
10:40 components/cover/mqtt.py (WARNING)

I am also trying to troubleshoot but I can’t find where mqtt-discovery is adding the components…

At a guess:

thnx…

Will try to troubleshoot. I think something has changed in HA with the cover component.
Not sure what.

Hi,

I hope you are fine.

I do have the same issue as some others here.
The settings, like turn off the stream is not going through the cam via MQTT.
I use the discovery function etc.
Also if I change at the cam side, I can see, after those 30 seconds, the state change, but it does not work the other way around.

Hass.io(docker version) with the mqtt add-on installed.
It looks like it is only working one way, but I would love to get it to work in booth ways

Unfortunately i am not that familiar with mqtt, so I am no sure if the command or status change to turn the stream off is ever reaching the cam.

I am allmost there, last problem is that I cannot start mqtt control, it shows NOK, mqtt status gives me a PID and number. What can be the problem?

I also do not see anything in the Home assistant interface, no sensors and actors.

Hope you guys can help me.

Thanks

Setup is:
USER=mqtt_user
PASS=*********
HOST=localhost
PORT=1883

LOCATION=“room”

DEVICE_NAME=“dafang”

Hi,

it is important to start the mqtt service BEFORE start the mqtt control, otherwise it will not work.
I do have booth to automatic startup, then do a restart and it should work again.

Are the sensors there ?
I mean you still have to create them in the view (if you are not using the default view anymore) otherwise the sensors are there but not on the GUI

Cheers

Ok, I got the sensors in HASS (the LED and RTSP) but they all show up unknows status.mqtt is working in HASS (I see developer options) and mqtt data in camera file has the same username/password/etc.) Also mqtt-control shows ‘NOK’

This is the data:

  • platform: mqtt
    name: “DaFang RTSP”
    state_topic: “room/dafang/status”
    value_template: “{% if value_json[“RTSP-Server”] == ‘running’ %}h264_noseg_start{% else %}rtsp_stop{% endif %}”
    command_topic: “room/dafang/set”
    payload_on: “h264_noseg_start”
    payload_off: “rtsp_stop”
    optimistic: false
  • platform: mqtt
    name: “blue LED”
    state_topic: “room/dafang/status”
    value_template: “{% if value_json.LEDs.Blue == ‘on’ %}blue_led_on{% else %}blue_led_off{% endif %}”
    command_topic: “room/dafang/set”
    payload_on: “blue_led_on”
    payload_off: “blue_led_off”
    optimistic: false
  • platform: mqtt
    name: “yellow LED”
    state_topic: “room/dafang/status”
    value_template: “{% if value_json.LEDs.Yellow == ‘on’ %}yellow_led_on{% else %}yellow_led_off{% endif %}”
    command_topic: “room/dafang/set”
    payload_on: “yellow_led_on”
    payload_off: “yellow_led_off”
    optimistic: false?

What am I missing?

Proper formatting.

3 Likes