56 lines
1.7 KiB
HCL
56 lines
1.7 KiB
HCL
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
|
|
mindesthumi = var.mindesthumi
|
|
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"
|
|
}
|