Can I have a sensor showing the state of a Global with a type: std::string?

Is it possible to show the state of a global if the type is a std::string ?

I have Globals similar to this…

  - id: global_example
    type: std::string
    restore_value: yes

Then some ‘automations’ which update the Global value (i hope!)?

       - globals.set:
           id: global_sms_sender
           value: !lambda 'return id(global_example).state;'

What I’m struggling with now, is creating a sensor to display in the web server, what the Global value is.

Instead of a Global you could just use a text_sensor?

Oh, and Globals do not have a state property. It would just be id(global_example).

1 Like

I’m trying to keep the values on reboot and the global ‘restore_value’ helps.

you are not clear if you want to set global or want to present it as sensor…
This for example updates template sensor to show global

Two ways to go around this:

You can either just copy the value of the text_sensor to the global in the on_value action of the text_sensor and then publish the value of the global to the text_sensor on_boot.

or if you just want to reflect the global in the text_sensor, create a lamba for the text_sensor that returns the global.


I’m using the Sim800l and would like to save the last message received as a global (as this can restore on reboot) and display that as a sensor (so i can visually see in the web interface.

You can use a template text sensor and have it returning the global in the lambda.

1 Like


This did the trick…

  - platform: template
    name: "TEST"
    id: test_id_1
    lambda: |-
      return {id(global_sms_sender)};
    update_interval: 60s