California Power Flex Alert (CAISO)

We Californians get Flex Alerts quite often during the summer. I’ve created some basic sensors to gather that information and present it in Home Assistant. Please note that the automation only presents the NEWEST alert or cancellation.

This code goes out and grabs the RSS feed provided by CAISO that has the latest flex alerts.

sensor:

  - platform: rest
    resource: http://content.caiso.com/awe/noticeflexRSS.xml
    scan_interval: 300 #5 minutes
    name: Flex_Alert_Newest
    value_template: "OK" #'{{ value_json["rss"]["channel"]["item"][0] |truncate(210,True) }}' #255 character max?
    json_attributes_path: "$.rss.channel.item.[0]"
    json_attributes:
      - title
      - link
      - description

This code provides the times that the latest flex alert applies to.

  - platform: template
    sensors:
       flex_alert_cancellation_datetime:
        friendly_name: Flex Alert Cancellation Datetime
        value_template: >
          {% if state_attr('sensor.flex_alert_newest', 'title').split(" ")[0] == "CANCEL" %}
          {{ strptime( (state_attr('sensor.flex_alert_newest', 'description').split(' ')[4] + ' ' + state_attr('sensor.flex_alert_newest', 'description').split(' ')[6] + ' ' + state_attr('sensor.flex_alert_newest', 'description').split(' ')[7]), '%d-%b-%Y %I:%M %p') }}
          {% endif %}
        unit_of_measurement: "timestamp"
       flex_alert_starttime:
        friendly_name: Flex Alert Start Time
        value_template: >
          {% if state_attr('sensor.flex_alert_newest', 'title').split(" ")[0] == "NOTICE" %}
          {{ strptime( (state_attr('sensor.flex_alert_newest', 'description').split(' ')[1] + ' ' + state_attr('sensor.flex_alert_newest', 'description').split(' ')[3] + ' ' + state_attr('sensor.flex_alert_newest', 'description').split(' ')[4]), '%d-%b-%Y %I:%M %p') }}
          {% endif %}
        unit_of_measurement: "timestamp"
       flex_alert_endtime:
        friendly_name: Flex Alert End Time
        value_template: >
          {% if state_attr('sensor.flex_alert_newest', 'title').split(" ")[0] == "NOTICE" %}
          {{ strptime( (state_attr('sensor.flex_alert_newest', 'description').split(' ')[6] + ' ' + state_attr('sensor.flex_alert_newest', 'description').split(' ')[8] + ' ' + state_attr('sensor.flex_alert_newest', 'description').split(' ')[9]), '%d-%b-%Y %I:%M %p') }}
          {% endif %}
        unit_of_measurement: "timestamp"    

This is a basic notification utilizing the raw flex alert data.

- alias: Monitoring - Flex Alert
  trigger:
    platform: state
    entity_id: sensor.flex_alert_newest
  action:
    - service: notify.peopletonotify
      data_template:
        title: "{{ state_attr('sensor.flex_alert_newest', 'title') }}"
        message: "{{ state_attr('sensor.flex_alert_newest', 'description') }}"
2 Likes

Thank you for developing and sharing this code!

I am attempting to integrate it into my HA system…

I do not seem to be getting correct start/end timestamps, and the value for the Flex_Alert_Newest seems wrong, see:

Any ideas or suggestions about things I should do/try to fix this?

You might double check the YAML/Jinja lines for the rest sensor and make sure your editor did not modify it in some way. The YAML/Jinja code in this section does seem to confuse my syntax checker in Sublime Text but does not modify. Other editors might try to be ‘helpful’ .

The sensor values for my setup, as shown in the ‘Developer Tools’ section of Home Assistant are shown below:

Thank you for this info/clarification.
AFAICT everything is working OK on my system, I changed one line of your code, which explains the difference I was seeing. If I were to change it back, I would get exactly the same thing you showed above, this is very helpful.
Thank you again!

P.S. It would “sure be nice” if CAISO also published FlexAlerts in a more structured machine-to-machine format, e.g. JSON…

I ended up spending some time yesterday evening getting binary_sensors for the Flex/EEA1/EEA2/EEA3 alerts. In case someone else finds this useful, here is the AppDaemon app.

Screenshot 2022-09-07 4.22.56 PM

This is great, thank you for developing this and sharing!
I’ve never used AppDaemon, so I am slogging through that, and hope to have this running today or tomorrow

You’re welcome. I’ve added another AppDeamon app to adjust the thermostat temperature in response to alerts. This is still a work in progress though so there may be bugs. I’m hoping to test it tonight.

@eesv, @James_Huang

I recently learned that CAISO provides the same/similar data in a JSON file:

https://www.caiso.com/TodaysOutlook/FlexAlert/FlexAlerts.json

The API includes the following information:

    1. date
    1. time range
    1. region - Statewide, Northern CA, Southern CA, and/or Valley Electric Association (VEA region)

AFAICT there may be one or two binary characters at the start of the returned file, which upsets/breaks some clients, curl and Firefox don’t like it, but Chrome seems to just handle it.

According to CAISO:

  • The value of the “ID” of a specific FlexAlert remains constant for the life of that FlexAlert
  • The file will refresh every minute
  • While Flex Alerts include the region – Statewide, No Cal, So Cal or VEA – the ISO doesn’t specifically define these regions nor do all of the customers in these regions fall in the ISO’s balancing area
  • VEA is located in Pahrump, NV, and is part of our balancing area although we’ve never called a Flex Alert specifically for VEA.

An example (made up) contents:

{
    "IsFlexAlertActive":  true,
    "UpdatedOn":  "06-11-2021 09:05:29",
    "Active":  [
                   {
                       "ID":  6,
                       "Title":  "Flex alert for 06/11/2021",
                       "StartDate":  "06-11-2021 09:00",
                       "EndDate":  "06-11-2021 21:00",
		       "Region":  "Northern California;VEA Region"
                   }
               ],
    "Future":  [
                   {
                       "ID":  1,
                       "Title":  "Flex alert for 06/14/2021",
                       "StartDate":  "06-14-2021 16:00",
                       "EndDate":  "06-14-2021 21:00",
		       "Region":  "Statewide"
                   },
                   {
                       "ID":  2,
                       "Title":  "Flex alert for 06/15/2021",
                       "StartDate":  "06-15-2021 15:00",
                       "EndDate":  "06-15-2021 21:00",
                       "Region":  "Southern California"
                   }
               ]
}

FYI, my long term wish/goal is to read/parse this JSON file, and publish them to MQTT, and then configure MQTT sensors in Home Assistant (because I prefer running things thru MQTT so more than just HA can see/use them…)