Error in automations for cpu fan

Hi.I tried to configure the fan control of my raspberry.
My automation section is:

- id: fan_cpu_on
  alias: "Fan CPU On"
  trigger:
  - platform: numeric_state
    entity_id: sensor.raspcpu
    above: 47.0
    condition:
      condition: time
      after: '7:00:00'
      before: '22:00:00'
    action:
    - service: switch.turn_on
      entity_id: switch.fan_cpu
      
- id: fan_cpu_off
  alias: "Fan CPU off"
  trigger:
    platform: numeric_state
    entity_id: sensor.raspcpu
    below: 45.0
    action:
    - service: switch.turn_off
      entity_id: switch.fan_cpu

My switch section is:

- platform: rpi_gpio
  ports:
    18: Fan CPU

With this configuration I get this error:

Invalid config for [automation]: [condition] is an invalid option for [automation]. Check: automation->trigger->0->condition. (See /config/configuration.yaml, line 83). Please check the docs at https://home-assistant.io/integrations/automation/
Invalid config for [automation]: [action] is an invalid option for [automation]. Check: automation->trigger->0->action. (See /config/configuration.yaml, line 83). Please check the docs at https://home-assistant.io/integrations/automation/

I use Hass.io.
I need help. Thanks

You need to fix your indentation. This should work:

- id: fan_cpu_on
  alias: "Fan CPU On"
  trigger:
    platform: numeric_state
    entity_id: sensor.raspcpu
    above: 47.0
  condition:
    condition: time
    after: '7:00:00'
    before: '22:00:00'
  action:
    service: switch.turn_on
    entity_id: switch.fan_cpu
      
- id: fan_cpu_off
  alias: "Fan CPU off"
  trigger:
    platform: numeric_state
    entity_id: sensor.raspcpu
    below: 45.0
  action:
    service: switch.turn_off
    entity_id: switch.fan_cpu

Yep, that should fix it. OP, note that trigger, condition, and action are all aligned with each other.

Thanks to fanaticDavid, Tediore. Now I get no error in configuration test . I’m waiting for a final test tonight.
I’m trying to learn how to write a yaml file. I feel a little dummy because I still couldn’t get the logic under control. Can you recommend me a good read? Many thanks

I had to use:
sensor.cpu_temperature

instead of sensor.raspcpu

Sorry, but why was it necessary to reply to my post? All I did was help someone out with their automation, and the error was due to bad indentation, not an incorrect sensor name. This issue may not have been marked as resolved, but it is…and it’s over a year old.

Sorry David

I reply because I used your example. But my device did not recognize the raspcpu sensor.

sensor.cpu_temperature works for me

I just wanted to help