Handling electricity dynamic pricing - Flex D

Thanks @ymerj, that's another simple solution. I prefer not using delays and rather use different trigger to make it simpler to debug. I also expect that the logic would better turn back to normal in case of hub reboot. But I must admit that I never ran into scheduling problem at bootup and my hub is on UPS.

I see you go down by 5°C, what's you normal temperature. I keep the house to 20° I feel going down to 15° would cause some complaints from the family :confused:

My hub is on UPS also and can last 5 days without power so no worries on that side. Normal temp is 20°C but I cheet a bit because I leave 2 rooms on the second floor at normal temperature (with doors close) to relax, watch TV or whatever when I feel the temp goes too low for confort.

@Cramezul I patched together a Gmail apps script from sample code to automate enabling a peak event state on the HE when I get an email from Hydro. Uses MakerAPI to turn a virtual switch on. If there's any interest I can share it.

2 Likes

Yes it would be interesting. This is the missing part of the puzzle! :+1:t2:

Here's the script in question. It's pretty dumb as it doesn't check the event date (in RM I assume the event occurs the next day) and doesn't parse the contents e.g. to figure out if it's a morning peak event, afternoon peak event or both (my RM rules assume both).

/*
  This is a Google Apps Script to detect any specified Gmail and turn on an HE virtual switch via a call to MakerAPI

  Inspired from : https://www.reddit.com/r/GMail/comments/i727l6/ive_made_a_tool_to_filter_gmails_and_trigger_any/

 */
  function Gmail_Trigger() {

  var cloudAPIurl = 'https://cloud.hubitat.com/api/'

  var hubId = 'abcde'                  // get this from "Settings", "Hub Details"
  var makerAPIKey = 'fghij'            // from the MakerAPI instance you plan to use for this automation
  var makerAPIAppId = '100'            // the app ID of the MakerAPI instance
  var virtualSwitchDeviceId = '200'    // the device ID of the virtual switch to be turned on

  var triggerLabel = 'HydroEvenementPointe'   // name of Gmail Label (optional to change)

  //-----------------------------------------------------------//

  console.log('Script Gmail_Trigger() start');

  var label = GmailApp.getUserLabelByName(triggerLabel);

  if (label == null){
    //GmailApp.createLabel(triggerLabel);  // better to go to gmail and create a filter.
    console.error('Label does not exist : %s', triggerLabel);
  } else{
    var threads = label.getThreads();
    if(threads.length > 0){
      console.log('Label found %d emails with label %s',threads.length, triggerLabel);
      console.log('executing commands');
      var response = UrlFetchApp.fetch(cloudAPIurl + hubId + '/apps/' + makerAPIAppId + '/devices/' + virtualSwitchDeviceId + '/on?access_token=' + makerAPIKey);
      console.log('command to hub got response code %d', response.getResponseCode());
    } else {
      console.log('No threads labeled %s',triggerLabel);
    }
    console.log('Removing label from threads');
    label.removeFromThreads(threads);     // comment out this line if removing trigger label from emails not required
  }

    console.log('Script Gmail_Trigger() end');
}

/*

  Typical Hydro email subject line (language specific)

  ❄ Avis d’évĂ©nement de pointe | Jeudi 22 dĂ©cembre 2022

  Create a gmail filter to tag these with triggerLabel

  Sample command :

  https://cloud.hubitat.com/api/[hubId]/apps/[MakerAPIappID]/devices/[Device ID]/[Command]/[Secondary value]?access_token=[MakerAPIkey]

  Instructions:

  0.  Create a virtual switch to be turned on and set up a MakerAPI instance to make it accessible via external http calls
  1.  Save this Script to your account. (Click 'File', 'Save a Copy', close this window and open the copy. Rename it if you like.)
  2.  Paste in your Hub ID, MakerAPI Key, MakerAPI app ID on your hub, and the device ID of the virtual switch to turn on at the top of the file.  Save again.
  3.  Click the 'Run' arrow button and allow permissions. (Advanced etc) Click it again. (It will create the label automatically)
  (Read the script, it can't do anything risky. It simply checks if any mail for that label and makes an http call)
  4.  Click 'Edit, Current project's triggers' above and Add a Trigger for this script to run once every minute, or whenever.
  5.  Set up a Filter in Gmail settings for the (triggering) emails, and set the filter to add the label name. (Default is 'TriggerMail')
  6.  Set up a Rule Machine instance to trigger on the virtual switch turning on and go wild.

 */

The thing ran yesterday for this morning's event and I didn't have to lift a finger. I did have to manually cancel the afternoon peak period though.

Now I need to figure out code to change the Ecobee's schedule so that it will start heating earlier to a slightly higher setpoint (I have a hydronic system... perfect for this program :wink: ).

Just wanted to drop this in:

@hubitrep your script gave me an idea to add an automated override that can be controlled with a switch like you're doing.

2 Likes

OMG! It is easier than i though! I was thinking of how to run an app in HE to poll my inbox, etc... This solution is really simple. Thanks for sharing.

1 Like

