twrecked / hass-aarlo

Asynchronous Arlo Component for Home Assistant
GNU Lesser General Public License v3.0
397 stars 79 forks source link

Impossible to change surveillance mode in automation #836

Open Diplo95 opened 1 year ago

Diplo95 commented 1 year ago

I use both Alarmo and Aarlo integrations. My aim is to sync between the both when I change the surveillance mode. So, as I created a package to deal with all my camera stuff, I tried this code :

aarlo:
  username: "*******"
  password: "*******"
  refresh_devices_every: 2
  stream_timeout: 120
  mqtt_host: mqtt-cluster-z1.arloxcld.com
  backend: sse
  tfa_source: imap
  tfa_type: email
  tfa_host: imap.gmail.com
  tfa_username: "*******"
  tfa_password: "*******"

camera:
  - platform: aarlo

alarm_control_panel:
  - platform: aarlo
    away_mode_name: armed
    home_mode_name: home
    night_mode_name: night
    disarmed_mode_name: disarmed
    trigger_time: 30
    alarm_volume: 8

automation:
  - id: Sync_Aarlo_Alarmo
    alias: 'Arlo armed quand personne a la maison'
    trigger:
      platform: state
      entity_id: alarm_control_panel.alarmo
      to: "armed_away"
    action:
      service: aarlo.alarm_set_mode
      data:
        entity_id: alarm_control_panel.aarlo_location_roquettes      
        mode: armed````` 

But I can't make it work. I know the trigger is good because I tested it with a notification on my phone. But there is no way I managed to change the surveillance mode in Arlo.

Here are the log :

Cette erreur provient d'une intégration personnalisée

Logger: pyaarlo
Source: custom_components/aarlo/pyaarlo/__init__.py:722
Integration: Arlo Camera Support (documentation, issues)
First occurred: 23:04:12 (1 occurrences)
Last logged: 23:04:12

error in response={'success': False, 'data': {'error': '2001', 'message': "The request's content is invalid.", 'reason': 'Invalid mode'}}
Logger: homeassistant.components.automation.arlo_armed_quand_personne_a_la_maison
Source: helpers/script.py:468
Integration: Automatisation (documentation, issues)
First occurred: 23:04:12 (1 occurrences)
Last logged: 23:04:12

Arlo armed quand personne a la maison: Error executing script. Unexpected error for call_service at pos 1: 'NoneType' object has no attribute 'get'
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 704, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/aarlo/alarm_control_panel.py", line 171, in async_service_callback
    await hass.async_add_executor_job(service_callback, call)
  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/aarlo/alarm_control_panel.py", line 167, in service_callback
    alarm_mode_service(hass, call)
  File "/config/custom_components/aarlo/alarm_control_panel.py", line 616, in alarm_mode_service
    get_entity_from_domain(hass, DOMAIN, entity_id).set_mode_in_ha(mode)
  File "/config/custom_components/aarlo/alarm_control_panel.py", line 532, in set_mode_in_ha
    self._location.mode = mode
    ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/aarlo/pyaarlo/location.py", line 143, in mode
    mode_revision = data.get("revision")
                    ^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'

and

Logger: homeassistant.components.automation.arlo_armed_quand_personne_a_la_maison
Source: components/automation/__init__.py:655
Integration: Automatisation (documentation, issues)
First occurred: 23:04:12 (1 occurrences)
Last logged: 23:04:12

While executing automation automation.arlo_armed_quand_personne_a_la_maison
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 655, in async_trigger
    await self.action_script.async_run(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1578, in async_run
    return await asyncio.shield(run.async_run())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 420, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 470, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 493, in _handle_exception
    raise exception
  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 704, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/aarlo/alarm_control_panel.py", line 171, in async_service_callback
    await hass.async_add_executor_job(service_callback, call)
  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/aarlo/alarm_control_panel.py", line 167, in service_callback
    alarm_mode_service(hass, call)
  File "/config/custom_components/aarlo/alarm_control_panel.py", line 616, in alarm_mode_service
    get_entity_from_domain(hass, DOMAIN, entity_id).set_mode_in_ha(mode)
  File "/config/custom_components/aarlo/alarm_control_panel.py", line 532, in set_mode_in_ha
    self._location.mode = mode
    ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/aarlo/pyaarlo/location.py", line 143, in mode
    mode_revision = data.get("revision")
                    ^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'

Any idea ? Thx

twrecked commented 1 year ago

I'll take a look a the code. The problem is I don't have an useful account with locations enabled, my main accounts are still using the old base station set up. Can you:

Diplo95 commented 1 year ago

Hi, I activated the standard alarm_control dashboard, and still had the issue. Here is the log : Aarlo_debug 20231114.txt

Thx for the help

twrecked commented 1 year ago

The logs are showing these 3 modes for your alarm bases: armAway, armHome, and standby.

Try sending armAway instead of armed as part of the automation.

You should also be able to put these in as your alarm modes and the standard alarm_control_panel services will work. (Something like this):

alarm_control_panel:
  - platform: aarlo
    away_mode_name: armAway
    home_mode_name: armHome
    night_mode_name: night
    disarmed_mode_name: standby
    trigger_time: 30
    alarm_volume: 8
Diplo95 commented 1 year ago

Thank you : if I use armAway in my automation, it does the trick.

But I don't understand why. Here is a screenshot of the values of alarm_control_panel.aarlo_user_location_home

Capture d’écran du 2023-11-15 19-52-38

As you can see, state is armed_away

So, I'll try now with Alarmo. And I've got a subsidiary question : if you can't relie on the info in the state page, where can you find the name of the states otherwise than in the the logs ?

twrecked commented 1 year ago

My bad, it's been a while since I looked at this code. After looking:

The last one is an oversight/bug, I'll modify the code to map the Home Assistant states to the Aarlo location ones. For now you'll need to use the native Arlo values.

I hope that makes sense.