AI task was working but suddenly stopped

Hi,
I’m struggling with the AI task. I got it working, but suddenly it stopped. I can’t find any issues in the code, but maybe I’m missing something. I can still use the instructions in the developer tools to generate text.

# AI ANALYS 1A_2
template: 
 - triggers:
      - trigger: time
        at: "10:35:00"
    actions:
      - action: ai_task.generate_data
        data:
          entity_id: ai_task.google_ai_task
          task_name: AI analyse 1
          instructions: |2-

                  Du analyserar ett batteris laddningsbeslut i Home Assistant.

                  Använd endast datan nedan. Gissa inte.

                  ====================
                  ENHETER
                  ====================
                  - Energi: kWh
                  - Boolean: true/false
                  - Tid: text

                  ====================
                  DATA
                  ====================

                  Should_charge:
                  {{ state_attr('sensor.sem_battery_charge_energy_1a_2','should_charge') }}

                  Battery_solar_enough_today:
                  {{ state_attr('sensor.sem_battery_charge_energy_1a_2','battery_solar_enough_today') }}

                  Battery_charge_profit:
                  {{ state_attr('sensor.sem_battery_charge_energy_1a_2','battery_charge_profit') }}

                  Laddnings_behov:
                  {{ states('sensor.sem_battery_charge_energy_1a_2') }}

                  Laddningsfönster:
                  {{ states('sensor.sem_battery_charge_window_cheapest_1a') }}

                  Systemläge: 
                  {{ states('input_select.sem_battery_charge_override_1a_2') }}
          

                  ====================
                  REGLER
                  ====================

                  - Should_charge = true → batteriet laddas
                  - Should_charge = false → batteriet laddas inte

                  Förklaring:
                  - Om Battery_solar_enough_today = true → laddning behövs inte p.g.a. solel
                  - Om Energi_behov > 0 → laddning behövs
                  - Om Battery_charge_profit = true → laddning är lönsam
                  - Om Battery_charge_profit = false → laddning är inte lönsam
                  - Om Systemläge = Ladda - då har användaren beslutat att ladda vilket skriver över systemets beslut
                  - Om Systemläge = Ladda ej - då har användaren beslutat att inte ladda vilket skriver över systemets beslut
                  - Om Systemläge = Auto - då gäller systemet beslut

                  ====================
                  SVAR
                  ====================

                  Svara kort, tydlig och förklarade på svenska (alltid 4 meningar):
                  - Vad systemet gör (laddar / laddar inte + ev. tid)
                  - Varför (baserat på sol, behov och lönsamhet)
                  - Ta inte med några siffror men tidpunkten för laddning ska framgå. Laddningsfönstrets klockaslag ska skrivas ut
                  - Om Systemläge = Ladda ej eller Ladda skriv ut att användaren tagit beslutet manuellt och systemets beslut skrivs över. 
                  - Skriv inte ut systemläge om systemet är i läget auto
          response_variable: result_1a_2
    sensor:
      - name: "sem_ai_analys_1"
        state: "{{ result_1a_2.data }}"

What does the trace tell you?

I have configured it in YAML, but I don’t see anything in the logs. It seems like the trigger isn’t working because the sensor doesn’t update.

The strange thing is that I got it working with one configuration, but when I duplicated it for another analysis, it stopped working.

Look in your voice debug logs, see if the agent is even attempting to call it.

Go to settings, Voice and pick your agent then select Debug.

I can start a conversation and get this information in debug.
The strange thing is that I can run the action in the Dev Tools and get generated data, but it doesn’t work in my template sensor.


My apologies aitask not script…

Wait ok… Is this a triggered template sensor or an automation? …the fact you had aitask and template at the same time… AFAIK you can’t action inside the trigger template sensor. Instead, you have to have an automation do your aitask and park the result somewhere like an input text. Then read that on change with your trigger template sensor. (it can read stuff all day long inside the trigger but you can’t fire an action)

I found the error. It was a typo on my part.

response_variable: result_2_1b

was in the wrong place, which is why I wasn’t getting any data.