Skip to content

Instantly share code, notes, and snippets.

View stas-dovgodko's full-sized avatar

Stas Dovgodko stas-dovgodko

View GitHub Profile
@stas-dovgodko
stas-dovgodko / test.php
Last active June 9, 2024 21:10
Laravel test1
<?php
class Post extends Model
{
public function comments()
{
return $this->hasOne(Comment::class);
}
}
@stas-dovgodko
stas-dovgodko / Ventilation.js
Created October 20, 2023 14:48
Openhab ventilation
let auto = require('openhab-auto');
auto.manager('Ventilation', {
label: 'Автоматичне керування температурою вентиляції',
groups: ['Ventilation'],
tags: ['HVAC', 'Control']
}, 'Ventilation_OutputSetpointTemperature').description('Автоматичне встановлення температури вентиляції відповідно до потреб')
.handle(function(event) {
// температура входу до рекуператора це міра "прогріву" будинку
const inhouse_temp = items.getItem('VentilationUnit_ExchangeTemperature').history.averageSince(time.ZonedDateTime.now().minusMinutes(5));
@stas-dovgodko
stas-dovgodko / proxy.js
Last active October 12, 2023 11:26
Openhab NVAC proxy layer
// Моя проксі-бібліотека
// https://www.npmjs.com/package/openhab-proxy-pattern
let proxy = require('openhab-proxy-pattern');
// modbus адаптер на датчики віддає температуру в цілому вигляді як десяті долі, наприклад 225
// в логічні елементи вже потрапляє як нормальне значення
const modbus_ds_map = function(value) {
if (typeof value == 'string') {
let t = parseInt(value) * 0.1;
@stas-dovgodko
stas-dovgodko / _ventilation_proxy.items
Created October 12, 2023 10:45
_ventilation_proxy.items
Group NEOCLIMA "NEOCLIMA"
Switch NEOCLIMA_SW_ONOFF { channel="modbus:data:neoclima:speed:onoff:switch" }
Switch NEOCLIMA_SW_HEATER { channel="modbus:data:neoclima:speed:heater:switch" }
Number NEOCLIMA_BYPASS_OPENING "NEOCLIMA - BYPASS OPENING" (NEOCLIMA) {channel="modbus:data:neoclima:speed:bypass_opening:number", autoupdate="false"}
Number NEOCLIMA_BYPASS_RANGE "NEOCLIMA - BYPASS RANGE" (NEOCLIMA) {channel="modbus:data:neoclima:speed:bypass_range:number", autoupdate="false"}
Number NEOCLIMA_S_SUPPLY "NEOCLIMA - S SUPPLY" (NEOCLIMA) {channel="modbus:data:neoclima:speed:supply:number"}
Number NEOCLIMA_S_EXHAUST "NEOCLIMA - S EXHAUST" (NEOCLIMA) {channel="modbus:data:neoclima:speed:exhaust:number"}
// флаг який встановлює чи потрібна зараз автоматична регуляція вентиляції
String Automation_Ventilation "Автоматичне керування вентиляцією" <robot> (Ventilation, gAutomation) ["Control"] {description="Автоматичне керування вентиляцією"}
// загальна група вентиляції та семантичного Equipment (https://www.openhab.org/docs/tutorial/model.html)
Group Ventilation "Вентиляційна система" <ventilation> (Main, gVentilation) ["HVAC"]
// фактична виміряна температура виходу вентиляції
Number:Temperature Ventilation_OutputTemperature "Температура повітря вентиляції [%.1f %unit%]" <temperature> (Ventilation) ["Measurement", "Temperature"] {ga="thermostatTemperatureAmbient"}
// бажана температура виходу вентиляції
Number:Temperature Ventilation_OutputSetpointTemperature "Бажана температура вентиляції [%.1f %unit%]" <thermostat> (Ventilation, gSetpointTemperature) ["Setpoint", "Temperature"] {ga="thermostatTemperatureSetpoint", listWidget="oh-stepper-item"[ step=0.5], widgetOrder="0"}
@stas-dovgodko
stas-dovgodko / ventilation.things
Last active October 12, 2023 10:47
Myhome vents things
// ПВУ neoclima
Bridge modbus:tcp:neoclima "PVU" [ host="***.***.***.***", port="***", id=1] {
// регістри керування вентиляторами, байпасом та нагрівачем
Bridge poller speed [ start=0, length=12, refresh=1000, type="holding" ] {
Thing data heater "PVU SW HEATER" [ readStart="1", readValueType="int16", writeStart="1", writeValueType="int16", writeType="holding" ]
Thing data bypass_opening "PVU BYPASS OPENING TEMP" [ readStart="2", readValueType="int16", writeStart="2", writeValueType="int16", writeType="holding" ]
Thing data bypass_range "PVU BYPASS OPENING RANGE" [ readStart="3", readValueType="int16", writeStart="3", writeValueType="int16", writeType="holding" ]
@stas-dovgodko
stas-dovgodko / backup.sh
Last active September 1, 2023 15:03
Backup php craft cms to aws s3 and glacier
#!/bin/bash
mydir="$(dirname "$(readlink -f "$0")")"
php ${mydir}/craft backup --interactive=0
backupfile="$(ls -Art "${mydir}/storage/backups/" | tail -n 1)"
now=`date +"%Y-%m-%d"`
tar cvzf ${mydir}/storage/runtime/temp/backup-${now}.tar.gz ${mydir}/storage/backups/${backupfile} ${mydir}/web/uploads/*
// при перемиканні ioncs8_config в ON конфігуруємо реле
rules.JSRule({
name: "Initial relay config",
triggers: [triggers.ItemCommandTrigger('ioncs8_config')],
execute: (event) => {
// відв'язуємо перший та восьмий вхід від виходу
if (event.receivedCommand === 'ON') items.getItem('ioncs8_1_configuration_outputmapping').sendCommand(0b01111110);
else items.getItem('ioncs8_1_configuration_outputmapping').sendCommand(0b11111111);
console.log('RELAY CONFIGURED');
Group ioncs8 "ION CS8" ["Equipment", "Light"]
Switch ioncs8_config "Налаштувати реле :)" (ioncs8)
Switch ioncs8_1_relay "1" (ioncs8) {channel="modbus:data:ion8cs_1:output:i1:switch"}
Contact ioncs8_1_status1 "1" (ioncs8) {channel="modbus:data:ion8cs_1:input:status1:contact"}
Contact ioncs8_1_status8 "8" (ioncs8) {channel="modbus:data:ion8cs_1:input:status8:contact"}
Group ioncs8_1_configuration "ION CS8 settings" (ioncs8)
Number ioncs8_1_configuration_outputmapping (ioncs8_1_configuration) {channel="modbus:data:ion8cs_1:outputs:mapping:number"}
// донгл /dev/usbModbus на швидкості 9600 з'єднано із реле slave=7
Bridge modbus:serial:ion8cs_1 [ port="/dev/usbModbus", id=7, baud=9600, stopBits="2.0", parity="none",dataBits=8, encoding="rtu"] {
// 8 coil регістрів починаючи з 0, це керування станом реле
// я не знайшов це в документації і якось здогадався шо воно може бути саме так
Bridge poller output [ start=0, length=8, type="coil" ] {
Thing data i1 "Стан 1" [ readStart="0", readValueType="bit", writeStart="0", writeType="coil"]
Thing data i2 "Стан 2" [ readStart="1", readValueType="bit", writeStart="1", writeType="coil"]
Thing data i3 "Стан 3" [ readStart="2", readValueType="bit", writeStart="2", writeType="coil"]
Thing data i4 "Стан 4" [ readStart="3", readValueType="bit", writeStart="3", writeType="coil"]
Thing data i5 "Стан 5" [ readStart="4", readValueType="bit", writeStart="4", writeType="coil"]