Dynamic Hostgroups?

I try to create online and offline hostgroups this way:

object HostGroup "online_hosts" {
    display_name = "Online Hosts"
    assign where host.state == 1
}
object HostGroup "offline_hosts" {
    display_name = "Offline Hosts"
    assign where host.state == 0
}

But why isn’t this working?
Quering https://localhost:5665/v1/objects/hosts/game?&pretty=1 shows me a “state”:1 condition. Or is it “another” variable than host.state?

How can this be done?

As stated here it is not possible to use host vars or states inside hostgroups, since hostgroups are generated via config reload.

But you can implement dashboards in icingaweb2 (monitoring module) that feature such a behaviour.
(https://youricinga/icingaweb2/monitoring/list/hosts?host_poblem=0)

(https://youricinga/icingaweb2/monitoring/list/hosts?host_poblem=1)