Set variables, custom component variables

I tried some things because i encountered the same problem but i got it fixed setting the variable attributes. I must say im pretty new to this type of coding and find it hard to get used to so my approach is mostly the trial and error method :laughing:

service: variable.set_variable
data:
  variable: rain_total_24h
  attributes: |-
    {
      "history_1": "{{ states('variable.rain_total_24h') }}",
      "history_2": "{{ state_attr('variable.rain_total_24h', 'history_1') }}",
      "history_3": "{{ state_attr('variable.rain_total_24h', 'history_2') }}"
    }

i have a problem with set the variable a (i don’t write anything in configuration.yaml i have write all code inside only in automation.yaml) with this my automation to find increase temperature

can you help me ? i don’ t know how i can resolve …

- alias: Controllo_incremento_temperatura301
  trigger:
  - platform: state
    entity_id: switch.sonoff_XXXX
    from: "off"
    to: "on"
  action:
  - variables:
      start_temperature301: "{{ states('sensor.sonoff_XXXX_temperature') }}"
      #counter: 0
  - alias: repeat until 
    repeat:
      sequence:
        - delay: 00:00:03
        - variables:
            new_temperature301: "{{ states('sensor.sonoff_XXXX_temperature') }}"
        - choose:
          - conditions:
              - condition: template
                value_template: "{{ (float(start_temperature301) + 0.1) < float(new_temperature301) }}"
            sequence:
              - variables:
                  a: 2   # this don't work
              - service: notify.mail
                data:
                  title: "Controllo Istantaneo temperatura 301"
                  message: "Incremento di 0.1 gradi rilevato"
          default:
            - variables: 
                a: 1  # this don't work
      until:
        condition:
          - or:
            - condition: template
              value_template: "{{ a != 2 }}"
            - condition: template
              value_template: "{{ repeat.index > 20 }}"
  - service: notify.mail
    data:
      title: "STATO CALDAIA ENTRO 15 MIN DA ACCENSIONE CALDO 301"
      message: >
        {% if a == 1 %}
          ALERT_CALDAIA NON FUNZIONANTE ENTRO 15 MIN_DOPO 301 CALDO ON
        {% elif a == 2 %}
          OK_CALDAIA FUNZIONANTE ENTRO 15 MIN_DOPO 301 CALDO ON
        {% else %}
          PROBLEMA NEL CODICE
        {% endif %}

how can i set variable a to 1 or 2
a=1 or a=2 ???
is the only tings that don’t work in this automation …

Good afternoon, I am trying to put an automation script together based off a Schedule. The challenge I have is setting the value of HVAC (Off or Heat) from a Scheduler (Off or On) - sorry for the ramble…

Schedule sends ‘on’ or ‘off’ based time, this works as I can include the state in a notification.

The switch takes hvac_mode: ‘off’ or ‘heat’

In my automation I need to map ‘on’ from the schedule to ‘heat’ and then use this variable in hvac_mode: %variable%

alias: Boiler Control - Weekdays PM
description: Boiler Control - Weekdays PM
trigger:
  - platform: state
    entity_id:
      - schedule.boiler_weekday_pm
    attribute: next_event
condition:
  - condition: template
    value_template: "{{ trigger.to_state.state in ['on', 'off'] }}"
action:
  - service: climate.set_hvac_mode
    metadata: {}
    data:
      **hvac_mode:** heat # needs to be a variable set by "trigger.to_state.state"
    target:
      entity_id: climate.controller_boiler
  - service: notify.mobile_app_carey_work_phone
    metadata: {}
    data:
      message: "\"Boiler switched {{ states('switch.controller_boiler') }}\""
mode: single