How to set global configuration or variables?

Hi,

i tried to set global config/vars that i can use within automations or scripts.

currently i tried

- sensor:
    - name: "storen_data"
      state: "active"
      attributes:
        data: >
          {{ {
            "bath": {
              "entity_id": "cover.storen_1_aebt_storen_1_gaestebad",
              "azimuth_min": 135,
              "azimuth_max": 225,
              "position_default": 100,
              "tilt_default": 100,
              "position_vor_abends": 0,
              "tilt_vor_abends": 30,
              "position_abends": 0,
              "tilt_abends": 0,
              "position_nacht": 0,
              "tilt_nacht": 0,
              "position_sonnenschutz": 0,
              "tilt_sonnenschutz": 40,
              "window_sensor": "sensor.custom_fenster_status_gaestebad",
              "automation_active_sensor": "input_boolean.storen_automatic_gaestebad_fenster"
            },

Autocomplete for this sensor works, and some test sensors function as well.
I’m trying to save the configuration as JSON, or I wish I could set the configuration in a YAML file.

i try to geht the data with :
{{ (state_attr(‘sensor.storen_data’, ‘data’)) }}

Hello mariva,

The easiest is to use helpers
Input number - Home Assistant.
Input text - Home Assistant.
Input boolean - Home Assistant.

Otherwise there is this:

You can use the custom_templates for that.
They can be actual templates, or just plain strings disguised as templates :wink:

hi, thank you.

is it not possible to set “custom” yaml files for example?

i think its a bit messy to use helpers esp. if i have to use it for each window :frowning:

i tried this.

in my configuration.yaml


template: !include_dir_merge_list custom_templates

then i used. the “template sensor” as shown above.

but my “data attribute is empty.”

wish i could store the config in yaml. i thought thats the purpose of yaml.

storen:
  gaestebad:
    entity_id: cover.storen_1_cec9_storen_1_gaestebad
    azimuth_min: 135
    azimuth_max: 225
    position_default: 100
    tilt_default: 100
    position_vor_abends: 0
    tilt_vor_abends: 30
    position_abends: 0
    tilt_abends: 0
    position_nacht: 0
    tilt_nacht: 0
    position_sonnenschutz: 0
    tilt_sonnenschutz: 40
    window_sensor: sensor.custom_fenster_status_gaestebad
    automation_active_sensor: input_boolean.storen_automatic_gaestebad_fenster

after i tried {{ storen.xyz.azimuth_min }}

Your template isn’t closed…

yes, because its only a crop the actual json/config is very long :slight_smile:

Well if you cut off half of the coding, then how can

data: >
  {{ {
    "gaestebad": {
      "entity_id": "cover.storen_1_cec9_storen_1_gaestebad",
      "azimuth_min": 135,
      "azimuth_max": 225,
      "position_default": 100,
      "tilt_default": 100,
      "position_vor_abends": 0,
      "tilt_vor_abends": 30,
      "position_abends": 0,
      "tilt_abends": 0,
      "position_nacht": 0,
      "tilt_nacht": 0,
      "position_sonnenschutz": 0,
      "tilt_sonnenschutz": 40,
      "window_sensor": "sensor.custom_fenster_status_gaestebad",
      "automation_active_sensor": "input_boolean.storen_automatic_gaestebad_fenster"
    }
  } | tojson }}

You should be able to use YAML:

yaml</s> <s>#custom_templates.yaml</s> <s>- sensor:</s> <s> - name: "storen_data"</s> <s> state: "active"</s> <s> attributes:</s> <s> data: </s> <s> gaestebad:</s> <s> entity_id: cover.storen_1_cec9_storen_1_gaestebad</s> <s> azimuth_min: 135</s> <s> azimuth_max: 225</s> <s> position_default: 100</s> <s> tilt_default: 100</s> <s> position_vor_abends: 0</s> <s> tilt_vor_abends: 30</s> <s> position_abends: 0</s> <s> tilt_abends: 0</s> <s> position_nacht: 0 </s> <s> tilt_nacht: 0</s> <s> position_sonnenschutz: 0</s> <s> tilt_sonnenschutz: 40</s> <s> window_sensor: sensor.custom_fenster_status_gaestebad</s> <s> automation_active_sensor: input_boolean.storen_automatic_gaestebad_fenster</s> <s>

Store the desired data as a dictionary using YAML.

EDIT : Ninja’d by Didgeridrew

EDIT2: This doesn’t work; see post below.

Example
- sensor:
    - name: storen_data
      state: active
      attributes:
        data:
          bath:
            entity_id: cover.storen_1_aebt_storen_1_gaestebad
            azimuth_min: 135
            azimuth_max: 225
            position_default: 100
            tilt_default: 100
            position_vor_abends: 0
            tilt_vor_abends: 30
            position_abends: 0
            tilt_abends: 0
            position_nacht: 0
            tilt_nacht: 0
            position_sonnenschutz: 0
            tilt_sonnenschutz: 40
            window_sensor: sensor.custom_fenster_status_gaestebad
            automation_active_sensor: input_boolean.storen_automatic_gaestebad_fenster

i tried, but my studio-code editor said:

Incorrect type. Expected "string".yaml-schema: http://schemas.home-assistant.io/integration-template

View Problem (Alt+F8)

i cant figure it out :frowning:

You can’t always believe those warnings… save the file, reload the config or restart HA then check it in the template editor tool.

i tried , doesnt work. :frowning:

{{ (state_attr(‘sensor.storen_data’, ‘data’)) }}

I don’t get those errors in VS Code.

Go to Developer Tools → YAML and select Check Configuration. If you get no errors, proceed to execute Reload Template Entities. Then check Logs for errors.

yep, this is what i always do , just to be sure :slight_smile:

still there is no config data available. i tried Developer Tools → Template

If you tried it and it doesn’t work, there are errors in the log or the yaml file isn’t loaded to begin with. Any errors?

looks like the value has to be a string …

This is working for me:

  - sensor:
      - name: "storen_data"
        state: "active"
        attributes:
          data: |
            {{ {"gaestebad": {
              "entity_id": "cover.storen_1_cec9_storen_1_gaestebad",
              "azimuth_min": 135,
              "azimuth_max": 225,
              "position_default": 100,
              "tilt_default": 100,
              "position_vor_abends": 0,
              "tilt_vor_abends": 30,
              "position_abends": 0,
              "tilt_abends": 0,
              "position_nacht": 0,  
              "tilt_nacht": 0,
              "position_sonnenschutz": 0,
              "tilt_sonnenschutz": 40,
              "window_sensor": "sensor.custom_fenster_status_gaestebad",
              "automation_active_sensor": "input_boolean.storen_automatic_gaestebad_fenster"} } }}

Then:

{{state_attr('sensor.storen_data', 'data').gaestebad.azimuth_min}}