justme-1968/homebridge-fhem

genericDeviceType "Security System" is shown as simple switch in home app

Closed this issue · 7 comments

Hey there,

in issue #20 you said, that homebridge-fhem supports all service types that can be found in hap-nodejs/lib/gen/HomeKitTypes.js .
On line 2658 I found a service type called "Security system".

/**
 * Service "Security System"
 */

Service.SecuritySystem = function(displayName, subtype) {
  Service.call(this, displayName, '0000007E-0000-1000-8000-0026BB765291', subtype);

  // Required Characteristics
  this.addCharacteristic(Characteristic.SecuritySystemCurrentState);
  this.addCharacteristic(Characteristic.SecuritySystemTargetState);

  // Optional Characteristics
  this.addOptionalCharacteristic(Characteristic.StatusFault);
  this.addOptionalCharacteristic(Characteristic.StatusTampered);
  this.addOptionalCharacteristic(Characteristic.SecuritySystemAlarmType);
  this.addOptionalCharacteristic(Characteristic.Name);
};

inherits(Service.SecuritySystem, Service);

Service.SecuritySystem.UUID = '0000007E-0000-1000-8000-0026BB765291';

According to line 1491 this service can five five states (0 1 2 3 4).

// The value property of SecuritySystemCurrentState must be one of the following:
Characteristic.SecuritySystemCurrentState.STAY_ARM = 0;
Characteristic.SecuritySystemCurrentState.AWAY_ARM = 1;
Characteristic.SecuritySystemCurrentState.NIGHT_ARM = 2;
Characteristic.SecuritySystemCurrentState.DISARMED = 3;
Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED = 4;

So I created a dummy with the attribute genericDeviceType="Security System" and setList="0 1 2 3 4".

First question: Is it right that the states are the numbers? Or are the states the keys (e.g. STAR_ARM)?

Then I restarted homebridge. For some reason this device is then presented as a switch which can only be set on and off.

I then looked at the console output of homebridge and found this error:

ALRM_SYSTEM: service name Security System unknown

Second question: Is there a bug, or did I do something wrong?

This is the jsonlist2 of my dummy device:

{ 
  "Arg":"ALRM_SYSTEM", 
  "Results": [ 
  { 
    "Name":"ALRM_SYSTEM", 
    "PossibleSets":"0 1 2 3 4", 
    "PossibleAttrs":"alias comment:textField-long eventMap group room suppressReading userReadings:textField-long verbose:0,1,2,3,4,5 readingList setList useSetExtensions event-on-change-reading event-on-update-reading event-aggregator event-min-interval stateFormat:textField-long timestamp-on-change-reading alarmDevice:Actor,Sensor alarmSettings cmdIcon devStateIcon devStateStyle genericDeviceType:ignore,switch,outlet,light,blind,thermometer,thermostat,garage,window,lock homebridgeMapping:textField-long icon sortby webCmd widgetOverride userattr", 
    "Internals": { 
      "CFGFN": "", 
      "NAME": "ALRM_SYSTEM", 
      "NR": "101", 
      "STATE": "0", 
      "TYPE": "dummy" 
    }, 
    "Readings": {      "state": { "Value":"0", "Time":"2016-10-04 10:07:16" }    }, 
    "Attributes": { 
      "genericDeviceType": "Security System", 
      "room": "Alarm", 
      "setList": "0 1 2 3 4" 
    } 
  }  ], 
  "totalResultsReturned":1 
} 

yes. you can use all types from HomeKitTypes.js directly.

in your case this would be SecuritySystem (no space) for the service type. this has to go to genericDeviceType.

for the setList in fhem you can use whatever you want and makes sense in the fhem ui as you have to provide a mapping from the fhem values to the homekit values anyway. in values you can (and should) use the defined terms from HomeKitTypes.js as the target. for example for the current state would look something like this:

setList state:stay,away,night,...
homebridgeMapping SecuritySystemCurrentState=state,values=stay:STAY_ARM;away:AWAY_ARM;...

for SecuritySystemTargetState you have to provide the values mapping and also the reverse mapping from the homekit values to the fhem values with the cmds mapping.

important: spaces are a source of problems. try to avoid them.

Thank you very much!

I tried the solution you provided. But it doesn't work yet.

I've set the state to "DISARMED" manually in fhem. But in the home app it is shown in the stay_armed state. When I change the state in the app, a spinner as shown and nothing happens.

The console outputs this error:

ALRM_SYSTEM-state value DISARMED not handled in values

This is my device:

