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

ON / OFF status in real time #62

Closed
SmartM-ui opened this issue Sep 29, 2021 · 30 comments
Closed

ON / OFF status in real time #62

SmartM-ui opened this issue Sep 29, 2021 · 30 comments
Assignees

Comments

@SmartM-ui
Copy link

Hi @fuatakgun
I noticed that if I change the on off status of the cam through the original app, in the home assistant, the status change is displayed with about 10 minutes delay.

To have it updated in real time, the security status must be changed, via the official app, by setting from home to away, or via the alarm activation service in the home assistant.

Conversely, I tried to turn the cam on and off from Home Assistant and the official app immediately shows the status change, closing and reopening the Eufy app.

Would it be possible to create the service to get the on / off status in real time?

Thanks

@fuatakgun
Copy link
Owner

As we have covered in previous issue, fetching on/off status real time is not feasible, given that eufy is not sending push notifications to its clients about state changes. My proposal is to create a service to fetch latest status and you can use this service as you want.

Conversely, I tried to turn the cam on and off from Home Assistant and the official app immediately shows the status change, closing and reopening the Eufy app. As you can see here, it actually did not show up immediately, you had to reopen the app, which had triggered to fetch latest status. Please do not mix it.

@SmartM-ui
Copy link
Author

As we have covered in previous issue, fetching on/off status real time is not feasible, given that eufy is not sending push notifications to its clients about state changes. My proposal is to create a service to fetch latest status and you can use this service as you want.

Conversely, I tried to turn the cam on and off from Home Assistant and the official app immediately shows the status change, closing and reopening the Eufy app. As you can see here, it actually did not show up immediately, you had to reopen the app, which had triggered to fetch latest status. Please do not mix it.

OK,
if you can create the service it would be a useful option!
Thanks

@fuatakgun fuatakgun self-assigned this Oct 2, 2021
@SmartM-ui
Copy link
Author

SmartM-ui commented Oct 6, 2021

Hi @fuatakgun ,
in the bropat repo (https://github.com/bropat/eufy-security-ws#device-level-commands) that you advised me to see in another topic, I found a service that I thought could be used to view sensor status updated:

service: eufy_security.send_message
data:
  message: |-
    {
      "messageId": "message_id_do_not_add_value_here", 
      "command": "driver.poll_refresh",
      "serialNumber": "T8410XXX", 
    }

I tried to run it, following your examples in the other topic, it did not report errors, but it did not update the device information on home assistant.

Did I get the code wrong or is it not for this?

Thanks

@fuatakgun
Copy link
Owner

i was going to wrap this by a specific service, but you are right, you can call this via send_message, but your format is wrong, you do not need to pass serial number as poll_refresh will try to refresh everything. can you try like below and check if there are any errors in eufy ws add on logs?

service: eufy_security.send_message
data:
  message: |-
    {
      "messageId": "message_id_do_not_add_value_here", 
      "command": "driver.poll_refresh"
    }

@SmartM-ui
Copy link
Author

i was going to wrap this by a specific service, but you are right, you can call this via send_message, but your format is wrong, you do not need to pass serial number as poll_refresh will try to refresh everything. can you try like below and check if there are any errors in eufy ws add on logs?

service: eufy_security.send_message
data:
  message: |-
    {
      "messageId": "message_id_do_not_add_value_here", 
      "command": "driver.poll_refresh"
    }

Yes!
It works :-)
By launching the service, it updates the status in real time.

I tried both the camera status and the led status and they are updated in real time after launching the service.

Great

@SmartM-ui
Copy link
Author

SmartM-ui commented Oct 6, 2021

Hi @fuatakgun,
after verifying that the camera.eufy attributes are updated in real time when launching the service, I was trying to create, for example, the status led sensor, but it always turns out unknow and even in the developer tools, it returns me "null" .

Can the attributes present be used to create a sensor or do you have to create it yourself as the binary sensor "enabled"?

example:

{{state_attr ('camera.eufy', 'statusLed')}}

(NULL)


sensor:
   - platform: template
     sensors:
       eufy_status_led:
         friendly_name: "Eufy Status Led"
         value_template: "{{state_attr ('camera.eufy', 'statusled')}}"

(UNKNOW)

Thanks

@fuatakgun
Copy link
Owner

replace garage_camera with your own camera name

