This article describes the cohomology spaces of any Lie algebra containing a Lie algebra of Heisenberg type (whose cohomology was studied by Santharoubane) as an ideal of codimension 1. For instance, the twisted standard filiform Lie algebras are of this kind. We give an explicit formula for the Betti numbers of this Lie algebra, and use this to describe new families of algebras whose Betti numbers do not behave unimodally.