{ 
  "Arg":"ALRM_SYSTEM", 
  "Results": [ 
  { 
    "Name":"ALRM_SYSTEM", 
    "PossibleSets":"setList state:STAY_ARM,AWAY_ARM,NIGHT_ARM,DISARMED,ALARM_TRIGGERED", 
    "PossibleAttrs":"alias comment:textField-long eventMap group room suppressReading userReadings:textField-long verbose:0,1,2,3,4,5 readingList setList useSetExtensions event-on-change-reading event-on-update-reading event-aggregator event-min-interval stateFormat:textField-long timestamp-on-change-reading alarmDevice:Actor,Sensor alarmSettings cmdIcon devStateIcon devStateStyle genericDeviceType:ignore,switch,outlet,light,blind,thermometer,thermostat,garage,window,lock homebridgeMapping:textField-long icon sortby webCmd widgetOverride userattr", 
    "Internals": { 
      "CFGFN": "", 
      "NAME": "ALRM_SYSTEM", 
      "NR": "101", 
      "STATE": "DISARMED", 
      "TYPE": "dummy" 
    }, 
    "Readings": {      "state": { "Value":"DISARMED", "Time":"2016-10-04 11:23:11" }    }, 
    "Attributes": { 
      "genericDeviceType": "SecuritySystem", 
      "homebridgeMapping": "SecuritySystemCurrentState=state,values= STAY_ARM:STAY_ARM; AWAY_ARM:AWAY_ARM;NIGHT_ARM:NIGHT_ARM;DISARMED:DISARMED;ALARM_TRIGGERED:ALARM_TRIGGERED", 
      "room": "Alarm", 
      "setList": "setList state:STAY_ARM,AWAY_ARM,NIGHT_ARM,DISARMED,ALARM_TRIGGERED" 
    } 
  }  ], 
  "totalResultsReturned":1 
} 

i see lots of spaces in the homebridgeMapping :)

@justme-1968 Shoot. You're right.

I fixed it. Now the disarmed state is shown correctly but when I change the state it still shows the spinner and does nothing...

But this time there is no error on the console :(

{ 
  "Arg":"ALRM_SYSTEM", 
  "Results": [ 
  { 
    "Name":"ALRM_SYSTEM", 
    "PossibleSets":"setList state:STAY_ARM,AWAY_ARM,NIGHT_ARM,DISARMED,ALARM_TRIGGERED", 
    "PossibleAttrs":"alias comment:textField-long eventMap group room suppressReading userReadings:textField-long verbose:0,1,2,3,4,5 readingList setList useSetExtensions event-on-change-reading event-on-update-reading event-aggregator event-min-interval stateFormat:textField-long timestamp-on-change-reading alarmDevice:Actor,Sensor alarmSettings cmdIcon devStateIcon devStateStyle genericDeviceType:ignore,switch,outlet,light,blind,thermometer,thermostat,garage,window,lock homebridgeMapping:textField-long icon sortby webCmd widgetOverride userattr", 
    "Internals": { 
      "NAME": "ALRM_SYSTEM", 
      "NR": "66", 
      "STATE": "DISARMED", 
      "TYPE": "dummy" 
    }, 
    "Readings": {      "state": { "Value":"DISARMED", "Time":"2016-10-04 11:23:11" }    }, 
    "Attributes": { 
      "genericDeviceType": "SecuritySystem", 
      "homebridgeMapping": "SecuritySystemCurrentState=state,values=STAY_ARM:STAY_ARM;AWAY_ARM:AWAY_ARM;NIGHT_ARM:NIGHT_ARM;DISARMED:DISARMED;ALARM_TRIGGERED:ALARM_TRIGGERED", 
      "room": "Alarm", 
      "setList": "setList state:STAY_ARM,AWAY_ARM,NIGHT_ARM,DISARMED,ALARM_TRIGGERED" 
    } 
  }  ], 
  "totalResultsReturned":1 
} 

as i said: you also have to map the SecuritySystemTargetState with reading, values and cmds.

some service classes use the same characteristic for both directions, others (mainly the multivalued) use two characteristics and you have to configure both.

Sorry so much, I over read that!

It worked! Thank you very much for being so patient with me!

For any other people struggling with this in the future.
This is my solution:

SecuritySystemCurrentState=state,values=STAY_ARM:STAY_ARM;AWAY_ARM:AWAY_ARM;NIGHT_ARM:NIGHT_ARM;DISARMED:DISARMED;ALARM_TRIGGERED:ALARM_TRIGGERED SecuritySystemTargetState=state,cmds=0:STAY_ARM;1:AWAY_ARM;2:NIGHT_ARM;3:DISARMED;4:ALARM_TRIGGERED,values=STAY_ARM:0;AWAY_ARM:1;NIGHT_ARM:2;DISARMED:3;ALARM_TRIGGERED:4

(attribute homebridgeMapping)