arachnetech / homebridge-mqttthing

A plugin for Homebridge allowing the integration of many different accessory types using MQTT.
Apache License 2.0
466 stars 104 forks source link

use custom topics with codecs #501

Closed FermedePommerieux closed 2 years ago

FermedePommerieux commented 2 years ago

it would be nice to be able to use custom topics, in order to get more sensor/action state in codec

could you allow the use of

config.getCustom?State config.setCustom?State

and not restrict to the "official" topic values for accessories types

FermedePommerieux commented 2 years ago

I found a little solution, with AltSensorState for my securitySystem

I add this to index.js

        // Characteristic.AltSensorState to help detecting triggered state with multiple sensors
        function characteristic_AltSensorState( service ) {
        // additional MQTT subscription instead of set-callback due to correct averaging:
            mqttSubscribe( config.topics.getAltSensorState, 'AltSensorState', function( topic, message ) {
                    // determine whether this is an on or off value
                    let newState = false; // assume off
                    if( isRecvValueOn( message ) ) {
                        newState = true; // received on value so on
                    } else if( !isRecvValueOff( message ) ) {
                        // received value NOT acceptable as 'off' so ignore message
                        return;
                    }

                    // if changed, set
                    if( state[ property ] != newState ) {
                        state[ property ] = newState;
                        propChangedHandler();
                    }
                } );
        }

and this inside the if( configType == "securitySystem" )

            if( config.topics.getStatusTampered ) {
                characteristic_StatusTampered( service );
            }
            if( config.topics.getAltSensorState ) {
                characteristic_AltSensorState( service );
            }
            // todo: SecuritySystemAlarmType

plus some add in config.schema.json

I'll later find a way to add multiple AltSensor[1-9]State

FermedePommerieux commented 2 years ago

here is the index.js patch file

======STARTS HERE===== --- index-1.32.js 2021-11-24 13:00:26.000000000 +0100 +++ index.js 2021-11-24 09:47:32.000000000 +0100 @@ -1516,6 +1516,27 @@ function characteristic_StatusTampered( service ) { booleanCharacteristic( service, 'statusTampered', Characteristic.StatusTampered, null, config.topics.getStatusTampered ); }

======ENDS HERE=====

arachnetech commented 2 years ago

Thanks. I merged your PR, so this should all be available in the latest release.