lawtancool / pyControl4

Python 3 asyncio package for interacting with Control4 systems
https://lawtancool.github.io/pyControl4/
Apache License 2.0
38 stars 16 forks source link

Adding device integrations #16

Open lawtancool opened 2 years ago

lawtancool commented 2 years ago

This issue is for discussion of efforts to add more device integrations to pyControl4/Home Assistant.

lawtancool commented 2 years ago

@Xorso I am currently working on an integration for alarm_control_panel and binary_sensor (for alarm system zones like doors, windows, motion).

Please let me know what Control4 devices you have and are willing to work on.

lawtancool commented 2 years ago

Another idea I had was to use the electrical power-related extra device attributes to create power consumption sensors in Home Assistant, so that we can use the new energy dashboard to track home lighting power usage.

This would, however, create a lot of sensor entities, especially for users with a lot of lights. Perhaps the sensor entities would have to be disabled by default. image

mellis commented 2 years ago

I also have an alarm system with some door and window sensors and a motion sensor (if you want any help testing or otherwise). Oh, and a door lock.

Additionally I have some thermostats (Sensibo ones that have a direct HA integration but also some zigbee/control4 line voltage ones that control some small baseboard heaters).

Xesyliad commented 2 years ago

While I'm not a coder, I have a Control4 system that I can help with testing on. The main feature I'm looking for is the relays built into the EA3 that are used to switch garage doors, or sense reed switch states, etc.

lawtancool commented 2 years ago

Hi everyone!

The HACS integration https://github.com/lawtancool/hass-control4 has just been updated with alarm_control_panel and binary_sensor support. Please update and let me know how it goes.

mellis commented 2 years ago

My alarm system showed up but I can’t seem to control it at all and it doesn’t seem to detect the armed state properly (stays disarmed even when I tried arming it from control4).

I don’t see any of the door/window reed switch sensors or the motion sensor at all.

Let me know if there is anything in particular that would be helpful. I probably won’t have time to dig into myself until at least the weekend.

Xesyliad commented 2 years ago

Are the binary sensors the relays in the EA? As far as I can tell nothing has changed after the update for me.

lawtancool commented 2 years ago

@mellis Please try updating to HACS integration 1.1.1, then follow the new instructions in the README: https://github.com/lawtancool/hass-control4#additional-configuration-required-for-alarm-control-panel

I'm not sure what's going on with the binary sensors on your system - was there anything in the logs? If not, I'll make an update so that the logs print out some useful info for debugging this.

@Xesyliad The binary sensors are for contact/motion sensors from an alarm system. Relays aren't supported yet.

mellis commented 2 years ago

@lawtancool so I attempted to configure it but it doesn’t seem to be detecting the state properly still and can’t seem to arm it. I’m guessing I used the wrong state names, do you know how I can get the correct ones? This information isn’t available through the C4 API?

I can disarm the system now though which is progress :).

I can probably fine some time to dig into it myself as well in the next few days I think.

lawtancool commented 2 years ago