(offtopic) Yeah I find it really elegant that you can essentially map any hub / device / app on the same route. Allows you to think of all your hubs (or all Hubitat units if you're its cloud platform operator :wink:) as one system. MakerAPI provides crude API management (authz) and I could imagine going even further, allowing writing apps that are hub-agnostic, for example by detecting when an endpoint is local and skipping the cloud hop, providing observability / throttling, etc. I've not looked at Hub Mesh/Connect yet but this sort of functionality makes those features obvious.

@Cramezul

Here is how I am able to find automatically a new morning or a new evening peak event.

In Gmail, I apply some labels to Hydro Québec emails :
Capture d’écran, le 2023-01-24 Ă  21.02.06

I use the app GCal search to find If there are some new Hydro Québec emails :

It will search for a new email with the label Hydro matin (I have a separate rule for hydro soir) :
Capture d’écran, le 2023-01-24 Ă  21.03.44


Then If there is a new email, It runs the RM rule to turn on a switch :

5 Likes

I don't know why it didn't occur to me to just use two labels instead of one. So simple. Thanks for pointing it out !

Wow!!! :astonished:

I don't know why HQ doesn't publish an API. They have one!

I found this thing: in your Espace Client, when a peak is scheduled, there's a frame with the next events.

To build this frame, the page calls this API
https://rb.solutions.hydroquebec.com/portraitweb/api/v3_0/conso?noContrat=[YourContractNumber]

It returns a json like this
{

"codeEtatPeriodeCourante": "000",
"dateDebutPeriode": "2023-01-04",
"dateFinPeriode": "2023-03-01",
"dateDerniereLecturePeriode": "2023-01-15",
"nbJourLecturePeriode": 12,
"nbJourPrevuPeriode": 57,
"montantFacturePeriode": 111.59,
"montantProjetePeriode": 697.57,
"indContratPuissance": false,
"adresseLieuConsoPartie1": "Adresse ligne1",
"adresseLieuConsoPartie2": "Adresse ligne2",
"codeTarif": "DPC",
"codeOptionTarif": "",
"listePeriodePointeCritiqueAujourdhui": [
    {
        "dateDebut": "2023-01-16T06:00:00-05:00",
        "dateFin": "2023-01-16T09:00:00-05:00"
    }
],
"listePeriodePointeCritiqueDemain": null

}

Problem is it needs authentication. That's where I am...

I also found this project but didn't have the time to look at it. It's not an HE project but there may be interesting things to take from it.

2 Likes

Nice thread. I wanted to implement some automatic fetching, but to be honest, it is very simple the way I implemented it: simply with 2 virtual switches. One for a morning and one for the afternoon peak events. I flip the corresponding switch manually when it is announced, and then it triggers rules in Rule Machine at specific times

The VSS: things are all Virtual Switch for Scenes. Each switch triggers what I call a scene, which is just another rule in Rule Machine. The rule sets thermostats, shuts off (or turns on) switches, etc.

1 Like

HYDROQC GITLAB Yes I saw this too. I was thinking installing it on HA and use HADB to import it in HE but a direct solution would be preferable.

I know that @nclark wrote an app to take advantage of Hydro Quebec dynamic pricing : Thermostat Scheduler [RELEASED] - #398 by nclark

This is really crazy that there is no public API.

I have an Ecobee thermostat, If only Hydro Quebec would partnered with them : they have a built in way of managing It : https://www.ecobee.com/en-ca/eco-plus/community-energy-savings/

Sinope is doing It with Éco SinopĂ© | SinopĂ© Technologies EN but I don't think there is a way to integrate the GT130 hub with Hubitat.

1 Like

I installed the HYDROQC integration to my HA and imported it to HE using HADB. It gives several info which are not very usefull but the relevant ones are there.

Yes indeed, Griddy's model was one that actually had more at risk BECAUSE of the structure of the power market in TX.

BUT interestingly, one of the big arguments used to support Smart Meters in many TX municipalities was inconsistently offered after the arguments were won, approvals were granted, and the meters were allowed to be put in.

That is, "giving the customer a break on electricity pricing because you would know exactly how much they were using peak vs off peak". As most know, "Off Peak" power, ESPECIALLY that which is generated between 10pm and 5am, is generally a HALF PRICED commodity.

But instead of all the big players making that a simple Easy Button option for consumers right from the start of the program...they concocted a cornucopia of combo pricing options that made picking providers, plans, and usage profiles very confusing for most folk.

In my mind, the promise of "cheaper power by shifting usage" never came to the market in the straight forward offering it should have. This would have benefited everyone (maybe not the gimmick prone power marketers)....the generators as far as not needing to rush to ramp up capacity, and the consumers ....REALLY getting a deal..... IF they could shift more power use to Off Peak. It's too bad it's not easy to "store" AC Cooling generated at night...for the next bloomin hot TX afternoon!

1 Like

Wow thanks so much for this information!! Nice tool Gcal :+1:

Je suis content d'avoir trouvé ce topic de Québécois pour les Québécois !! :stuck_out_tongue_winking_eye::call_me_hand:

2 Likes

You could have a bulb over the electric dryer, dim red during peak time, bright white during off peak.

Has anyone looked into using cold outside air (with a heat exchanger) to reduce your refrigerator and maybe your freezer usage?

1 Like

I would like to point out that in Québec, where heating is almost exclusively electric, all the energy consumed by electric devices in winter ultimately end up in heat. Reducing their usage will reduce the amout of heat they disperse which will have to be compensate by the heating system, resulting in a net 0 effect on the electricity bill.

So in that particular situation, freezer, frige, light etc. does not cost anything to run in winter. The 2 that are wasting are the dryer and hot water. Because both are discarding heat outside.

1 Like