This will give you a list of local databases that are not in an AG, or where the local server is the AG primary...
select name from sys.databases where database_id not in (select database_id from sys.dm_hadr_database_replica_states)
union all
select name from sys.databases where database_id in (select database_id from sys.dm_hadr_availability_replica_states where is_local = 1)