{{ state_attr("camera.garage_camera", "data")["statusled"] }}

@SmartM-ui
Copy link
Author

SmartM-ui commented Oct 6, 2021

replace garage_camera with your own camera name

{{ state_attr("camera.garage_camera", "data")["statusled"] }}

Thanks @fuatakgun for that too.
I noticed some strange behavior!

From the developer tools and in the camera.eufy attributes, the status is changed immediately.

The sensor created, however, is not always updated:

sensor:
  - platform: template
    sensors:
      eufy_status_led:
        friendly_name: "Eufy Status Led"
        value_template: "{{ state_attr('camera.xxx', 'data')['statusLed'] }}"

Look at the attribute value (statusLed: false) and the state of the new sensor (True):

Schermata 2021-10-06 alle 17 40 08

@fuatakgun
Copy link
Owner

Yes template sensor is very slow and unreliable, i didn't understand this too.

@SmartM-ui
Copy link
Author

SmartM-ui commented Oct 6, 2021

Yes template sensor is very slow and unreliable, i didn't understand this too.

@fuatakgun
I have a news, I saw that the statusLed sensor of camera.xxx takes a long time to update, while the statusLed sensor of the binary_sensor.xxx_enabled (always created through integration) is updated in real time.

I tried to create the led sensor from the binary sensor, but it doesn't show up in the developer model:

{{state_attr ('binary_sensor.xxx_enabled', 'data') ['statusLed']}}

Do you have any suggestions?

@fuatakgun
Copy link
Owner

Hey before moving forward, i suggest you to create this sensor directly in integration, it is very straightforward, do you have any experience in development? If not i can help you, if you don't want to get into this, having these sensors are fairly simple, one liner in codebase.

@SmartM-ui
Copy link
Author

Hey before moving forward, i suggest you to create this sensor directly in integration, it is very straightforward, do you have any experience in development? If not i can help you, if you don't want to get into this, having these sensors are fairly simple, one liner in codebase.

@fuatakgun If you help me to create the sensors directly from the integration I would be grateful. I'd love to learn

@fuatakgun
Copy link
Owner

Check this line:

("motion_sensor", "Motion Sensor", "motionDetected", None, DEVICE_CLASS_MOTION),

You see there is a list of binary sensors here. Just add all applicable binary sensors here and they will be generated as a real sensor in your machine. After testing out locally, create a push request so we can merge your change into codebase.

You can go ahead and change custom_components/eufy_security/binary_sensor.py and restart your HA to pick up changes and create respective sensors.

@SmartM-ui
Copy link
Author

SmartM-ui commented Oct 6, 2021

Check this line:

("motion_sensor", "Motion Sensor", "motionDetected", None, DEVICE_CLASS_MOTION),

You see there is a list of binary sensors here. Just add all applicable binary sensors here and they will be generated as a real sensor in your machine. After testing out locally, create a push request so we can merge your change into codebase.

You can go ahead and change custom_components/eufy_security/binary_sensor.py and restart your HA to pick up changes and create respective sensors.

I added this line:

