How to only read a sensor at a specific time

Yes, I have exactly whats below…

globals:
  - id: first_read
    type: boolean
    initial_value: 'true'

time:
  # time based on Home Assistant time
  id: ha_time
  platform: homeassistant
  timezone: Australia/Sydney


sensor:
  - id: water_tank
    platform: ultrasonic
    trigger_pin: D1
    echo_pin: D4
    name: Tank Sensor
    filters:
      lambda: |-
        auto now = id(ha_time).now(); // local time
        if ((now.hour >= 22 && now.hour < 6) || id(first_read)) return x;
        else return id(water_tank).state;
        id(first_read) = false;

You can see where I uploaded the new code (around 3pm) it has effected the frequency of readings but still every minute or so…

Actually, after looking at this history data this isnt going to solve my problem anyway…
Back to the drawing board, sorry…

Looking at that data graph, what you might want to do is have a statistics sensor that can hold various statistical properties of a given sensor or binary_sensor over a given amount of time. You could, say, have a sensor that held the state of the average value of water tank sensor over the past 12 or 24 hours. Is that useful?

Ok so the filter will not affect the sample rate just the reported value. The type in globals should be bool not boolean I believe.

Average could work, yes.

I tried bool but same results, both compile with no errors.