Files

65 lines
2.2 KiB
Terraform

locals {
templated_code = templatefile("${path.module}/scripts/Taupi-4.0.js", {
sensor_aussen_mac = var.sensor_aussen_mac
sensor_innen_mac = var.sensor_innen_mac
taupunktschwelle = var.taupunktschwelle
mindesttemperatur = var.mindesttemperatur
max_indoor_temp_heating = var.max_indoor_temp_heating
winter_temp_threshold_in = var.winter_temp_threshold_in
winter_temp_threshold_out = var.winter_temp_threshold_out
target_humi_summer = var.target_humi_summer
target_humi_winter = var.target_humi_winter
urgent_humi_threshold = var.urgent_humi_threshold
night_window_start_hour = var.night_window_start_hour
night_window_end_hour = var.night_window_end_hour
max_runtime_minutes = var.max_runtime_minutes
min_pause_minutes = var.min_pause_minutes
schaltzeit = var.schaltzeit
battery_warngrenze = var.battery_warngrenze
lost_connection = var.lost_connection
critical_humi_base = var.critical_humi_base
critical_humi_temp_coeff = var.critical_humi_temp_coeff
critical_humi_ref_temp = var.critical_humi_ref_temp
critical_humi_buffer = var.critical_humi_buffer
})
}
resource "local_file" "templated_script" {
content = local.templated_code
filename = "${path.module}/scripts/Taupi-4.0.templated.js"
}
resource "shelly_script_config" "taupi" {
ip = var.shelly_ip
id = 1
name = "Taupi-4.0"
enable = true
}
resource "null_resource" "upload_script" {
triggers = {
code_hash = sha256(local_file.templated_script.content)
ip = var.shelly_ip
}
provisioner "local-exec" {
command = "python3 ${path.module}/scripts/upload.py ${var.shelly_ip} 1 ${local_file.templated_script.filename}"
}
depends_on = [shelly_script_config.taupi]
}
data "external" "script_status" {
program = ["python3", "${path.module}/scripts/get_status.py", var.shelly_ip, "1"]
# Trigger re-run whenever upload finishes
query = {
trigger = null_resource.upload_script.id
}
}
output "script_status" {
value = data.external.script_status.result
description = "The runtime status of the Shelly script"
}