Condition formating, numeric state

Hi, I am fairly new to HA and trying to build my very first automation here. Sadly i’m getting stuck and cant seem to find the right syntax. Well, I guess its a syntax thing.

- id: '1003'
  alias: licht gang aan bij beweging gang MAX
  trigger:
  - entity_id: input_boolean.beweging_gang
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: numeric state
    above: 300
    below: 1000
    device_id: 'sensor.illumination_286c07fa2477'
  action:
  -  service: light.turn_on
     entity_id: light.gang
     data:
       brightness_pct: 90

When I comment out the whole condition its works fine. Any suggestions would be very welcome. Probably something stupid…

The logs:

Invalid config for [automation]: expected a dictionary @ data['condition'][0]. Got None
extra keys not allowed @ data['above']. Got None
extra keys not allowed @ data['below']. Got None
extra keys not allowed @ data['device_id']. Got None. (See /config/configuration.yaml, line 73). Please check the docs at https://home-assistant.io/components/automation/

From the documentation for a numeric-state condition:

If both below and above are specified, both tests have to pass.

My mistake! I misread your condition.

@123 thanks. The current value is 209lx, so i would say it would not pass, but still valid test

Obviously im totally oblivious for something here.

The problem is device_id. It should be entity_id.

1 Like

Great, changed that one. Code is now:

- id: '1003'
  alias: licht gang aan bij beweging gang MAX
  trigger:
  - entity_id: input_boolean.beweging_gang
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: numeric state
    entity_id: sensor.illumination_286c07fa2477
    above: 300
    below: 1000
  action:
  -  service: light.turn_on
     entity_id: light.gang
     data:
       brightness_pct: 90

Still getting errors:

Invalid config for [automation]: not a valid value for dictionary value @ data['condition'][0]['condition']. Got None. (See /config/configuration.yaml, line 73). Please check the docs at https://home-assistant.io/components/automation/

line 73 in CONFIGURATION.YAML is:
group: !include groups.yaml

Looks like the value of the sensor can not be retrieved?

You have a space in numeric_state, instead of an underscore.

1 Like

Solved! Damn, thank you man. Something dumb.

Thank you very much!

1 Like

Beat me to it …

2 Likes

TIP:

Your automation is defined using YAML which Home Assistant understands as JSON. The condition section of your automation looks like this in JSON:

		"condition": [
			{
				"condition": "numeric state",
				"entity_id": "sensor.illumination_286c07fa2477",
				"above": 300,
				"below": 1000
			}
		],

That’s represents a fragment of a JSON dictionary (a data structure that organizes information using key:value pairs).

Here’s that error message you received:

not a valid value for dictionary value @ data[‘condition’][0][‘condition’]

OK, it says one of the dictionary values is invalid and says it’s this one:
data['condition'][0]['condition']

The complaint is regarding condition, specifically its zeroth item (it’s zero-based so the first item is actually the zeroth), containing the key condition.

Referring to the JSON code (shown above), we see it’s complaining about "condition": "numeric state",.

Here’s a different example. Let’s say this was your condition section, containing two conditions:

  condition:
  - condition: state
    entity_id: input_boolean.test
    state: 'on'
  - condition: numeric state
    entity_id: sensor.illumination_286c07fa2477
    above: 300
    below: 1000

In this case the error is in the second condition. Home Assistant’s error message would be:

`not a valid value for dictionary value @ data['condition'][1]['condition']`

Notice the [1] instead of [0]? That’s because the error is no longer in the zeroth item but in the first item. Again, we have to remember is is zero-based so 1 actually means the second item.

I hope this helps to de-mystify the error messages, even if only just a little bit.

3 Likes

@123 Thank you so much! Actually, that really clears things up for me and will help me troubleshoote more independent next time.

Really appreciate the effort you took there to explain that.

1 Like

Hello, in the numeric condition, in replacement if the lx value, it’s possible to path a input_number.***?

Sorry for my Bad english.

no you have to use a template