firstOrFail(); $zone = Zone::query()->firstOrCreate( ['name' => 'Гроубокс'], ['user_id' => $owner->id, 'description' => 'Демо-зона для проверки платформы'] ); $sensorType = DeviceType::where('code', 'sensor_temp_humidity')->firstOrFail(); $fanType = DeviceType::where('code', 'fan')->firstOrFail(); $sensor = Device::query()->firstOrCreate( ['external_id' => 'sensor-1'], [ 'user_id' => $owner->id, 'zone_id' => $zone->id, 'device_type_id' => $sensorType->id, 'name' => 'Датчик температуры', 'protocol' => 'mqtt', ] ); $fan = Device::query()->firstOrCreate( ['external_id' => 'fan-1'], [ 'user_id' => $owner->id, 'zone_id' => $zone->id, 'device_type_id' => $fanType->id, 'name' => 'Вентилятор', 'protocol' => 'mqtt', ] ); AutomationRule::query()->firstOrCreate( [ 'condition_source_device_id' => $sensor->id, 'target_device_id' => $fan->id, ], [ 'user_id' => $owner->id, 'zone_id' => $zone->id, 'condition_sensor_type' => 'temperature', 'condition_operator' => '>', 'condition_value' => 28, 'action_type' => 'turn_on', 'action_params' => [], 'is_active' => true, ] ); } }