Accessing / setting global variables from custom component header?

Hi

In my yaml file, I have:

esphome:
name: c3-test
friendly_name: c3-test
libraries:
- Preferences
includes:
- c3-test.h

globals:

  • id: threshold1
    type: float
    restore_value: yes
    initial_value: “0.5”

Now - how do I read/update this value from the custom components header file ?

And is it possible to change the value from the custom component ?

This is with a float … As far as I remember, it should be possible to do with strings as well ?

As the taget is ESP32-C3, apparently I cannot use any functions from “preferences.h” file

Any ideas - or links to examples ?

Regards
Brian