Scrape Yaml

I want to put scrape code directly in the yaml instead of using the visual part of the integration and I can’t get it to work… any ideas? This is the code, if I configure it from the visual with the same data it works but if I put this code in the sensors section, when I restart the system the sensor doesn’t even appear.

  - platform: scrape
    resource: https://www.dinoonline.com.ar/super/producto/aceite-de-girasol-natura-x-15-lt/_/A-2320031-2320031-s
    name: Aceite
    select: "#addToCartx > div:nth-child(5) > div:nth-child(1) > div > div > div.precio-unidad > span"
    scan_interval: 43200 
    value_template: "{{ value | float }}"  
    unit_of_measurement: "ARS"

Look at the YAML example in the documentation: Scrape - Home Assistant

Scrape is not a sensor platform it is its own integration. It goes under it’s own integration in your configuration.yaml file not under sensor:

# configuration.yaml
scrape:
  - resource: https://www.dinoonline.com.ar/super/producto/aceite-de-girasol-natura-x-15-lt/_/A-2320031-2320031-s
    scan_interval: 43200 
    sensor:
      - name: "Globos"
        select: "#addToCartx > div:nth-child(5) > div:nth-child(1) > div > div > div.precio-unidad > span"
        unit_of_measurement: "ARS"

I tried it there and the same thing happens, when I restart it the sensor doesn’t even appear.

Did you format it correctly as I have done above?

Did you restart or reload after doing that?

What entity id are you looking for?

It should be called sensor.aceite_de_prueba

Errors in Settings → System → Logs?

I just checked the log and found this error.

Registrador: homeassistant.components.sensor
Fuente: helpers/entity_platform.py:633
integración: Sensor (documentación, problemas)
Ocurrió por primera vez: 23:49:24 (1 ocurrencias)
Última vez registrado: 23:49:24

Error adding entity sensor.aceite_de_prueba for domain sensor with platform scrape
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 640, in state
    numerical_value = float(value)  # type:ignore[arg-type]
ValueError: could not convert string to float: '\r\n\t\t\t\t\t\t\t\t$3,129.00\r\t'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 633, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 972, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1383, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/scrape/sensor.py", line 206, in async_added_to_hass
    self.async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in async_write_ha_state
    self._async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1148, in _async_write_ha_state
    self.__async_calculate_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1085, in __async_calculate_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1029, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 642, in state
    raise ValueError(
    ...<5 lines>...
    ) from err
ValueError: Sensor sensor.aceite_de_prueba has device class 'None', state class 'None' unit 'ARS' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '
								$3,129.00
	' (<class 'str'>)

I added it there,

value_template: "{{ value.replace('$', '').replace(',', '').strip() | float }}"

and it worked. Honestly, I hadn’t realized to check the logs. Thanks so much!!