INSTRUMENTS = [

         ("status_led", "Status Led", "statusLed", "mdi: led-on", None),
or
        ("status_led", "Status Led", "statusLed", None, DEVICE_CLASS_MOTION),

I restarted Home Assistant and reloaded the integration, but I only ever have 8 entities and the new one doesn't load.

Where did I go wrong?
I made the change directly in my binary_sensor.py file without downloading the 19fe9d9 version as it is the version I use.

I tried to remove motion from binary_sensor.py and it actually removed it from Home Assistant, so the problem is related to the statusLed

@SmartM-ui
Copy link
Author

SmartM-ui commented Oct 6, 2021

Hi @fuatakgun
I added more binary_sensors and this is the result:

         ("autonightvision", "auto Night vision", "autoNightvision", "mdi:weather-night", None),

Binary sensor imported as entity = OK
Status change displayed in real time after starting the service "driver.poll_refresh" = NO

         ("microphone", "Microphone", "microphone", "mdi:microphone", None),

Binary sensor imported as entity = OK
Status change displayed in real time after starting the service "driver.poll_refresh" = OK

         ("speaker", "Speaker", "speaker", "mdi:bullhorn", None),

Binary sensor imported as entity = OK
Status change displayed in real time after starting the service "driver.poll_refresh" = OK

         ("statusled", "Status Led", "statusLed", None, DEVICE_CLASS_MOTION),

Binary sensor imported as entity = NO

@fuatakgun
Copy link
Owner

Hey, it should be ledStatus in our existing version. You can validate the attribute names using state dumper in developer settings page.

@SmartM-ui
Copy link
Author

SmartM-ui commented Oct 6, 2021

Hey, it should be ledStatus in our existing version. You can validate the attribute names using state dumper in developer settings page.

OK, he also sees the led. Thanks

I have entered all the binary sensors available, tomorrow I will check who is able to update in real time after running the service.

Schermata 2021-10-07 alle 01 42 01

If tomorrow you explain to me how to create the push request, after testing the sensors, I will add the request

Good night

@SmartM-ui
Copy link
Author

SmartM-ui commented Oct 7, 2021

Hi @fuatakgun

I realized that actually the "statusLed" sensor exists in your integration and it is the one that is actually updated when I launch the service.

I am attaching screenshots where the two sensors are present (it also results in the binary sensors created by the integration).

Schermata 2021-10-07 alle 01 48 33

At the precise moment, the webcam led was actually off as is evident in "statusLed: false".
The "ledStatus" sensor, on the other hand, always remains on "true"

The problem is that the "statusLed" sensor is not interpreted if inserted into the integration through the binary_sensor.py

Maybe it's a problem with how the name was reported in the integration / add-on?

Further info:

The "statusLed" sensor of the "binary_sensor.salone_led_status" and of the "binary_sensor.salotto_enabled" are updated in real time after running the refresh service.
The "statusLed" sensor of "camera.salotto" is not updated in real time after running the refresh service, but it often takes about 10 minutes to wait.

The "ledStatus" sensor of the binary_sensor and camera.salotto never update and always remain "true"

@fuatakgun
Copy link
Owner

apparently, this is the bug which was resolved in 0.4.0 version of add-on but we are not able to update into that one yet because of p2p live stream problem. If you do not have a direct dependency on p2p live stream, go ahead and update your add on using following this: #59
and stick with statusLed, apparently ledStatus is deprecated

@SmartM-ui
Copy link
Author

apparently, this is the bug which was resolved in 0.4.0 version of add-on but we are not able to update into that one yet because of p2p live stream problem. If you do not have a direct dependency on p2p live stream, go ahead and update your add on using following this: #59 and stick with statusLed, apparently ledStatus is deprecated

Hi @fuatakgun
I have configured the add-on:
Eufy Security WS Addon
Current version: 0.4.2

The "ledStatus" sensor is never displayed both in the camera.salotto and in the binary_sensor.salotto_enabled

The "statusLed" sensor attribute is displayed only after a change from the official app of the status LED

I tried reporting in the binary_sensor.py

("statusled", "Status Led", "statusLed", "mdi: led-on", None),

but the sensor is not created, as was the case with the previous addon

In developer templates / tools, when the sensor is displayed as an attribute after an app change, it is reported correctly

{{state_attr ('room.salotto', 'data') ['statusLed']}}: True

{{state_attr ('binary_sensor.salotto_enabled', 'statusLed')}}: True

Can I perform any other tests?

@SmartM-ui
Copy link
Author

Hi @DivanX10 ,
I wrote about your issue, but then I preferred to report it in mine because it is more relevant to the title and we avoid confusion.

I was looking at how to sync the settings imparted by the eufy app to Home Assistant.

I enabled additional binary sensors (e.g. motion tracking) and, taking a cue from your topic: #71, I created the boolean inputs for the sensors of interest.

However, I have seen that the switches report the correct status only if the data is sent from Home Assistant to the cam.

As a remedy, in addition to your automation I have created two more in order to position the switch as per the eufy app.

In this way the switches, after 10 minutes of waiting provided by the add-on to get the status from the eufy app, you get the correct status of the switch.

Forcing the refresh of the update service
service: eufy_security.send_message
date:
  message: | -
    {
      "messageId": "message_id_do_not_add_value_here",
      "command": "driver.poll_refresh"
    }

you can get the status in real time, without waiting for the 10 minute wait provided by Eufy. (I would like to force the update every time I view the Home Assistant page where the cam switches are present).

In summary, to have the synchronization between Eufy and Home Assistant I set these codes:

input_boolean:
  eufy_camera_salotto_motion_tracking:
    name: eufy_camera_salotto_motion_tracking

automation:
  - id: eufy_motion_tracking_off_binary_sensor_off
    alias: eufy_motion_tracking_off_binary_sensor_off
    description: ''
    mode: single
    trigger:
      - platform: state
        entity_id: binary_sensor.salone_motion_tracking
        from: 'True'
        to: 'False'
    condition: []
    action:
      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.eufy_camera_salotto_motion_tracking

  - id: eufy_motion_tracking_on_binary_sensor_on
    alias: eufy_motion_tracking_on_binary_sensor_on
    description: ''
    mode: single
    trigger:
      - platform: state
        entity_id: binary_sensor.salone_motion_tracking
        from: 'False'
        to: 'True'
    condition: []
    action:
      - service: input_boolean.turn_on
        target:
          entity_id: input_boolean.eufy_camera_salotto_motion_tracking

and your automation which I do not report in full, but which includes the following condition:

          - conditions:
              - condition: trigger
                id: Camera Motion Tracking
            sequence:
              - service: eufy_security.send_message
                date:
                  message: | -
                    {
                      "messageId": "cmdMotionTracking",
                      "command": "device.set_property",
                      "serialNumber": "T8410xxx",
                      "name": "motionTracking",
                      "value":
                         {% - set led = states ("input_boolean.eufy_camera_salotto_motion_tracking")%}
                         {% - if led == 'on'%} true
                         {% else%} false
                         {% endif%}
                    }

Do you have any suggestions to improve it all?

@DivanX10
Copy link

DivanX10 commented Oct 8, 2021

Thank you for sharing the link. I have just started transferring eufi from iobroker to a home assistant, and of course I will take into account all the recommendations of this project and will definitely try your option and unsubscribe. Did I understand correctly that I need to do binary sensors manually so that I have the same list of sensors as you?

These are all the sensors that my home assistant is showing now, but iobroker has all the sensors
image

@SmartM-ui
Copy link
Author

Thank you for sharing the link. I have just started transferring eufi from iobroker to a home assistant, and of course I will take into account all the recommendations of this project and will definitely try your option and unsubscribe. Did I understand correctly that I need to do binary sensors manually so that I have the same list of sensors as you?

These are all the sensors that my home assistant is showing now, but iobroker has all the sensors image

Hi @DivanX10 ,
for the moment you have to manually bring the sensors back into the binary_sensor.py.

This is the list of sensors I have entered in my Home Assistant
Schermata 2021-10-07 alle 01 42 01

I am waiting to know from @fuatakgun how to open a pull request to merge the sensors in the code for all

Thanks again for the help on io-broker!

@DivanX10
Copy link

DivanX10 commented Oct 8, 2021

I added the DEVICE_CLASS_LIGHT class for auto Night vision, although I liked the option ("auto night vision", "auto Night vision", "autonightvision", "mdi:weather-night", None, DEVICE_CLASS_LIGHT) more, but this is a matter of taste, and now to the point

auto Night vision doesn't work for me. and Motion Tracking shows the status True\False.

I understand that you need to create another file switch.py where there will be switches and there is no need to use automation in the home assistant and then the statuses will work correctly

image

from homeassistant.config_entries import ConfigEntry
from homeassistant.components.binary_sensor import (
    DEVICE_CLASS_MOTION,
    DEVICE_CLASS_SOUND,
    DEVICE_CLASS_DOOR,
    DEVICE_CLASS_POWER,
    DEVICE_CLASS_LIGHT
)

from .const import DOMAIN
from .entity import EufySecurityEntity
from .coordinator import EufySecurityDataUpdateCoordinator

_LOGGER: logging.Logger = logging.getLogger(__package__)


async def async_setup_entry(hass, entry, async_add_devices):
    coordinator: EufySecurityDataUpdateCoordinator = hass.data[DOMAIN]

    INSTRUMENTS = [
        ("motion_sensor", "Motion Sensor", "motionDetected", None, DEVICE_CLASS_MOTION),
        ("motion_tracking", "Motion Tracking", "motionTracking", None, DEVICE_CLASS_MOTION),
        ("person_detector_sensor", "Person Detector Sensor", "personDetected", None, DEVICE_CLASS_MOTION),
        ("pet_detector_sensor", "Pet Detector Sensor", "petDetected", None, DEVICE_CLASS_MOTION),
        ("sound_detector_sensor", "Sound Detector Sensor", "soundDetected", None, DEVICE_CLASS_SOUND),
        ("crying_detector_sensor", "Crying Detector Sensor", "cryingDetected", None, DEVICE_CLASS_SOUND),
        ("sensor_open", "Sensor Open", "sensorOpen", None, DEVICE_CLASS_DOOR),
        ("ringing_sensor", "Ringing Sensor", "ringing", "mdi:bell-ring", None),
        ("enabled", "Enabled", "enabled", None, DEVICE_CLASS_POWER),
#        ("autonightvision", "auto Night vision", "autoNightvision", "mdi:weather-night", None, DEVICE_CLASS_LIGHT),
        ("autonightvision", "auto Night vision", "autoNightvision", None, DEVICE_CLASS_LIGHT),
        ("microphone", "Microphone", "microphone", "mdi:microphone", None),
        ("speaker", "Speaker", "speaker", "mdi:bullhorn", None),
#        ("status_led", "Status Led", "statusLed", None, DEVICE_CLASS_LIGHT)
    ]

@DivanX10
Copy link

DivanX10 commented Oct 8, 2021

I didn't look at the camera attributes right away, but as soon as I saw them, I realized that there was no point in editing the file binary_sensor.py , you can create a file and output any sensor.

sensor:
  - platform: template
    sensors:
      camera_hall_led:
        friendly_name: "Камера в коридоре. Status Led"
        value_template: "{{ state_attr('camera.hall', 'data')['ledStatus'] }}"
        icon_template: >-
          {% if state_attr('camera.hall','data')['ledStatus'] == True %}
          mdi:alarm-light-outline
          {% else %}
          mdi:alarm-light-off-outline
          {% endif %}

  - platform: template
    sensors:
      camera_hall_auto_nightvision:
        friendly_name: "Камера в коридоре. Auto Nightvision"
        value_template: "{{ state_attr('camera.hall', 'data')['autoNightvision'] }}"
        icon_template: >-
          {% if state_attr('camera.hall','data')['autoNightvision'] == True %}
          mdi:weather-night
          {% else  %}
          mdi:weather-sunny
          {% endif %}

  - platform: template
    sensors:
      camera_hall_motion_tracking:
        friendly_name: "Камера в коридоре. Motion Tracking"
        value_template: "{{ state_attr('camera.hall', 'data')['motionTracking'] }}"
        icon_template: >-
          {% if state_attr('camera.hall','data')['motionTracking'] == True %}
          mdi:motion-sensor
          {% else  %}
          mdi:motion-sensor-off
          {% endif %}

But I can't get the sensor status in real time by calling the service and driver.poll_refresh. How are you calling the service for a status update? My statuses are updated only after a reboot HA (

service: eufy_security.send_message
data:
  message: |-
    {
      "messageId": "string", 
      "command": "driver.poll_refresh"
    }

@SmartM-ui
Copy link
Author

SmartM-ui commented Oct 8, 2021

Hi @DivanX10 ,
I was also creating the sensors for each individual attribute (#62 (comment)), but actually, putting those lines in the binary_sensor.py is more immediate.

To update the statuses, I use this code:

service: eufy_security.send_message
date:
   message: | -
     {
       "messageId": "message_id_do_not_add_value_here",
       "command": "driver.poll_refresh"
     }

@DivanX10
Copy link

DivanX10 commented Oct 8, 2021

Yes, indeed, the status changes faster when they are in the file binary_sensor.py . Then it would be good for the author to make a file switch.py with a standard set of switches, but in order to be able to add your own switches, for example, the author will indicate all possible switches, but comment them out, and we just need to uncomment the necessary switches

@SmartM-ui
Copy link
Author

@DivanX10
If you are interested, I had also created switches with the service
#63 (comment)

@fuatakgun
Copy link
Owner

service is created to trigger pull from cloud and it is named as force_sync
you can also configure the interval to automatically fetch the data from cloud.

image

@SmartM-ui
Copy link
Author

service is created to trigger pull from cloud and it is named as force_sync you can also configure the interval to automatically fetch the data from cloud.

image

Excellent possibility to choose the scan time!

I can't find a way to automate the action on viewing a particular Home Assistant page.
Do you know which command to give to trigger an atomation on the page change?

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

No branches or pull requests

3 participants