@mellis You can get the state names by trying to arm your system through the Control4 app. Type them into the config flow exactly as they appear in the app (case-sensitive, don't include an extra space on the end).

The Control4 API does have a way to get a list of the state names, but doesn't tell us how they correspond to the Home Assistant states (ex. Stay in Control4 = Armed Home in HA). I'll see if I can make it so that there's a drop-down in the config flow so the user can choose from the list that Control4 gives us. Screenshot_20220115-102116.png

mellis commented 2 years ago

Hmm okay, I tried updating the different state names again. I wasn't sure which to use for the last one, I also tried leaving it blank.

image image

After I did this I can "Arm Night" from the HA dashboard and it does correctly change the alarm systems state, however that isn't reflected in HA. Similarly if I change the state from Control4 it also doesn't see the state change.

I did try reloading the integration and it then changed to an "unknown" armed state. I was then able to disarm it from HA, which did work but again the armed/disarmed state in HA did not update. I didn't notice anything in the log from the C4 integration.

lawtancool commented 2 years ago

@mellis Can you send a screenshot of Home Assistant -> Developer Tools -> States so I can see the extra state attributes of your alarm control panel?

mellis commented 2 years ago

@lawtancool here's what it looks like both disarmed and in night mode.

image image

lawtancool commented 2 years ago

@mellis Thanks for the screenshots! Please update to HACS integration version 1.1.5, which should solve those issues. After you update, please delete the Control4 integration and set it up again if you encounter any errors.

It also adds a config flow field for "arm vacation mode name", so you can have all five of your alarm arming modes in HA.

Also, I noticed that your system has code_required_to_arm: false. Does your system actually arm without a code when you do it through the Control4 app? If so, I'll add some handling for that in Home Assistant. (Right now, its hardcoded to require code to arm in HA)

mellis commented 2 years ago

@lawtancool Yeah, my system can be armed without the code.

mellis commented 2 years ago

Seeing some errors in the log now from the integration after updating.

Source: custom_components/control4/alarm_control_panel.py:351 
Integration: Alarm control panel (documentation, issues) 
First occurred: 4:53:22 PM (2 occurrences) 
Last logged: 4:53:22 PM

Error adding entities for domain alarm_control_panel with platform control4
Error while setting up control4 platform for alarm_control_panel
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 523, in _async_add_entity
    supported_features=entity.supported_features,
  File "/config/custom_components/control4/alarm_control_panel.py", line 351, in supported_features
    if self.entry_data[CONF_ALARM_VACATION_MODE] is not None:
KeyError: 'alarm_vacation_mode'

One about a binary sensor too.


Logger: homeassistant.components.binary_sensor
Source: custom_components/control4/__init__.py:137 
Integration: Binary sensor (documentation, issues) 
First occurred: 4:53:21 PM (1 occurrences) 
Last logged: 4:53:21 PM

Error while setting up control4 platform for binary_sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/control4/binary_sensor.py", line 106, in async_setup_entry
    items_of_category = await get_items_of_category(hass, entry, CONTROL4_CATEGORY)
  File "/config/custom_components/control4/__init__.py", line 137, in get_items_of_category
    return_list = await director.getAllItemsByCategory(category)
  File "/usr/local/lib/python3.9/site-packages/pyControl4/director.py", line 112, in getAllItemsByCategory
    return_list = await self.sendGetRequest(
  File "/usr/local/lib/python3.9/site-packages/pyControl4/director.py", line 63, in sendGetRequest
    await checkResponseForError(await resp.text())
  File "/usr/local/lib/python3.9/site-packages/pyControl4/error_handling.py", line 112, in checkResponseForError
    if dictionary["details"] in DIRECTOR_ERROR_DETAILS:
KeyError: 'details'
lawtancool commented 2 years ago

@mellis I made a small mistake, please update to version 1.1.6. That should fix the alarm control panel. If you continue to have issues, please delete the Control4 configuration entry and set it up again.

I'm not really sure what's going on with your binary sensors, as I've never seen that before on my system. I'll look into it and maybe push a version with more debug output so I can fix that.

lawtancool commented 2 years ago

@mellis Please update to version 1.1.7. I've improved the alarm config flow to use dropdowns to set the alarm state names. These state names are pulled from the Control4 API, so it should help make it easier to set up.

mellis commented 2 years ago

@lawtancool updated, this seems better. I have noticed it still shows the stated as "unknown" (but armed) when I switch it to the night mode. I haven't tested any of the other modes yet.

lawtancool commented 2 years ago

@mellis You might need to delete the Control4 config entry and set it up again - all the updates might have messed up the configuration data.

image

I'm not sure what you mean by "unknown" (but armed)?

mellis commented 2 years ago

@lawtancool I tried deleting it and re-adding but it doesn't seem to have helped. Here's what I mean by armed but having a state "unknown"

image

image

lawtancool commented 2 years ago

@mellis The integration detects the arm state by comparing the ARMED_TYPE string to the strings stored in the config flow. It looks like your Control4 system is reporting different names for the ARMED_TYPEs than the names that appear in the Control4 app.

Can you send a screenshot of the drop down options you see in the config flow dialog? It would also be nice to know what the value of ARMED_TYPE becomes when you use each arming mode. (ex. "Instant Stay" = "Night" ARMED_TYPE)

Also, are you able to arm the alarm from Home Assistant, or are you making the state changes through the Control4 app?

If this issue persists, I might need to revert the drop down UI to a text entry field, so that the user can manually arm their system in each mode to figure out what ARMED_TYPE string corresponds to each mode, and enter their findings into the config flow.

mellis commented 2 years ago

@mellis The integration detects the arm state by comparing the ARMED_TYPE string to the strings stored in the config flow. It looks like your Control4 system is reporting different names for the ARMED_TYPEs than the names that appear in the Control4 app.

Yeah, that was what I thought after peaking around the code a bit.

Can you send a screenshot of the drop down options you see in the config flow dialog? It would also be nice to know what the value of ARMED_TYPE becomes when you use each arming mode. (ex. "Instant Stay" = "Night" ARMED_TYPE)

I dropped one earlier in this comment.

I'll try and record the state of the entity for each arming type in control4 when I get a chance. Will have to be when no one else is home for some of them so I don't accidentally trigger it 😅.

Also, are you able to arm the alarm from Home Assistant, or are you making the state changes through the Control4 app?

Yup, after I set the config to the menu names I was able to arm the system from home assistant. It does display the away state correctly as well I happened to notice, so that one likely aligns with the menu option. I think it's mostly the night/stay modes that are different but I'll go through them all to check.

I wonder if this is something specific to my setup or if this is something that is controllable with the dealer software 🤔.

mellis commented 2 years ago

@lawtancool Okay I got a chance to try every alarm state. I captured the alarm panels state from the developer section of HA in each state as well as the exit delay states. I was asked for the code before entering some of the states (I noted which).

Beginning in the "Disarmed" state

code_format: number
changed_by: null
code_arm_required: true
HOME_STATE: 0
AWAY_STATE: 0
DISARMED_STATE: 1
ALARM_STATE: 0
DISPLAY_TEXT: Jan 23, 2022  10:31 AM
TROUBLE_TEXT: ''
IS_ACTIVE: 1
PARTITION_STATE: DISARMED_READY
DELAY_TIME_TOTAL: 30
DELAY_TIME_REMAINING: 30
OPEN_ZONE_COUNT: 0
ALARM_TYPE: ''
ARMED_TYPE: ''
LAST_EMERGENCY: ''
LAST_ARM_FAILED: NA
item id: 65
parent item id: 63
zone_state:
  '1':
    id: 1
    is_open: false
    is_bypassed: false
  '2':
    id: 2
    is_open: false
    is_bypassed: false
  '3':
    id: 3
    is_open: false
    is_bypassed: false
ENABLED: true
CODE_REQUIRED_TO_CLEAR: true
CODE_REQUIRED_TO_ARM: false
SILENT: false
interface_id: ''
friendly_name: Partition 1
supported_features: 7

Began "Stay with no entry delay" (asked for code). Began exit delay of 120s

code_format: number
changed_by: null
code_arm_required: true
HOME_STATE: 0
AWAY_STATE: 0
DISARMED_STATE: 1
ALARM_STATE: 0
DISPLAY_TEXT: Jan 23, 2022  10:31 AM
TROUBLE_TEXT: ''
IS_ACTIVE: 1
PARTITION_STATE: EXIT_DELAY
DELAY_TIME_TOTAL: 120
DELAY_TIME_REMAINING: 120
OPEN_ZONE_COUNT: 0
ALARM_TYPE: ''
ARMED_TYPE: ''
LAST_EMERGENCY: ''
LAST_ARM_FAILED: NA
item id: 65
parent item id: 63
zone_state:
  '1':
    id: 1
    is_open: false
    is_bypassed: false
  '2':
    id: 2
    is_open: false
    is_bypassed: false
  '3':
    id: 3
    is_open: false
    is_bypassed: false
ENABLED: true
CODE_REQUIRED_TO_CLEAR: true
CODE_REQUIRED_TO_ARM: false
SILENT: false
interface_id: c4-9AC1C0B1-BD84-4645-B5E8-8FC94209294B
action: KEYPAD
friendly_name: Partition 1
supported_features: 7

After exit delay countdown, Control4 state read "Armed Night".

code_format: number
changed_by: null
code_arm_required: true
HOME_STATE: 0
AWAY_STATE: 0
DISARMED_STATE: 1
ALARM_STATE: 0
DISPLAY_TEXT: Jan 23, 2022  10:35 AM
TROUBLE_TEXT: ''
IS_ACTIVE: 1
PARTITION_STATE: ARMED
DELAY_TIME_TOTAL: 120
DELAY_TIME_REMAINING: 10
OPEN_ZONE_COUNT: 0
ALARM_TYPE: ''
ARMED_TYPE: Night
LAST_EMERGENCY: ''
LAST_ARM_FAILED: NA
item id: 65
parent item id: 63
zone_state:
  '1':
    id: 1
    is_open: false
    is_bypassed: true
  '2':
    id: 2
    is_open: false
    is_bypassed: false
  '3':
    id: 3
    is_open: false
    is_bypassed: false
ENABLED: true
CODE_REQUIRED_TO_CLEAR: true
CODE_REQUIRED_TO_ARM: false
SILENT: false
interface_id: c4-9AC1C0B1-BD84-4645-B5E8-8FC94209294B
action: KEYPAD
friendly_name: Partition 1
supported_features: 7

Instant Stay

code_format: number
changed_by: null
code_arm_required: true
HOME_STATE: 0
AWAY_STATE: 0
DISARMED_STATE: 1
ALARM_STATE: 0
DISPLAY_TEXT: Jan 23, 2022  10:35 AM
TROUBLE_TEXT: ''
IS_ACTIVE: 1
PARTITION_STATE: ARMED
DELAY_TIME_TOTAL: 120
DELAY_TIME_REMAINING: 10
OPEN_ZONE_COUNT: 0
ALARM_TYPE: ''
ARMED_TYPE: Night
LAST_EMERGENCY: ''
LAST_ARM_FAILED: NA
item id: 65
parent item id: 63
zone_state:
  '1':
    id: 1
    is_open: false
    is_bypassed: true
  '2':
    id: 2
    is_open: false
    is_bypassed: false
  '3':
    id: 3
    is_open: false
    is_bypassed: false
ENABLED: true
CODE_REQUIRED_TO_CLEAR: true
CODE_REQUIRED_TO_ARM: false
SILENT: false
interface_id: c4-9AC1C0B1-BD84-4645-B5E8-8FC94209294B
action: KEYPAD
friendly_name: Partition 1
supported_features: 7

No entry delay (asked for code before arming). Began 120s countdown.

code_format: number
changed_by: null
code_arm_required: true
HOME_STATE: 0
AWAY_STATE: 0
DISARMED_STATE: 1
ALARM_STATE: 0
DISPLAY_TEXT: Jan 23, 2022  10:35 AM
TROUBLE_TEXT: ''
IS_ACTIVE: 1
PARTITION_STATE: EXIT_DELAY
DELAY_TIME_TOTAL: 120
DELAY_TIME_REMAINING: 120
OPEN_ZONE_COUNT: 0
ALARM_TYPE: ''
ARMED_TYPE: ''
LAST_EMERGENCY: ''
LAST_ARM_FAILED: NA
item id: 65
parent item id: 63
zone_state:
  '1':
    id: 1
    is_open: false
    is_bypassed: false
  '2':
    id: 2
    is_open: false
    is_bypassed: false
  '3':
    id: 3
    is_open: false
    is_bypassed: false
ENABLED: true
CODE_REQUIRED_TO_CLEAR: true
CODE_REQUIRED_TO_ARM: false
SILENT: false
interface_id: c4-9AC1C0B1-BD84-4645-B5E8-8FC94209294B
action: KEYPAD
friendly_name: Partition 1
supported_features: 7

After exit delay countdown, Control4 state read "Armed Night"

code_format: number
changed_by: null
code_arm_required: true
HOME_STATE: 0
AWAY_STATE: 0
DISARMED_STATE: 1
ALARM_STATE: 0
DISPLAY_TEXT: Jan 23, 2022  10:39 AM
TROUBLE_TEXT: ''
IS_ACTIVE: 1
PARTITION_STATE: ARMED
DELAY_TIME_TOTAL: 120
DELAY_TIME_REMAINING: 10
OPEN_ZONE_COUNT: 0
ALARM_TYPE: ''
ARMED_TYPE: Night
LAST_EMERGENCY: ''
LAST_ARM_FAILED: NA
item id: 65
parent item id: 63
zone_state:
  '1':
    id: 1
    is_open: false
    is_bypassed: true
  '2':
    id: 2
    is_open: false
    is_bypassed: false
  '3':
    id: 3
    is_open: false
    is_bypassed: false
ENABLED: true
CODE_REQUIRED_TO_CLEAR: true
CODE_REQUIRED_TO_ARM: false
SILENT: false
interface_id: c4-9AC1C0B1-BD84-4645-B5E8-8FC94209294B
action: KEYPAD
friendly_name: Partition 1
supported_features: 7

Away. Began 60s countdown.

code_format: number
changed_by: null
code_arm_required: true
HOME_STATE: 0
AWAY_STATE: 0
DISARMED_STATE: 1
ALARM_STATE: 0
DISPLAY_TEXT: Jan 23, 2022  10:39 AM
TROUBLE_TEXT: ''
IS_ACTIVE: 1
PARTITION_STATE: EXIT_DELAY
DELAY_TIME_TOTAL: 60
DELAY_TIME_REMAINING: 60
OPEN_ZONE_COUNT: 0
ALARM_TYPE: ''
ARMED_TYPE: ''
LAST_EMERGENCY: ''
LAST_ARM_FAILED: NA
item id: 65
parent item id: 63
zone_state:
  '1':
    id: 1
    is_open: false
    is_bypassed: false
  '2':
    id: 2
    is_open: false
    is_bypassed: false
  '3':
    id: 3
    is_open: false
    is_bypassed: false
ENABLED: true
CODE_REQUIRED_TO_CLEAR: true
CODE_REQUIRED_TO_ARM: false
SILENT: false
interface_id: c4-9AC1C0B1-BD84-4645-B5E8-8FC94209294B
action: KEYPAD
friendly_name: Partition 1
supported_features: 7

After 60s countdown, Control4 state read "Armed Away"

code_format: number
changed_by: null
code_arm_required: true
HOME_STATE: 0
AWAY_STATE: 0
DISARMED_STATE: 1
ALARM_STATE: 0
DISPLAY_TEXT: Jan 23, 2022  10:39 AM
TROUBLE_TEXT: ''
IS_ACTIVE: 1
PARTITION_STATE: ARMED
DELAY_TIME_TOTAL: 60
DELAY_TIME_REMAINING: 10
OPEN_ZONE_COUNT: 0
ALARM_TYPE: ''
ARMED_TYPE: Away
LAST_EMERGENCY: ''
LAST_ARM_FAILED: NA
item id: 65
parent item id: 63
zone_state:
  '1':
    id: 1
    is_open: false
    is_bypassed: false
  '2':
    id: 2
    is_open: false
    is_bypassed: false
  '3':
    id: 3
    is_open: false
    is_bypassed: false
ENABLED: true
CODE_REQUIRED_TO_CLEAR: true
CODE_REQUIRED_TO_ARM: false
SILENT: false
interface_id: c4-9AC1C0B1-BD84-4645-B5E8-8FC94209294B
action: KEYPAD
friendly_name: Partition 1
supported_features: 7

Stay, began 120s countdown

code_format: number
changed_by: null
code_arm_required: true
HOME_STATE: 0
AWAY_STATE: 0
DISARMED_STATE: 1
ALARM_STATE: 0
DISPLAY_TEXT: Jan 23, 2022  10:39 AM
TROUBLE_TEXT: ''
IS_ACTIVE: 1
PARTITION_STATE: EXIT_DELAY
DELAY_TIME_TOTAL: 120
DELAY_TIME_REMAINING: 120
OPEN_ZONE_COUNT: 0
ALARM_TYPE: ''
ARMED_TYPE: ''
LAST_EMERGENCY: ''
LAST_ARM_FAILED: NA
item id: 65
parent item id: 63
zone_state:
  '1':
    id: 1
    is_open: false
    is_bypassed: false
  '2':
    id: 2
    is_open: false
    is_bypassed: false
  '3':
    id: 3
    is_open: false
    is_bypassed: false
ENABLED: true
CODE_REQUIRED_TO_CLEAR: true
CODE_REQUIRED_TO_ARM: false
SILENT: false
interface_id: c4-9AC1C0B1-BD84-4645-B5E8-8FC94209294B
action: KEYPAD
friendly_name: Partition 1
supported_features: 7

After 120s countdown, Control4 state read "Armed Night"

code_format: number
changed_by: null
code_arm_required: true
HOME_STATE: 0
AWAY_STATE: 0
DISARMED_STATE: 1
ALARM_STATE: 0
DISPLAY_TEXT: Jan 23, 2022  10:43 AM
TROUBLE_TEXT: ''
IS_ACTIVE: 1
PARTITION_STATE: ARMED
DELAY_TIME_TOTAL: 120
DELAY_TIME_REMAINING: 10
OPEN_ZONE_COUNT: 0
ALARM_TYPE: ''
ARMED_TYPE: Night
LAST_EMERGENCY: ''
LAST_ARM_FAILED: NA
item id: 65
parent item id: 63
zone_state:
  '1':
    id: 1
    is_open: false
    is_bypassed: true
  '2':
    id: 2
    is_open: false
    is_bypassed: false
  '3':
    id: 3
    is_open: false
    is_bypassed: false
ENABLED: true
CODE_REQUIRED_TO_CLEAR: true
CODE_REQUIRED_TO_ARM: false
SILENT: false
interface_id: c4-9AC1C0B1-BD84-4645-B5E8-8FC94209294B
action: KEYPAD
friendly_name: Partition 1
supported_features: 7
Xesyliad commented 2 years ago

Hi, will there be any ongoing feature development on pyControl4 at all? There hasn't been any activity for quite a while.

gadgetbazza commented 2 years ago

Hi, just to add another vote for extra C4 functionality. The light power usage data (whilst extensive) would be great for me. I have around 50 lighting circuits! Some of my lighting circuits are used to turn other devices on/off using a C4 non dimming lighting module as these can run devices up to 16A per pair of outputs. As such, I have 2 external garden heaters and a pool pump setup on these outputs. In C4 they have been configured to something other than a light so that they appear as a heater icon and pump icon, but they are in effect exactly the same as the lighting circuits in the same module.

Im using the official C4 integration currently and these "other" switched devices are not shown, but all the lights from the same modules are. Is there a way that they can still be imported?

Lastly, being able to trigger the relays for things like gates / garage doors would be a real bonus too.