Compare commits
2 Commits
41aac081ca
...
77e42910c5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77e42910c5 | ||
|
|
397b2c9f30 |
@@ -1,3 +1,5 @@
|
|||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -16,7 +18,9 @@ app.MapPost(
|
|||||||
{
|
{
|
||||||
Console.WriteLine("high power alert was received.");
|
Console.WriteLine("high power alert was received.");
|
||||||
using var client = new HttpClient();
|
using var client = new HttpClient();
|
||||||
var heatPumpState = await client.GetFromJsonAsync<HeatPumpStatus>("http://192.168.1.121/control");
|
var heatPumpState = await client.GetFromJsonAsync<HeatPumpStatus>(
|
||||||
|
"http://192.168.1.121/control"
|
||||||
|
);
|
||||||
var message = "";
|
var message = "";
|
||||||
Console.WriteLine(heatPumpState.heatpump.power);
|
Console.WriteLine(heatPumpState.heatpump.power);
|
||||||
switch (body.Status)
|
switch (body.Status)
|
||||||
@@ -32,7 +36,8 @@ app.MapPost(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
message = "@everyone high power alert, but heat pump could not be disabled because state was not 'ON'";
|
message =
|
||||||
|
"@everyone high power alert, but heat pump could not be disabled because state was not 'ON'";
|
||||||
}
|
}
|
||||||
await client.PostAsJsonAsync<DiscordMessage>(
|
await client.PostAsJsonAsync<DiscordMessage>(
|
||||||
"https://discord.com/api/webhooks/1455072237207158981/C9qvSIGMZVc60VwpZizxqKigyzvA182RDSdt9k8qtWTq-fBgzlJHh53wAYIqYkGNkBM3",
|
"https://discord.com/api/webhooks/1455072237207158981/C9qvSIGMZVc60VwpZizxqKigyzvA182RDSdt9k8qtWTq-fBgzlJHh53wAYIqYkGNkBM3",
|
||||||
@@ -48,8 +53,10 @@ app.MapPost(
|
|||||||
"http://192.168.1.121/control?cmd=heatpump&set_power_mode=on"
|
"http://192.168.1.121/control?cmd=heatpump&set_power_mode=on"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
message = "@everyone Heat pump could not be re enabled because state was not 'ON'";
|
{
|
||||||
|
message =
|
||||||
|
"@everyone Heat pump could not be re enabled because state was not 'ON'";
|
||||||
}
|
}
|
||||||
await client.PostAsJsonAsync<DiscordMessage>(
|
await client.PostAsJsonAsync<DiscordMessage>(
|
||||||
"https://discord.com/api/webhooks/1455072237207158981/C9qvSIGMZVc60VwpZizxqKigyzvA182RDSdt9k8qtWTq-fBgzlJHh53wAYIqYkGNkBM3",
|
"https://discord.com/api/webhooks/1455072237207158981/C9qvSIGMZVc60VwpZizxqKigyzvA182RDSdt9k8qtWTq-fBgzlJHh53wAYIqYkGNkBM3",
|
||||||
@@ -75,6 +82,46 @@ app.MapPost(
|
|||||||
)
|
)
|
||||||
.WithName("Low Power Alert");
|
.WithName("Low Power Alert");
|
||||||
|
|
||||||
|
// Example: querying an InfluxDB v2 instance via its Flux query API.
|
||||||
|
app.MapGet(
|
||||||
|
"/example/influx_query",
|
||||||
|
async () =>
|
||||||
|
{
|
||||||
|
var token = "0kycl3gLT7kWBzfrNcvkmXVDUUjdWUwKnTmBZJfS_dHrE2EiJYv_HthDLc92Xsdaui3FxRsm7zndyyS33Mh9YA==";
|
||||||
|
var org = "homeassistant";
|
||||||
|
|
||||||
|
using var client = new HttpClient();
|
||||||
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
|
||||||
|
"Token",
|
||||||
|
token
|
||||||
|
);
|
||||||
|
client.DefaultRequestHeaders.Accept.Add(
|
||||||
|
new MediaTypeWithQualityHeaderValue("application/csv")
|
||||||
|
);
|
||||||
|
|
||||||
|
var flux = """
|
||||||
|
from(bucket: "homeassistant")
|
||||||
|
|> range(start: -5m)
|
||||||
|
|> filter(fn: (r) => r._measurement == "W")
|
||||||
|
|> filter(fn: (r) => r.domain == "sensor")
|
||||||
|
|> filter(fn: (r) => r.entity_id == "p1_meter_power")
|
||||||
|
|> filter(fn: (r) => r._field == "value")
|
||||||
|
|> mean()
|
||||||
|
|> yield(name: "mean")
|
||||||
|
""";
|
||||||
|
var content = new StringContent(flux, Encoding.UTF8, "application/vnd.flux");
|
||||||
|
|
||||||
|
var response = await client.PostAsync(
|
||||||
|
$"http://influxdb.pladijs/api/v2/query?org={org}",
|
||||||
|
content
|
||||||
|
);
|
||||||
|
var result = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
return Results.Content(result, "text/csv");
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.WithName("ExampleInfluxQuery");
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
record AlertBody(string Status);
|
record AlertBody(string Status);
|
||||||
|
|||||||
Reference in New Issue
Block a user